forwardback {HiddenMarkov} | R Documentation |
Forward and Backward Probabilities of DTHMM
Description
These functions calculate the forward and backward probabilities for a dthmm
process, as defined in MacDonald & Zucchini (1997, Page 60).
Usage
backward(x, Pi, distn, pm, pn = NULL)
forward(x, Pi, delta, distn, pm, pn = NULL)
forwardback(x, Pi, delta, distn, pm, pn = NULL, fortran = TRUE)
forwardback.dthmm(Pi, delta, prob, fortran = TRUE, fwd.only = FALSE)
Arguments
x |
is a vector of length |
Pi |
is the |
delta |
is the marginal probability distribution of the |
distn |
is a character string with the distribution name, e.g. |
pm |
is a list object containing the current (Markov dependent) parameter estimates associated with the distribution of the observed process (see |
pn |
is a list object containing the observation dependent parameter values associated with the distribution of the observed process (see |
prob |
an |
fortran |
logical, if |
fwd.only |
logical, if |
Details
Denote the matrices containing the forward and backward probabilities as
and
, respectively. Then the
th elements are
and
Further, the diagonal elements of the product matrix are all the same, taking the value of the log-likelihood.
Value
The function forwardback
returns a list with two matrices containing the forward and backward (log) probabilities, logalpha
and logbeta
, respectively, and the log-likelihood (LL
).
The functions backward
and forward
return a matrix containing the forward and backward (log) probabilities, logalpha
and logbeta
, respectively.
Author(s)
The algorithm has been taken from Zucchini (2005).
References
Cited references are listed on the HiddenMarkov manual page.
See Also
Examples
# Set Parameter Values
Pi <- matrix(c(1/2, 1/2, 0, 0, 0,
1/3, 1/3, 1/3, 0, 0,
0, 1/3, 1/3, 1/3, 0,
0, 0, 1/3, 1/3, 1/3,
0, 0, 0, 1/2, 1/2),
byrow=TRUE, nrow=5)
p <- c(1, 4, 2, 5, 3)
delta <- c(0, 1, 0, 0, 0)
#------ Poisson HMM ------
x <- dthmm(NULL, Pi, delta, "pois", list(lambda=p), discrete=TRUE)
x <- simulate(x, nsim=10)
y <- forwardback(x$x, Pi, delta, "pois", list(lambda=p))
# below should be same as LL for all time points
print(log(diag(exp(y$logalpha) %*% t(exp(y$logbeta)))))
print(y$LL)
#------ Gaussian HMM ------
x <- dthmm(NULL, Pi, delta, "norm", list(mean=p, sd=p/3))
x <- simulate(x, nsim=10)
y <- forwardback(x$x, Pi, delta, "norm", list(mean=p, sd=p/3))
# below should be same as LL for all time points
print(log(diag(exp(y$logalpha) %*% t(exp(y$logbeta)))))
print(y$LL)