Package uk.co.rafilevy.MarkovModels
Class HiddenMarkovModel<H,E>
- java.lang.Object
-
- uk.co.rafilevy.MarkovModels.HiddenMarkovModel<H,E>
-
- Type Parameters:
H
- The superset of the hidden sequence's statesE
- The superset of the emitted sequence's states
public class HiddenMarkovModel<H,E> extends java.lang.Object
A derivative of a MarkovModel where there is a hidden ordered sequence of states of type with fixed transition probabilities between states These hidden states each emit a value such that there is an observed ordered sequence of emitted values The class can be used to generate sequences probabilistically following the model or to decode an emitted sequence giving the most probable hidden sequence that generated it
-
-
Method Summary
Modifier and Type Method Description java.util.List<H>
decodeSequence(java.util.List<E> sequence)
Calculates the most probable hidden state sequence which may have generated a given emitted sequencestatic <HT,ET>
HiddenMarkovModel<HT,ET>fromSequences(java.util.Map<java.util.List<HT>,java.util.List<ET>> sequences)
A static factory method which creates a model given pairs of hidden and emitted sequences which define the model's transition and emission probabilitiesjava.util.List<E>
generateSequence(H startState, int length)
Generates a random emitted sequence following the model's probabilities with a fixed lengthjava.util.List<E>
generateSequence(H startState, H endState)
Generates a random emitted sequence following the model's probabilities with a given start and end state
-
-
-
Method Detail
-
fromSequences
public static <HT,ET> HiddenMarkovModel<HT,ET> fromSequences(java.util.Map<java.util.List<HT>,java.util.List<ET>> sequences)
A static factory method which creates a model given pairs of hidden and emitted sequences which define the model's transition and emission probabilities- Type Parameters:
HT
- the superset of the hidden sequence's statesET
- the superset of the emitted sequence's states- Parameters:
sequences
- a mapping of hidden sequences and the emission sequences they generated which the model's probabilities will be defined from- Returns:
- a model with probabilities defined by the given sequence pairs
-
generateSequence
public java.util.List<E> generateSequence(H startState, int length)
Generates a random emitted sequence following the model's probabilities with a fixed length- Parameters:
startState
- the state to start the hidden sequence withlength
- the length of the generated sequence- Returns:
- a randomly generated sequence
-
generateSequence
public java.util.List<E> generateSequence(H startState, H endState)
Generates a random emitted sequence following the model's probabilities with a given start and end state- Parameters:
startState
- the state to start the hidden sequence withendState
- the hidden state after which the sequence ends- Returns:
- a randomly generated sequence
-
decodeSequence
public java.util.List<H> decodeSequence(java.util.List<E> sequence)
Calculates the most probable hidden state sequence which may have generated a given emitted sequence- Parameters:
sequence
- the emitted sequence to be decoded- Returns:
- the most probable hidden state sequence which generated the given emitted sequence
- See Also:
- en.wikipedia.org/wiki/Viterbi_algorithm
-
-