GODPAPER | All Packages | All Classes | Index | Frames No Frames |
MarkovChain

Package | com.suckatmath.machinelearning.markov
Class | public class MarkovChain
Inheritance | MarkovChain Object

A simple markov chain which tracks distribution from arbitrary k-grams of tokens to the next token. for efficiency, kgrams are implemented as bare arrays

Public Properties

| Property | Defined By
--- | --- | ---
|  | k : int getter for kgram size | MarkovChain

Public Methods

| Method | Defined By
--- | --- | ---
|  | MarkovChain(k:int = 1, corpus:Array = null) construct a new Markov Chain | MarkovChain
|  | evaluateProb(tokenSequence:Array):Number return the probability of the given sequence | MarkovChain
|  | generateSequence(max:int = 100):Array generate a sequence of tokens | MarkovChain
|  | score(tokenSequence:Array):Number returns the sum of each transition's probability. | MarkovChain
|  | trainFromCorpus(corpus:Array):void calculates and populates graph from a corpus subsequent calls will act as if they were part of the same corpus | MarkovChain

Property Detail

k | property

`k:int`

getter for kgram size

Implementation
`public function get k():int`
`public function set k(value:int):void`
Constructor Detail

MarkovChain | () | Constructor

`public function MarkovChain(k:int = 1, corpus:Array = null)`

construct a new Markov Chain

Parameters

| `k:int` (default = `1`)`` — int size of kgrams
| `corpus:Array` (default = `null`)`` — Array of tokens to train on.

Method Detail

evaluateProb | () | method

`public function evaluateProb(tokenSequence:Array):Number`

return the probability of the given sequence

Parameters

| `tokenSequence:Array`

Returns

| `Number` — probability 0 to 1

generateSequence | () | method |

`public function generateSequence(max:int = 100):Array`

generate a sequence of tokens

Parameters

| `max:int` (default = `100`)`` — maximum number of tokens to generate

Returns

| `Array` — Array of tokens.

score | () | method |

`public function score(tokenSequence:Array):Number`

returns the sum of each transition's probability.

Parameters

| `tokenSequence:Array`

Returns

| `Number` —

trainFromCorpus | () | method |

`public function trainFromCorpus(corpus:Array):void`

calculates and populates graph from a corpus subsequent calls will act as if they were part of the same corpus

Parameters

| `corpus:Array` — : Array of Tokens

Thu Jan 16 2014, 01:11 PM +08:00