chainkov

Crates.iochainkov
lib.rschainkov
version1.1.3
sourcesrc
created_at2019-11-13 06:05:52.298578
updated_at2020-01-05 21:11:22.965164
descriptionHashMap / Tuple-backed Markov Chains
homepage
repositoryhttps://github.com/ru-lai/chainkov
max_upload_size
id180865
size12,246
TL Boright (tlboright)

documentation

README

Chainkov Build Status

HashMap / tuple-backed Markov Chains

Install

  1. Add the dependency to the Cargo.toml of your project
// Cargo.toml
[dependencies]
chainkov = "0.1.0"
  1. Run cargo build
cargo build

Usage

extern crate chainkov;

use chainkov::*;

let mut m = MarkovChain::new();
// MarkovChain{ transition_prob: {} }

m.add_state_choice("a", ("b".to_string(), 1.0));
// MarkovChain { transition_prob: {"a": [("b", 0.4)]} }

m.add_state_choice("b", ("c".to_string(), 1.0));
// MarkovChain { transition_prob: {"a": [("b", 1.0)], "b": [("c", 1.0)]} }

m.add_state_choice("c", ("a".to_string(), 1.0));
// MarkovChain { transition_prob: {"c": [("a", 1.0)], "a": [("b", 1.0)], "b": [("c", 1.0)]} }

m.generate_states("a".to_string(), 4);
// ["b", "c", "a", "b"]

m.next_state("a".to_string());
// "b"

// incrementing when a state already exists
m.increment_state("a", "b");
// MarkovChain { transition_prob: {"c": [("a", 1.0)], "a": [("b", 2.0)], "b": [("c", 1.0)]} }

// incrementing when a key exists but the state transition doesn't
m.increment_state("a", "c");
// MarkovChain { transition_prob: {"c": [("a", 1.0)], "a": [("b", 2.0), ("c", 1.0)], "b": [("c", 1.0)]} }

// incrementing when a key exists but the state transition doesn't
m.increment_state("a", "c");
// MarkovChain { transition_prob: {"c": [("a", 1.0)], "a": [("b", 2.0), ("c", 1.0)], "b": [("c", 1.0)]} }

// incrementing when there is a new state in the MarkovChain
m.increment_state("e", "a");
// MarkovChain { transition_prob: {"e": [("a", 1.0)], "c": [("a", 1.0)], "a": [("b", 2.0), ("c", 1.0)], "b": [("c", 1.0)]} }
Commit count: 33

cargo fmt