public class HMMLabeler<T> extends java.lang.Object implements SequenceLabeler<T>
Modifier and Type | Field and Description |
---|---|
HMM |
model
The HMM model.
|
java.util.function.ToIntFunction<T> |
ordinal
The lambda returns the ordinal numbers of symbols.
|
Constructor and Description |
---|
HMMLabeler(HMM model,
java.util.function.ToIntFunction<T> ordinal)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static <T> HMMLabeler<T> |
fit(T[][] observations,
int[][] labels,
java.util.function.ToIntFunction<T> ordinal)
Fits an HMM by maximum likelihood estimation.
|
double |
logp(T[] o)
Returns the logarithm probability of an observation sequence.
|
double |
logp(T[] o,
int[] s)
Returns the log joint probability of an observation sequence along a
state sequence.
|
double |
p(T[] o)
Returns the probability of an observation sequence.
|
double |
p(T[] o,
int[] s)
Returns the joint probability of an observation sequence along a state
sequence.
|
int[] |
predict(T[] o)
Returns the most likely state sequence given the observation sequence by
the Viterbi algorithm, which maximizes the probability of
P(I | O, HMM) . |
java.lang.String |
toString() |
void |
update(T[][] observations,
int iterations)
Updates the HMM by the Baum-Welch algorithm.
|
public final HMM model
public final java.util.function.ToIntFunction<T> ordinal
public static <T> HMMLabeler<T> fit(T[][] observations, int[][] labels, java.util.function.ToIntFunction<T> ordinal)
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.public void update(T[][] observations, int iterations)
observations
- the training observation sequences.iterations
- the number of iterations to execute.public java.lang.String toString()
toString
in class java.lang.Object
public double p(T[] o, int[] s)
o
- an observation sequence.s
- a state sequence.public double logp(T[] o, int[] s)
o
- an observation sequence.s
- a state sequence.public double p(T[] o)
o
- an observation sequence.public double logp(T[] o)
o
- an observation sequence.public int[] predict(T[] o)
P(I | O, HMM)
. In the calculation, we may get ties. In this
case, one of them is chosen randomly.predict
in interface SequenceLabeler<T>
o
- an observation sequence.