Class MarkovModel<A>

  • Type Parameters:
    A - the superset of the model's states
    Direct Known Subclasses:
    StringBigramModel, StringMarkovModel, StringTrigramModel

    public class MarkovModel<A>
    extends java.lang.Object
    A model representing an ordered sequence of states with a fixed probability of transitioning from a state to a consecutive state The class can be used to generate sequences probabilistically following the model
    See Also:
    en.wikipedia.org/wiki/Markov_chain
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected MarkovModel​(MarkovModel<A> model)
      Creates a new MarkovModel identical to an existing one used for creating subclass instances from static factory methods of this class
    • Method Summary

      Modifier and Type Method Description
      static <T> MarkovModel<T> fromSequences​(java.util.Collection<java.util.List<T>> sequences)
      A static factory method creating a new MarkovModel given a collection of state sequences
      java.util.List<A> generateSequence​(A startState, int length)
      Generates a random sequence according to the model's transition probabilities with a fixed length
      java.util.List<A> generateSequence​(A startState, A endState)
      Generates a random sequence according to the model's transition probabilities with a given start and end state The sequence will be continually generated until the end state is reached at which point it will terminate
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MarkovModel

        protected MarkovModel​(MarkovModel<A> model)
        Creates a new MarkovModel identical to an existing one used for creating subclass instances from static factory methods of this class
        Parameters:
        model - the model to be copied
    • Method Detail

      • fromSequences

        public static <T> MarkovModel<T> fromSequences​(java.util.Collection<java.util.List<T>> sequences)
        A static factory method creating a new MarkovModel given a collection of state sequences
        Type Parameters:
        T - the superset of the model's states
        Parameters:
        sequences - a collection of state sequences to create the model from
        Returns:
        a new model created from the state sequences
      • generateSequence

        public java.util.List<A> generateSequence​(A startState,
                                                  int length)
        Generates a random sequence according to the model's transition probabilities with a fixed length
        Parameters:
        startState - the state to start the sequence with
        length - the length of the sequence generated
        Returns:
        a generated state sequence
      • generateSequence

        public java.util.List<A> generateSequence​(A startState,
                                                  A endState)
        Generates a random sequence according to the model's transition probabilities with a given start and end state The sequence will be continually generated until the end state is reached at which point it will terminate
        Parameters:
        startState - the state to start the sequence with
        endState - the state to end the sequence on
        Returns:
        a generated state sequence