Markov Chain
[![GitHub Tests Action Status][ico-workflows]][link-workflows]
![Total Downloads][ico-downloads]
, (*1)
Markov Chain implementation.
You train it by giving it arrays of tokens. Then you can get the occurrences and probability of
tokens after a given token., (*2)
Installation
You can install the package via composer:, (*3)
``` bash
$ composer require scripturadesign/markov, (*4)
## Usage
!!! Out of date, look in tests for now !!!
``` php
/* Create a new first order Markov Chain object */
$chain = new Chain(1);
/* Learn from arrays of tokens */
$chain->learn(['the', 'falcon', 'likes', 'the', 'snake']);
/* Get all the history of the training */
$chain->history();
// [
// [
// 0 => [''],
// 1 => ['the'],
// 2 => ['falcon'],
// 3 => ['likes'],
// 4 => ['snake'],
// ],
// [
// 0 => ['the' => 1],
// 1 => ['falcon' => 1, 'snake' => 1],
// 2 => ['likes' => 1],
// 3 => ['the' => 1],
// 4 => ['' => 1],
// ],
// ]
``` php
/* Create a new second order Markov Chain object */
$chain = new Chain(2);, (*5)
/* Learn from arrays of tokens */
$chain->learn(['the', 'falcon', 'likes', 'the', 'snake']);, (*6)
/* Get all the history of the training */
$chain->history();
// [
// [
// 0 => ['', ''],
// 1 => ['', 'the'],
// 2 => ['the', 'falcon'],
// 3 => ['falcon', 'likes'],
// 4 => ['likes', 'the'],
// 5 => ['the', 'snake'],
// ],
// [
// 0 => ['the' => 1],
// 1 => ['falcon' => 1],
// 2 => ['likes' => 1],
// 3 => ['the' => 1],
// 4 => ['snake' => 1],
// 5 => ['' => 1],
// ],
// ], (*7)
## Testing
``` bash
$ composer test
Change log
Please see CHANGELOG for more information what has changed recently., (*8)
Contributing
Please see CONTRIBUTING for details., (*9)
Security
If you discover any security related issues, please email martindilling@gmail.com instead of using the issue tracker., (*10)
Credits
License
The MIT License (MIT). Please see License File for more information., (*11)