scripturadesign / markov
Markov Chain
Installs: 3 679
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4.0
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.15.0
README
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.
Installation
You can install the package via composer:
$ composer require scripturadesign/markov
Usage
!!! Out of date, look in tests for now !!!
/* 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], // ], // ]
/* Create a new second order Markov Chain object */ $chain = new Chain(2); /* 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 => ['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], // ], // ]
Testing
$ composer test
Change log
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email martindilling@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.