Crate markov_chain [] [src]

A markov chain library for Rust.

Features

  • Training sequences of arbitrary types
  • Nodes of N order
  • Specialized string generation and training
  • Serialization via serde
  • Generation utility

Examples

In your Cargo.toml file, make sure you have the line markov_chain = "0.1" under the [dependencies] section.

Markov chains may be created with any type that implements Clone, Hash, and Eq, and with some order (which is the number of items per node on the markov chain).

Creating a basic chain

use markov_chain::Chain;
 
let mut chain = Chain::new(1); // 1 is the order of the chain
 
// Train the chain on some vectors
chain.train(vec![1, 2, 3, 2, 1, 2, 3, 4, 3, 2, 1])
    .train(vec![5, 4, 3, 2, 1]);
 
// Generate a sequence and print it out
let sequence = chain.generate();
println!("{:?} ", sequence);

Structs

Chain

A struct representing a markov chain.

Traits

Chainable

A trait that defines a restrictions required for chainable items.