Class MChain<T>

java.lang.Object
net.andreinc.markovneat.MChain<T>
Type Parameters:
T -
Direct Known Subclasses:
MChainText

public class MChain<T>
extends java.lang.Object
Markov chain class.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected java.util.Map<MState<T>,​MProb<T>> chain  
    protected java.util.Random random  
    protected java.util.List<MState<T>> states  
  • Constructor Summary

    Constructors 
    Constructor Description
    MChain()  
    MChain​(int noStates)  
    MChain​(int noStates, java.util.Random random)  
  • Method Summary

    Modifier and Type Method Description
    void add​(MState<T> state, T element)
    Adds a new state transition to the Markov Chain
    void add​(MState<T> state, T element, double weight)  
    java.util.List<T> generate​(int numElements)
    Generates a number of elements and stores in a List<T> based on the current Markov Chain.
    java.util.List<T> generate​(MState<T> initialState, int numElements)
    Generates a number of elements and stores them in a List<T> based on the current Markov chain.
    MState<T> randomState()  
    void train​(java.lang.Iterable<T> elements)
    Trains the Markov chain with a sequence of elements.
    protected void train​(java.util.Iterator<T> iterator)
    Trains the markov chain with a sequence of elements.
    void train​(T... elements)
    Trains the markov chain with a sequence of elements.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • MChain

      public MChain()
    • MChain

      public MChain​(int noStates)
    • MChain

      public MChain​(int noStates, java.util.Random random)
  • Method Details

    • add

      public void add​(MState<T> state, T element)
      Adds a new state transition to the Markov Chain
      Parameters:
      state - The initial state
      element - The element where we transition.
    • add

      public void add​(MState<T> state, T element, double weight)
    • train

      public void train​(java.lang.Iterable<T> elements)
      Trains the Markov chain with a sequence of elements.
      Parameters:
      elements -
    • train

      public void train​(T... elements)
      Trains the markov chain with a sequence of elements.
      Parameters:
      elements -
    • train

      protected void train​(java.util.Iterator<T> iterator)
      Trains the markov chain with a sequence of elements. The minimum number of the iterator needs to be >= noStates.
      Parameters:
      iterator -
    • generate

      public java.util.List<T> generate​(int numElements)
      Generates a number of elements and stores in a List<T> based on the current Markov Chain. Careful: the resulting List<T> will contain numElements + noStates elements.
      Parameters:
      numElements - The number of elements to be generate on top of an arbitrary initial state.
      Returns:
      A List<T> of elements.
    • randomState

      public MState<T> randomState()
    • generate

      public java.util.List<T> generate​(MState<T> initialState, int numElements)
      Generates a number of elements and stores them in a List<T> based on the current Markov chain.
      Parameters:
      initialState - The initial state from which we start the generation of elements. If the initial state doesn't exist in the Markov Chain an empty List will be returned.
      numElements - The number of elements that will be generated on top of the initial state. The number should be a positive value. (If the state has a 3 elements, and numElements is 2 a List<T> of 5=3+2 elements will be returned).
      Returns:
      A List<T> generated with the markov chain.