Constructor
new Chain(optionsopt)
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
{} | Options object Properties
|
Members
(readonly) initialState :Tuple.<any>
Initial state with BEGIN tokens.
Type:
- Tuple.<any>
(readonly) model :Map.<Tuple.<any>, any>
Map of chain states.
Type:
- Map.<Tuple.<any>, any>
(readonly) order :number
Order of chain.
Type:
- number
(readonly) tokenMap :Map.<any, Tuple.<any>>
Map of token to state.
Type:
- Map.<any, Tuple.<any>>
Methods
(static) fromJSON(jsonChain, options) → {Chain}
Creates a Chain from a JSON string.
Parameters:
Name | Type | Description |
---|---|---|
jsonChain |
string | A chain serialised with |
options |
object | Additional options to Chain constructor |
Returns:
A new chain instance
- Type
- Chain
(static) seed(run, chainopt)
Updates a model from a single run.
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
run |
Array.<any> | Array of tokens |
||||||||||||||||||||||
chain |
object |
<optional> |
{} | Chain object Properties
|
run(optionsopt) → {Array.<Array.<any>>}
Walks the Markov chain and returns all steps.
The returned step array will look like:
[ [backward_steps], [starting_tokens], [forward_steps] ]
The starting tokens are only returned when forward or backward steps were actually generated from a subset of the {options.tokens} parameter.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Options object Properties
|
Returns:
Array with back root and forward steps
- Type
- Array.<Array.<any>>
toJSON() → {Array.<any>}
Serialises the chain into a JSONable array.
The returned array will look like:
[ [ [state], [ [next, count], ...], [ [prev, count], ...] ], ...]
- Source:
- See:
Returns:
JSON array
- Type
- Array.<any>
(generator) walkBackward(fromStateopt) → {any}
Generates successive states until the chain reaches a BEGIN.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fromState |
Tuple.<any> |
<optional> |
Starting state of the chain walk |
Yields:
- Type
- any
(generator) walkForward(fromStateopt) → {any}
Generates successive states until the chain reaches an END.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fromState |
Tuple.<any> |
<optional> |
Begin state of the chain walk |
Yields:
- Type
- any