Crates.io | markov_rs |
lib.rs | markov_rs |
version | 0.1.2 |
source | src |
created_at | 2021-11-10 12:52:04.771239 |
updated_at | 2021-12-13 06:07:25.797555 |
description | A simple and fast Markov chain generator in Rust. |
homepage | https://github.com/ichi-h/markov_rs |
repository | https://github.com/ichi-h/markov_rs |
max_upload_size | |
id | 479703 |
size | 145,551 |
A simple and fast Markov Chain generator in Rust.
By using the Walker's Alias Method (WAM), a weighted random sampling algorithm, the model can generate elements very quickly. For details about the WAM, see ichi-h / weighted_rand.
The benchmark for this crate and the Markov Chain using the Cumulative Distribution Function (CDF) is as follows.
The time to create a Markov Chain model from each of the dummy texts of 100, 500, and 1000 words.
For both models, the generation time increases as the number of words in the text increases, but the slope of the time is larger for the WAM.
The time to generate 10 elements from the above models.
The CDF is slower to generate elements as the number of words in the text increases, but the WAM remains fast regardless.
Add this to your Cargo.toml:
[dependencies]
markov_rs = "0.1"
use markov_rs::MarkovChain;
fn main() {
let text = [
"I", "think", "that", "that", "that", "that", "that", "boy", "wrote", "is", "wrong",
];
let mut model = MarkovChain::from(&text);
for _ in 0..20 {
print!("{} ", model.next());
}
}
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.