02.09.2014 Views

multivariate poisson hidden markov models for analysis of spatial ...

multivariate poisson hidden markov models for analysis of spatial ...

multivariate poisson hidden markov models for analysis of spatial ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

eta[T,]=matrix(1,nrow=1,ncol=N)<br />

<strong>for</strong> (t in (T-1):1){<br />

beta[t,]=(beta[t+1,]*dens[t+1,])%*%t(TRANS)<br />

beta[t,]=beta[t,]/scale[,t]<br />

}<br />

####M-step, reestmation <strong>of</strong> the transition matrix<br />

##compute unnormalized transition probabilities (this is indeed still the end <strong>of</strong> the E-<br />

#step, which explains that TRANS appears on the right-hand side below)<br />

#[Refer to equation (5.24)]<br />

P<br />

n<br />

∑<br />

jk<br />

i=<br />

2<br />

jk<br />

= n m<br />

∑∑<br />

i= 2 l=<br />

1<br />

vˆ<br />

( i)<br />

. (5.24)<br />

vˆ<br />

( i)<br />

jl<br />

TRANS=TRANS*(t(alpha[1:(T-1),])%*%(dens[2:T,]*beta[2:T,]))<br />

###Normalization <strong>of</strong> the transition matrix<br />

oness=matrix(1,nrow=1,ncol=N)<br />

sumtrans=matrix(0,nrow=N,ncol=1,byrow=T)<br />

<strong>for</strong> (n in 1:N){<br />

sumtrans[n,]=sum(TRANS[n,])<br />

}<br />

sumtrans=sumtrans%*%oness<br />

TRANS=TRANS/sumtrans<br />

####M-step, reestimation <strong>of</strong> the rates<br />

###Compute a posteriori probabilities and store them in matrix beta to save space<br />

#[Refer to equation (5.25) and (5.26)]<br />

#The <strong>for</strong>ward and backward variables<br />

α ( i) = P[ y , y ,..., y , S = j]<br />

and<br />

#<br />

j 1 2 n i<br />

( i) = P[ y ,..., y | S = j]<br />

(5.25)<br />

# β<br />

j i+<br />

1 n i<br />

#which yield the quantities <strong>of</strong> interest by<br />

α<br />

j() i β<br />

j() i α<br />

j() i β<br />

j()<br />

i<br />

# uˆ j<br />

() i = =<br />

m<br />

∑αl<br />

( n)<br />

α () i β () i<br />

l<br />

∑<br />

j=<br />

1<br />

j<br />

j<br />

and<br />

208

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!