Package smile.sequence
Class HMMLabeler<T>
java.lang.Object
smile.sequence.HMMLabeler<T>
- Type Parameters:
T
- the data type of model input objects.
- All Implemented Interfaces:
Serializable
,SequenceLabeler<T>
First-order Hidden Markov Model sequence labeler.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionfinal HMM
The HMM model.final ToIntFunction
<T> The lambda returns the ordinal numbers of symbols. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> HMMLabeler
<T> fit
(T[][] observations, int[][] labels, ToIntFunction<T> ordinal) Fits an HMM by maximum likelihood estimation.double
Returns the logarithm probability of an observation sequence.double
Returns the log joint probability of an observation sequence along a state sequence.double
Returns the probability of an observation sequence.double
Returns the joint probability of an observation sequence along a state sequence.int[]
Returns the most likely state sequence given the observation sequence by the Viterbi algorithm, which maximizes the probability ofP(I | O, HMM)
.toString()
void
Updates the HMM by the Baum-Welch algorithm.
-
Field Details
-
model
The HMM model. -
ordinal
The lambda returns the ordinal numbers of symbols.
-
-
Constructor Details
-
HMMLabeler
Constructor.- Parameters:
model
- the HMM model.ordinal
- a lambda returning the ordinal numbers of symbols.
-
-
Method Details
-
fit
Fits an HMM by maximum likelihood estimation.- Type Parameters:
T
- the data type of observations.- 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.ordinal
- a lambda returning the ordinal numbers of symbols.- Returns:
- the model.
-
update
Updates the HMM by the Baum-Welch algorithm.- Parameters:
observations
- the training observation sequences.iterations
- the number of iterations to execute.
-
toString
-
p
Returns the joint probability of an observation sequence along a state sequence.- Parameters:
o
- an observation sequence.s
- a state sequence.- Returns:
- the joint probability P(o, s | H) given the model H.
-
logp
Returns the log joint probability of an observation sequence along a state sequence.- Parameters:
o
- an observation sequence.s
- a state sequence.- Returns:
- the log joint probability P(o, s | H) given the model H.
-
p
Returns the probability of an observation sequence.- Parameters:
o
- an observation sequence.- Returns:
- the probability of this sequence.
-
logp
Returns the logarithm probability of an observation sequence. A scaling procedure is used in order to avoid underflow when computing the probability of long sequences.- Parameters:
o
- an observation sequence.- Returns:
- the log probability of this sequence.
-
predict
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:
predict
in interfaceSequenceLabeler<T>
- Parameters:
o
- an observation sequence.- Returns:
- the most likely state sequence.
-