Package net.andreinc.markovneat
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
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description voidadd(MState<T> state, T element)Adds a new state transition to the Markov Chainvoidadd(MState<T> state, T element, double weight)java.util.List<T>generate(int numElements)Generates a number of elements and stores in aList<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 aList<T>based on the current Markov chain.MState<T>randomState()voidtrain(java.lang.Iterable<T> elements)Trains the Markov chain with a sequence of elements.protected voidtrain(java.util.Iterator<T> iterator)Trains the markov chain with a sequence of elements.voidtrain(T... elements)Trains the markov chain with a sequence of elements.
-
Field Details
-
Constructor Details
-
Method Details
-
add
Adds a new state transition to the Markov Chain- Parameters:
state- The initial stateelement- The element where we transition.
-
add
-
train
Trains the Markov chain with a sequence of elements.- Parameters:
elements-
-
train
Trains the markov chain with a sequence of elements.- Parameters:
elements-
-
train
Trains the markov chain with a sequence of elements. The minimum number of the iterator needs to be>=noStates.- Parameters:
iterator-
-
generate
Generates a number of elements and stores in aList<T>based on the current Markov Chain. Careful: the resultingList<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
-
generate
Generates a number of elements and stores them in aList<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 aList<T>of 5=3+2 elements will be returned).- Returns:
- A
List<T>generated with the markov chain.
-