head	1.2;
access;
symbols;
locks
	rolf:1.2; strict;
comment	@# @;


1.2
date	2013.04.17.02.30.39;	author rolf;	state Exp;
branches;
next	1.1;

1.1
date	2009.09.23.03.39.00;	author rturner;	state Exp;
branches;
next	;


desc
@Calculate the forward probabilities ``alpha''.
@


1.2
log
@Adjusted the dimensioning --- no more 1's.
@
text
@subroutine afun(fy,xispd,tpm,epsilon,n,nstate,wrk,xlc,alpha)
implicit double precision(a-h,o-z)
dimension wrk(nstate), xispd(nstate), xlc(n)
dimension fy(nstate,n), tpm(nstate,nstate), alpha(nstate,n)

# Set some constants
one  = 1.d0
zero = 0.d0

# Set the value to give to ``log-likelihood constant'', xlc(...)
# if this is indeterminate --- i.e. less than epsilon.
# Possible choices: -1, 1, or epsilon.
dummy = epsilon

# Update the initial alpha.
tsum = zero
do j = 1,nstate {
	wrk(j) =  fy(j,1)*xispd(j)
	tsum = tsum + wrk(j)
}

if(tsum < epsilon) {
	xlc(1) = dummy
	do j = 1,nstate {
		alpha(j,1) = one/nstate
	}
}
else {
	xlc(1) = tsum
	do j = 1,nstate {
		alpha(j,1) = wrk(j)/tsum
	}
}

# Run through the remaining n-1 of the alphas (recursing!).
do kt = 2,n {
	tsum = zero
	ktm = kt - 1
	do j = 1,nstate {
		wrk(j) = zero
		do i = 1,nstate {
			wrk(j) = wrk(j) + alpha(i,ktm)*tpm(i,j)
		}
		wrk(j) = fy(j,kt)*wrk(j)
		tsum = tsum + wrk(j)
	}
	if(tsum < epsilon) {
		xlc(kt) = dummy
		do j = 1,nstate {
			alpha(j,kt) = one/nstate
		}
	}
	else {
		xlc(kt) = tsum
		do j = 1,nstate {
			alpha(j,kt) = wrk(j)/tsum
		}
	}
}

return
end
@


1.1
log
@Initial revision
@
text
@d3 2
a4 2
dimension wrk(1), xispd(1), xlc(1)
dimension fy(nstate,1), tpm(nstate,1), alpha(nstate,1)
d13 1
a13 1
dummy = -one
@
