Calculates ``the'' most probable state sequence underlying each of one or more replicate observation sequences.
viterbi(y, model = NULL, tpm, Rho, ispd=NULL,log=FALSE, warn=TRUE)
If y
consists of a single observation sequence, the
value is the underlying most probable observation sequence,
or a matrix whose columns consist of such sequences if there
is more than one (equally) most probable sequence.
If y
consists of a list of observation sequences, the
value is a list each entry of which is of the form described
above.
If y
is of class "multipleHmmDataSets"
then the
value returned is a list of lists of the sort described above.
The observations for which the most probable sequence(s)
of underlying hidden states are required. May be a sequence of
observations in the form of a vector or a one or two column matrix,
or a list each component of which constitutes a (replicate)
sequence of observations. It may also be an object of class
"multipleHmmDataSets"
as returned by rhmm()
with nsim>1
.
If y
is missing, it is extracted from
model
(whence it will not be of class
"multipleHmmDataSets"
!) provided that model
and
its y
component are not NULL
. Otherwise an error
is given.
An object describing a hidden Markov model, as
fitted to the data set y
by hmm()
.
The transition probability matrix for a hidden
Markov model; ignored if model
is non-null.
An object specifying the probability distributions
of the observations for a hidden Markov model. See
hmm()
. Ignored if model
is non-null. Should
bear some reasonable relationship to y
.
If Rho
has dimension names (or if its entries have
dimension names in the case where Rho
is a list) then the
appropriate dimension names must include all corresponding values
of the observations. If a relevant vector of dimension names is
NULL
then it is formed as the sort unique values of the
approprate columns of the observation matrices. In this case the
corresponding dimensions must match the number of unique values.
The initial state probability distribution for a hidden
Markov model; ignored if model
is non-null. Should
bear some reasonable relationship to y
. If model
and ispd
are both NULL
then ispd
is set
equal to the stationary distribution calculated from tpm
.
Logical scalar. Should logarithms be used in the
recursive calculations of the probabilities involved in the
Viterbi algorithm, so as to avoid underflow? If log
is
FALSE
then underflow is avoided instead by a normalization
procedure. The quantity delta
(see Rabiner 1989, page 264)
is replaced by delta/sum(delta)
at each step. It should
actually make no difference whether log
is set to TRUE
.
I just included the option because I could. Also the HMM
package uses the logarithm approach so setting log=TRUE
might be of interest if comparisons are to be made between
results from the two packages.
Logical scalar; should a warning be issued if Rho
hasn't got relevant dimension names? (Note that if this is so,
then the corresponding dimension names are formed from the sorted
unique values of y
or of the appropriate column(s) of y
.
And if this is so, then the user should be sure that the
ordering of the entries of Rho
corresponds properly to the
the sorted unique values of y
.) This argument is passed
to the utility function check.yval()
which actually issues
the warning if warn=TRUE
.
Rolf Turner
r.turner@auckland.ac.nz
There may be more than one equally most probable state sequence underlying a given observation sequence. This phenomenon can occur but appears to be unlikely to do so in practice.
The correction made to the code so as to avoid underflow problems was made due to an inquiry and suggestion from Owen Marshall.
Applies the Viterbi algorithm to calculate ``the'' most probable robable state sequence underlying each observation sequences.
Rabiner, L. R., "A tutorial on hidden Markov models and selected applications in speech recognition," Proc. IEEE vol. 77, pp. 257 -- 286, 1989.
hmm()
, rhmm()
,
mps()
, pr()