Package uk.co.rafilevy.MarkovModels
Class MarkovModel<A>
- java.lang.Object
-
- uk.co.rafilevy.MarkovModels.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 sequencesjava.util.List<A>
generateSequence(A startState, int length)
Generates a random sequence according to the model's transition probabilities with a fixed lengthjava.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
-
-
-
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 withlength
- 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 withendState
- the state to end the sequence on- Returns:
- a generated state sequence
-
-