Viterbi algorithm for state decoding in periodically inhomogeneous HMMs
viterbi_p.RdThe Viterbi algorithm allows one to decode the most probable state sequence of an HMM.
Arguments
- delta
initial distribution of length
nStates, or matrix of dimensionc(nTracks, nStates)fornTracksindependent tracks, iftrackIDis providedThis could e.g. be the periodically stationary distribution (for each track).
- Gamma
array of transition probability matrices for each time point in the cycle of dimension
c(nStates, nStates, L), where L is the length of the cycle- allprobs
matrix of state-dependent probabilities/ density values of dimension
c(nObs, nStates)- tod
(Integer valued) variable for cycle indexing in 1, ..., L, mapping the data index to a generalised time of day (length
nObs)For half-hourly data L = 48. It could, however, also be day of year for daily data and L = 365.
- trackID
optional vector of length
nObscontainingnTracksunique IDs that separate tracks. The observations of each track need to be consecutive.- mod
optional model object containing initial distribution
delta, transition probability matrixGamma, matrix of state-dependent probabilitiesallprobs, and potentially atrackIDvariableIf you are using automatic differentiation either with
RTMB::MakeADFunorqremland includeforward_pin your likelihood function, the objects needed for state decoding are automatically reported after model fitting. Hence, you can pass the model object obtained fromobj$report(),lamaorqremldirectly to this function.
Details
Deprecated: please use viterbi with argument tod instead.
See also
Other decoding functions:
stateprobs(),
stateprobs_g(),
stateprobs_p(),
viterbi(),
viterbi_g()
Examples
delta = c(0.5, 0.5)
beta = matrix(c(-2, 1, -1,
-2, -1, 1), nrow = 2, byrow = TRUE)
Gamma = tpm_p(1:24, 24, beta)
tod = rep(1:24, 5)
n = length(tod)
allprobs = matrix(runif(2*n), nrow = n, ncol = 2)
states = viterbi_p(delta, Gamma, allprobs, tod)
#> viterbi_p() is deprecated, please use viterbi(..., tod = tod) for periodic models instead.