smile.sequence
Class HMM<O>
- java.lang.Object
-
- smile.sequence.HMM<O>
-
- All Implemented Interfaces:
- SequenceLabeler<O>
public class HMM<O> extends java.lang.Object implements SequenceLabeler<O>
First-order Hidden Markov Model. A hidden Markov model (HMM) is a statistical Markov model in which the system being modeled is assumed to be a Markov process with unobserved (hidden) states. An HMM can be considered as the simplest dynamic Bayesian network.In a regular Markov model, the state is directly visible to the observer, and therefore the state transition probabilities are the only parameters. In a hidden Markov model, the state is not directly visible, but output, dependent on the state, is visible. Each state has a probability distribution over the possible output tokens. Therefore the sequence of tokens generated by an HMM gives some information about the sequence of states.
-
-
Constructor Summary
Constructors Constructor and Description HMM(double[] pi, double[][] a, double[][] b)Constructor.HMM(double[] pi, double[][] a, double[][] b, O[] symbols)Constructor.HMM(int[][] observations, int[][] labels)Learn an HMM from labeled observation sequences by maximum likelihood estimation.HMM(O[][] observations, int[][] labels)Learn an HMM from labeled observation sequences by maximum likelihood estimation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description double[]getInitialStateProbabilities()Returns the initial state probabilities.double[][]getStateTransitionProbabilities()Returns the state transition probabilities.double[][]getSymbolEmissionProbabilities()Returns the symbol emission probabilities.HMM<O>learn(int[][] observations, int iterations)With this HMM as the initial model, learn an HMM by the Baum-Welch algorithm.HMM<O>learn(O[][] observations, int iterations)With this HMM as the initial model, learn an HMM by the Baum-Welch algorithm.doublelogp(int[] o)Returns the logarithm probability of an observation sequence given this HMM.doublelogp(int[] o, int[] s)Returns the log joint probability of an observation sequence along a state sequence given this HMM.doublelogp(O[] o)Returns the logarithm probability of an observation sequence given this HMM.doublelogp(O[] o, int[] s)Returns the log joint probability of an observation sequence along a state sequence given this HMM.intnumStates()Returns the number of states.intnumSymbols()Returns the number of emission symbols.doublep(int[] o)Returns the probability of an observation sequence given this HMM.doublep(int[] o, int[] s)Returns the joint probability of an observation sequence along a state sequence given this HMM.doublep(O[] o)Returns the probability of an observation sequence given this HMM.doublep(O[] o, int[] s)Returns the joint probability of an observation sequence along a state sequence given this HMM.int[]predict(int[] o)Returns the most likely state sequence given the observation sequence by the Viterbi algorithm, which maximizes the probability ofP(I | O, HMM).int[]predict(O[] o)Returns the most likely state sequence given the observation sequence by the Viterbi algorithm, which maximizes the probability ofP(I | O, HMM).java.lang.StringtoString()
-
-
-
Constructor Detail
-
HMM
public HMM(double[] pi, double[][] a, double[][] b)Constructor.- Parameters:
pi- the initial state probabilities.a- the state transition probabilities, of which a[i][j] is P(s_j | s_i);b- the symbol emission probabilities, of which b[i][j] is P(o_j | s_i).
-
HMM
public HMM(double[] pi, double[][] a, double[][] b, O[] symbols)Constructor.- Parameters:
pi- the initial state probabilities.a- the state transition probabilities, of which a[i][j] is P(s_j | s_i);b- the symbol emission probabilities, of which b[i][j] is P(o_j | s_i).symbols- the list of emission symbols.
-
HMM
public HMM(int[][] observations, int[][] labels)Learn an HMM from labeled observation sequences by maximum likelihood estimation.- Parameters:
observations- the observation sequences, of which symbols take values in [0, n), where n is the number of unique symbols.labels- the state labels of observations, of which states take values in [0, p), where p is the number of hidden states.
-
HMM
public HMM(O[][] observations, int[][] labels)
Learn an HMM from labeled observation sequences by maximum likelihood estimation.- Parameters:
observations- the observation sequences.labels- the state labels of observations, of which states take values in [0, p), where p is the number of hidden states.
-
-
Method Detail
-
numStates
public int numStates()
Returns the number of states.
-
numSymbols
public int numSymbols()
Returns the number of emission symbols.
-
getInitialStateProbabilities
public double[] getInitialStateProbabilities()
Returns the initial state probabilities.
-
getStateTransitionProbabilities
public double[][] getStateTransitionProbabilities()
Returns the state transition probabilities.
-
getSymbolEmissionProbabilities
public double[][] getSymbolEmissionProbabilities()
Returns the symbol emission probabilities.
-
p
public double p(int[] o, int[] s)Returns the joint probability of an observation sequence along a state sequence given this HMM.- Parameters:
o- an observation sequence.s- a state sequence.- Returns:
- the joint probability P(o, s | H) given the model H.
-
logp
public double logp(int[] o, int[] s)Returns the log joint probability of an observation sequence along a state sequence given this HMM.- Parameters:
o- an observation sequence.s- a state sequence.- Returns:
- the log joint probability P(o, s | H) given the model H.
-
p
public double p(int[] o)
Returns the probability of an observation sequence given this HMM.- Parameters:
o- an observation sequence.- Returns:
- the probability of this sequence.
-
logp
public double logp(int[] o)
Returns the logarithm probability of an observation sequence given this HMM. A scaling procedure is used in order to avoid underflows when computing the probability of long sequences.- Parameters:
o- an observation sequence.- Returns:
- the log probability of this sequence.
-
predict
public int[] predict(int[] o)
Returns the most likely state sequence given the observation sequence by the Viterbi algorithm, which maximizes the probability ofP(I | O, HMM). In the calculation, we may get ties. In this case, one of them is chosen randomly.- Parameters:
o- an observation sequence.- Returns:
- the most likely state sequence.
-
learn
public HMM<O> learn(O[][] observations, int iterations)
With this HMM as the initial model, learn an HMM by the Baum-Welch algorithm.- Parameters:
observations- the observation sequences on which the learning is based. Each sequence must have a length higher or equal to 2.iterations- the number of iterations to execute.- Returns:
- the updated HMM.
-
learn
public HMM<O> learn(int[][] observations, int iterations)
With this HMM as the initial model, learn an HMM by the Baum-Welch algorithm.- Parameters:
observations- the observation sequences on which the learning is based. Each sequence must have a length higher or equal to 2.iterations- the number of iterations to execute.- Returns:
- the updated HMM.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
p
public double p(O[] o, int[] s)
Returns the joint probability of an observation sequence along a state sequence given this HMM.- Parameters:
o- an observation sequence.s- a state sequence.- Returns:
- the joint probability P(o, s | H) given the model H.
-
logp
public double logp(O[] o, int[] s)
Returns the log joint probability of an observation sequence along a state sequence given this HMM.- Parameters:
o- an observation sequence.s- a state sequence.- Returns:
- the log joint probability P(o, s | H) given the model H.
-
p
public double p(O[] o)
Returns the probability of an observation sequence given this HMM.- Parameters:
o- an observation sequence.- Returns:
- the probability of this sequence.
-
logp
public double logp(O[] o)
Returns the logarithm probability of an observation sequence given this HMM. A scaling procedure is used in order to avoid underflows when computing the probability of long sequences.- Parameters:
o- an observation sequence.- Returns:
- the log probability of this sequence.
-
predict
public int[] predict(O[] o)
Returns the most likely state sequence given the observation sequence by the Viterbi algorithm, which maximizes the probability ofP(I | O, HMM). In the calculation, we may get ties. In this case, one of them is chosen randomly.- Specified by:
predictin interfaceSequenceLabeler<O>- Parameters:
o- an observation sequence.- Returns:
- the most likely state sequence.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG