# doc-cache created by Octave 11.2.0
# name: cache
# type: cell
# rows: 3
# columns: 5
# name: <cell-element>
# type: sq_string
# elements: 1
# length: 9
hmmdecode


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 2479
statistics: pstates = hmmdecode ( sequence , transprob , outprob )
statistics: [ pstates , logpseq ] = hmmdecode (&hellip;)
statistics: [ pstates , logpseq , fs , bs , s ] = hmmdecode (&hellip;)
statistics: [&hellip;] = hmmdecode (&hellip;, "symbols" , symbols )

Posterior state probabilities of a hidden Markov model.

Calculate the posterior state probabilities of the sequence sequence
from a hidden Markov model. The posterior state probabilities are the
conditional probabilities of being in each state given the whole observed
sequence. The model assumes that the generation starts in state 1
at step 0 but does not include step 0 in the sequence.

Arguments

sequence is a vector of length len of given outputs. The
outputs must be integers ranging from 1 to columns (outprob) .

transprob is the matrix of transition probabilities of the states.
transprob(i, j) is the probability of a transition to state
j given state i .

outprob is the matrix of output probabilities.
outprob(i, j) is the probability of generating output j
given state i .

Return values

pstates is the matrix of posterior state probabilities. It has one
row for each state and one column for each element of sequence .
pstates(i, j) is the conditional probability that the model is in
state i when it generates the j -th output of sequence ,
given that sequence is emitted.

logpseq is the logarithm of the probability of the sequence
sequence .

fs and bs are the scaled forward and backward probabilities,
respectively, and s is the vector of scale factors used to keep the
computation numerically stable.

If "symbols" is specified, then sequence is expected to be a
sequence of the elements of symbols instead of integers ranging from
1 to columns (outprob) . symbols can be a cell array.

Examples

transprob = [0.8, 0.2; 0.4, 0.6];
outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1];
[sequence, states] = hmmgenerate (25, transprob, outprob);
pstates = hmmdecode (sequence, transprob, outprob);

symbols = {"A", "B", "C"};
[sequence, states] = hmmgenerate (25, transprob, outprob, ...
"symbols", symbols);
pstates = hmmdecode (sequence, transprob, outprob, "symbols", symbols);

References

Wendy L. Martinez and Angel R. Martinez. Computational Statistics
Handbook with MATLAB . Appendix E, pages 547-557, Chapman & Hall/CRC,
2001.

Lawrence R. Rabiner. A Tutorial on Hidden Markov Models and Selected
Applications in Speech Recognition. Proceedings of the IEEE ,
77(2), pages 257-286, February 1989.


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 55
Posterior state probabilities of a hidden Markov model.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 11
hmmestimate


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 3722
statistics: [ transprobest , outprobest ] = hmmestimate ( sequence , states )
statistics: [&hellip;] = hmmestimate (&hellip;, "statenames" , statenames )
statistics: [&hellip;] = hmmestimate (&hellip;, "symbols" , symbols )
statistics: [&hellip;] = hmmestimate (&hellip;, "pseudotransitions" , pseudotransitions )
statistics: [&hellip;] = hmmestimate (&hellip;, "pseudoemissions" , pseudoemissions )

Estimation of a hidden Markov model for a given sequence.

Estimate the matrix of transition probabilities and the matrix of output
probabilities of a given sequence of outputs and states generated by a
hidden Markov model. The transition probabilities are estimated by counting
the transitions that actually occur between consecutive states in
states ; the output probabilities are estimated from the outputs
emitted by each state.

Arguments

sequence is a vector of a sequence of given outputs. The outputs
must be integers ranging from 1 to the number of outputs of the
hidden Markov model.

states is a vector of the same length as sequence of given
states. The states must be integers ranging from 1 to the number
of states of the hidden Markov model.

Return values

transprobest is the matrix of the estimated transition
probabilities of the states. transprobest(i, j) is the estimated
probability of a transition to state j given state i .

outprobest is the matrix of the estimated output probabilities.
outprobest(i, j) is the estimated probability of generating
output j given state i .

If 'symbols' is specified, then sequence is expected to be a
sequence of the elements of symbols instead of integers.
symbols can be a cell array.

If 'statenames' is specified, then states is expected to be
a sequence of the elements of statenames instead of integers.
statenames can be a cell array.

If 'pseudotransitions' is specified then the integer matrix
pseudotransitions is used as an initial number of counted
transitions. pseudotransitions(i, j) is the initial number of
counted transitions from state i to state j .
transprobest will have the same size as pseudotransitions .
Use this if you have transitions that are very unlikely to occur.

If 'pseudoemissions' is specified then the integer matrix
pseudoemissions is used as an initial number of counted outputs.
pseudoemissions(i, j) is the initial number of counted outputs
j given state i . If 'pseudoemissions' is also
specified then the number of rows of pseudoemissions must be the
same as the number of rows of pseudotransitions . outprobest
will have the same size as pseudoemissions . Use this if you have
outputs or states that are very unlikely to occur.

Examples

transprob = [0.8, 0.2; 0.4, 0.6];
outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1];
[sequence, states] = hmmgenerate (25, transprob, outprob);
[transprobest, outprobest] = hmmestimate (sequence, states)

symbols = {"A", "B", "C"};
statenames = {"One", "Two"};
[sequence, states] = hmmgenerate (25, transprob, outprob, ...
"symbols", symbols, ...
"statenames", statenames);
[transprobest, outprobest] = hmmestimate (sequence, states, ...
"symbols', symbols, ...
"statenames', statenames)

pseudotransitions = [8, 2; 4, 6];
pseudoemissions = [2, 4, 4; 7, 2, 1];
[sequence, states] = hmmgenerate (25, transprob, outprob);
[transprobest, outprobest] = hmmestimate (sequence, states, ...
"pseudotransitions", pseudotransitions, ...
"pseudoemissions", pseudoemissions)

References

Wendy L. Martinez and Angel R. Martinez. Computational Statistics
Handbook with MATLAB . Appendix E, pages 547-557, Chapman & Hall/CRC,
2001.

Lawrence R. Rabiner. A Tutorial on Hidden Markov Models and Selected
Applications in Speech Recognition. Proceedings of the IEEE ,
77(2), pages 257-286, February 1989.


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 57
Estimation of a hidden Markov model for a given sequence.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 11
hmmgenerate


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 2091
statistics: [ sequence , states ] = hmmgenerate ( len , transprob , outprob )
statistics: [&hellip;] = hmmgenerate (&hellip;, "symbols" , symbols )
statistics: [&hellip;] = hmmgenerate (&hellip;, "statenames" , statenames )

Output sequence and hidden states of a hidden Markov model.

Generate an output sequence and hidden states of a hidden Markov model.
The model starts in state 1 at step 0 but will not include
step 0 in the generated states and sequence.

Arguments

len is the number of steps to generate. sequence and
states will have len entries each.

transprob is the matrix of transition probabilities of the states.
transprob(i, j) is the probability of a transition to state
j given state i .

outprob is the matrix of output probabilities.
outprob(i, j) is the probability of generating output j
given state i .

Return values

sequence is a vector of length len of the generated
outputs. The outputs are integers ranging from 1 to
columns (outprob) .

states is a vector of length len of the generated hidden
states. The states are integers ranging from 1 to
columns (transprob) .

If "symbols" is specified, then the elements of symbols are
used for the output sequence instead of integers ranging from 1 to
columns (outprob) . symbols can be a cell array.

If "statenames" is specified, then the elements of
statenames are used for the states instead of integers ranging from
1 to columns (transprob) . statenames can be a cell
array.

Examples

transprob = [0.8, 0.2; 0.4, 0.6];
outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1];
[sequence, states] = hmmgenerate (25, transprob, outprob)

symbols = {"A", "B", "C"};
statenames = {"One", "Two"};
[sequence, states] = hmmgenerate (25, transprob, outprob, ...
"symbols", symbols, ...
"statenames", statenames)

References

Wendy L. Martinez and Angel R. Martinez. Computational Statistics
Handbook with MATLAB . Appendix E, pages 547-557, Chapman & Hall/CRC,
2001.

Lawrence R. Rabiner. A Tutorial on Hidden Markov Models and Selected
Applications in Speech Recognition. Proceedings of the IEEE ,
77(2), pages 257-286, February 1989.


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 59
Output sequence and hidden states of a hidden Markov model.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 8
hmmtrain


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 4335
statistics: [ esttr , estout ] = hmmtrain ( sequence , transguess , outguess )
statistics: [&hellip;] = hmmtrain (&hellip;, "algorithm" , algorithm )
statistics: [&hellip;] = hmmtrain (&hellip;, "symbols" , symbols )
statistics: [&hellip;] = hmmtrain (&hellip;, "tolerance" , tol )
statistics: [&hellip;] = hmmtrain (&hellip;, "maxiterations" , maxiter )
statistics: [&hellip;] = hmmtrain (&hellip;, "pseudotransitions" , pseudotransitions )
statistics: [&hellip;] = hmmtrain (&hellip;, "pseudoemissions" , pseudoemissions )
statistics: [&hellip;] = hmmtrain (&hellip;, "verbose" , vflag )

Estimate the parameters of a hidden Markov model from emitted sequences.

Given one or more observed output sequences and initial guesses for the
transition and output probability matrices, hmmtrain finds maximum
likelihood estimates of the two matrices using the Baum-Welch algorithm
(the default) or Viterbi training. The model assumes that the generation
starts in state 1 at step 0 but does not include step
0 in the sequence.

Arguments

sequence is a vector of a sequence of given outputs, or, for training
from several sequences, a cell array of such vectors or a matrix whose rows
are individual sequences. The outputs must be integers ranging from
1 to columns (outguess) .

transguess is the initial guess for the matrix of transition
probabilities. transguess(i, j) is the probability of a transition
to state j given state i .

outguess is the initial guess for the matrix of output probabilities.
outguess(i, j) is the probability of generating output j
given state i .

Return values

esttr is the estimated matrix of transition probabilities.

estout is the estimated matrix of output probabilities.

Name-Value pair arguments

"algorithm" selects the training algorithm, either
"BaumWelch" (default) or "Viterbi" . "BaumWelch"
performs the standard forward-backward re-estimation and is recommended for
most uses. "Viterbi" performs segmental (hard) re-estimation from
the most likely state path of each sequence; it is faster but only
approximates the maximum-likelihood estimate.

"symbols" specifies the possible outputs. If given, sequence
is expected to hold the elements of symbols instead of integers.
symbols can be a cell array.

"tolerance" is the convergence tolerance (default 1e-6 ). The
algorithm terminates when the change in the log-likelihood and in both
estimated matrices falls below tol .

"maxiterations" is the maximum number of iterations (default
500 ). A warning is issued if the algorithm has not converged within
this many iterations.

"pseudotransitions" and "pseudoemissions" supply pseudo-count
matrices for Viterbi training, used to keep transitions or outputs that are
very unlikely to occur from collapsing to zero probability.

"verbose" , when true, prints the log-likelihood and the change in the
estimates at each iteration.

Examples

transprob = [0.8, 0.2; 0.4, 0.6];
outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1];
sequence = hmmgenerate (100, transprob, outprob);
transguess = [0.6, 0.4; 0.5, 0.5];
outguess = [0.3, 0.3, 0.4; 0.5, 0.3, 0.2];
[esttr, estout] = hmmtrain (sequence, transguess, outguess);

Two results of Viterbi training differ from MATLAB&rsquo;s, deliberately.

Given several sequences, the counts of every sequence are pooled and
normalized once, so a sequence contributes in proportion to its length.
MATLAB normalizes each sequence separately and averages the results, which
weights an eight-symbol sequence as heavily as a twenty-four-symbol one and
is not the maximum likelihood estimate. Its own Baum-Welch pools expected
counts, as both algorithms do here.

Given "pseudotransitions" or "pseudoemissions" , the
pseudo-counts are added to the counted transitions and outputs, once per
iteration, before the row is normalized. MATLAB does the same on its first
iteration; from its second it adds them to an estimate that has already been
normalized, so its iterate mixes counts with probabilities and is no longer
a count matrix of any state path.

References

Wendy L. Martinez and Angel R. Martinez. Computational Statistics
Handbook with MATLAB . Appendix E, pages 547-557, Chapman & Hall/CRC,
2001.

Lawrence R. Rabiner. A Tutorial on Hidden Markov Models and Selected
Applications in Speech Recognition. Proceedings of the IEEE ,
77(2), pages 257-286, February 1989.


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 72
Estimate the parameters of a hidden Markov model from emitted sequences.



# name: <cell-element>
# type: sq_string
# elements: 1
# length: 10
hmmviterbi


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 2201
statistics: vpath = hmmviterbi ( sequence , transprob , outprob )
statistics: vpath = hmmviterbi (&hellip;, "symbols" , symbols )
statistics: vpath = hmmviterbi (&hellip;, "statenames" , statenames )

Viterbi path of a hidden Markov model.

Use the Viterbi algorithm to find the Viterbi path of a hidden Markov
model given a sequence of outputs. The model assumes that the generation
starts in state 1 at step 0 but does not include step
0 in the generated states and sequence.

Arguments

sequence is the vector of length len of given outputs. The
outputs must be integers ranging from 1 to
columns (outprob) .

transprob is the matrix of transition probabilities of the states.
transprob(i, j) is the probability of a transition to state
j given state i .

outprob is the matrix of output probabilities.
outprob(i, j) is the probability of generating output j
given state i .

Return values

vpath is the vector of the same length as sequence of the
estimated hidden states. The states are integers ranging from 1 to
columns (transprob) .

If "symbols" is specified, then sequence is expected to be a
sequence of the elements of symbols instead of integers ranging
from 1 to columns (outprob) . symbols can be a cell array.

If "statenames" is specified, then the elements of
statenames are used for the states in vpath instead of
integers ranging from 1 to columns (transprob) .
statenames can be a cell array.

Examples

transprob = [0.8, 0.2; 0.4, 0.6];
outprob = [0.2, 0.4, 0.4; 0.7, 0.2, 0.1];
[sequence, states] = hmmgenerate (25, transprob, outprob);
vpath = hmmviterbi (sequence, transprob, outprob);

symbols = {"A", "B", "C"};
statenames = {"One", "Two"};
[sequence, states] = hmmgenerate (25, transprob, outprob, ...
"symbols", symbols, "statenames", statenames);
vpath = hmmviterbi (sequence, transprob, outprob, ...
"symbols", symbols, "statenames", statenames);

References

Wendy L. Martinez and Angel R. Martinez. Computational Statistics
Handbook with MATLAB . Appendix E, pages 547-557, Chapman & Hall/CRC,
2001.

Lawrence R. Rabiner. A Tutorial on Hidden Markov Models and Selected
Applications in Speech Recognition. Proceedings of the IEEE ,
77(2), pages 257-286, February 1989.


# name: <cell-element>
# type: sq_string
# elements: 1
# length: 38
Viterbi path of a hidden Markov model.





