Last chance! 50% off unlimited learning
Sale ends in
"forward"(hmm, obs)
"backward"(hmm, obs)
hmm
or one of its subclasses representing the hidden Markov model.backward
returns the $N \times T$ matrix of (log transformed) backward variables,
where $N$ is the number of states of hmm
and $T$ is the length of obs
.forward
returns a list with components
obs
|hmm
)]backward
hmm
## create two state HMM with t distributions
state.names <- c("one","two")
transition <- c(0.1, 0.02)
location <- c(1, 2)
scale <- c(1, 1)
df <- c(4, 6)
model <- getHMM(list(a=transition, mu=location, sigma=scale, nu=df),
state.names)
## obtain observation sequence from model
obs <- sampleSeq(model, 100)
## calculate the probability of the observation given the model
fwd <- forward(model, obs)
fwd$logProb
## compute posterior probabilities
bwd <- backward(model,obs)
post <- bwd + fwd$alpha.scaled
post <- t(t(post) - apply(post,2,logSum))
## get sequence of most likely states
state.seq <- state.names[apply(post,2,which.max)]
Run the code above in your browser using DataLab