Class HiddenMarkovModel<H,​E>

  • Type Parameters:
    H - The superset of the hidden sequence's states
    E - 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
    See Also:
    en.wikipedia.org/wiki/Hidden_Markov_model
    • 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 sequence
      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
      java.util.List<E> generateSequence​(H startState, int length)
      Generates a random emitted sequence following the model's probabilities with a fixed length
      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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 states
        ET - 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 with
        length - 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 with
        endState - 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