Accord.Statistics.Models.Markov BaseHiddenMarkovModel
Accord.Statistics.Models.Markov HiddenMarkovModel
Namespace: Accord.Statistics.Models.Markov
Assembly: Accord.Statistics (in Accord.Statistics.dll) Version: 2.9.0.0 (2.9.0.0)
[SerializableAttribute] public class HiddenMarkovModel : BaseHiddenMarkovModel, IHiddenMarkovModel, ICloneable
Hidden Markov Models (HMM) are stochastic methods to model temporal and sequence data. They are especially known for their application in temporal pattern recognition such as speech, handwriting, gesture recognition, part-of-speech tagging, musical score following, partial discharges and bioinformatics.
Dynamical systems of discrete nature assumed to be governed by a Markov chain emits a sequence of observable outputs. Under the Markov assumption, it is also assumed that the latest output depends only on the current state of the system. Such states are often not known from the observer when only the output values are observable.
Hidden Markov Models attempt to model such systems and allow, among other things,
- To infer the most likely sequence of states that produced a given output sequence,
- Infer which will be the most likely next state (and thus predicting the next output),
- Calculate the probability that a given sequence of outputs originated from the system (allowing the use of hidden Markov models for sequence classification).
The “hidden” in Hidden Markov Models comes from the fact that the observer does not know in which state the system may be in, but has only a probabilistic insight on where it should be.
References:
- http://en.wikipedia.org/wiki/Hidden_Markov_model
- http://www.shokhirev.com/nikolai/abc/alg/hmm/hmm.html
- P396-397 “Spoken Language Processing” by X. Huang
- Dawei Shen. Some mathematics for HMMs, 2008. Available in: http://courses.media.mit.edu/2010fall/mas622j/ProblemSets/ps4/tutorial.pdf
- http://www.stanford.edu/class/cs262/presentations/lecture7.pdf
- http://cs.oberlin.edu/~jdonalds/333/lecture11.html
The example below reproduces the same example given in the Wikipedia entry for the Viterbi algorithm (http://en.wikipedia.org/wiki/Viterbi_algorithm). In this example, the model's parameters are initialized manually. However, it is possible to learn those automatically using BaumWelchLearning.
// Create the transation matrix A double[,] transition = { { 0.7, 0.3 }, { 0.4, 0.6 } }; // Create the emission matrix B double[,] emission = { { 0.1, 0.4, 0.5 }, { 0.6, 0.3, 0.1 } }; // Create the initial probabilities pi double[] initial = { 0.6, 0.4 }; // Create a new hidden Markov model HiddenMarkovModel hmm = new HiddenMarkovModel(transition, emission, initial); // After that, one could, for example, query the probability // of a sequence ocurring. We will consider the sequence int[] sequence = new int[] { 0, 1, 2 }; // And now we will evaluate its likelihood double logLikelihood = hmm.Evaluate(sequence); // At this point, the log-likelihood of the sequence // ocurring within the model is -3.3928721329161653. // We can also get the Viterbi path of the sequence int[] path = hmm.Decode(sequence, out logLikelihood); // At this point, the state path will be 1-0-0 and the // log-likelihood will be -4.3095199438871337