v2.0.0 2021-12-15 00:09 UTC

This package is auto-updated.

Last update: 2024-04-15 04:53:53 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads Software License

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.