MarkovChain

Undocumented in source.

Constructors

this
this()
Undocumented in source.
this
this(size_t[] sizes)

Constructs a markov chain with empty states of the given sizes.

this
this(State!T[] states)

Constructs a markov chain using a list of existing states.

Members

Functions

feed
void feed(T[] first, T follow)

Trains the markov chain with a specific token sequence.

generate
T generate()
Nullable!(Unqual!T) generate()

Returns a token generated from the internal set of states, based on the tokens previously generated. If no token can be produced, a random one is returned.

generate
Unqual!T[] generate(size_t length)

Ditto, but produces an array of token with the given length.

generate
size_t generate(size_t length, Unqual!T[] output)

Ditto, but the array is given as an out-parameter.

push
void push(T follow)

Pushes a token to the markov chain's history buffer.

seed
void seed(T[] seed)

Pushes tokens to the markov chain's history buffer, seeding it for subsequent calls to select() or generate().

select
T select()
Nullable!(Unqual!T) select()

Returns a token generated from the internal set of states, based on the tokens previously generated. If no token can be produced, null is returned.

train
void train(T[] input)

Trains the markov chain from a sequence of input tokens.

Properties

empty
bool empty [@property getter]

Checks if all of the markov chain's states are empty.

length
size_t length [@property getter]

Returns the number of states used by the markov chain.

lengths
size_t[] lengths [@property getter]

Returns the lengths of the markov chain's states in an unknown order.

random
T random [@property getter]
Nullable!(Unqual!T) random [@property getter]

Returns a randomly selected token from a randomly selected state.

rehash
void rehash [@property getter]

Rehashes the associative arrays used in the markov chain's states.

reset
void reset [@property getter]

Resets the markov chain's history buffer to an empty state.

sizes
size_t[] sizes [@property getter]

Returns the sizes of the markov chain's states in an unknown order.

states
State!T[] states [@property getter]

Returns an array representing the markov chain's internal set of states.

Meta