[−][src]Struct chainkov::MarkovChain
chainkov Basic Usage
Example
use std::collections::HashMap; let mut m = chainkov::MarkovChain::new(); assert_eq!(m.transition_prob, HashMap::new()); m.add_state_choice("a", ("b".to_string(), 1.0)); let mut new_state = &m.transition_prob.get("a").unwrap()[0]; assert_eq!(new_state.0, "b".to_string()); assert_eq!(new_state.1, 1.0); m.add_state_choice("b", ("c".to_string(), 1.0)); new_state = &m.transition_prob.get("b").unwrap()[0]; assert_eq!(new_state.0, "c".to_string()); assert_eq!(new_state.1, 1.0); m.add_state_choice("c", ("d".to_string(), 1.0)); new_state = &m.transition_prob.get("c").unwrap()[0]; assert_eq!(new_state.0, "d".to_string()); assert_eq!(new_state.1, 1.0); m.add_state_choice("d", ("a".to_string(), 1.0)); new_state = &m.transition_prob.get("d").unwrap()[0]; assert_eq!(new_state.0, "a".to_string()); assert_eq!(new_state.1, 1.0); let answer_vec = m.generate_states("a".to_string(), 4); assert_eq!(answer_vec, vec!["b", "c", "d", "a"]); let mut answer = m.next_state("a".to_string()); assert_eq!(answer, "b"); // incrementing when a state already exists m.increment_state("a", "b"); new_state = &m.transition_prob.get("a").unwrap()[0]; assert_eq!(new_state.0, "b"); assert_eq!(new_state.1, 2.0); // incrementing when a key exists but the state transition doesn't m.increment_state("a", "c"); new_state = &m.transition_prob.get("a").unwrap()[1]; assert_eq!(new_state.0, "c"); assert_eq!(new_state.1, 1.0); // incrementing when there is a new state in the MarkovChain m.increment_state("e", "a"); new_state = &m.transition_prob.get("e").unwrap()[0]; assert_eq!(new_state.0, "a"); assert_eq!(new_state.1, 1.0);
Fields
transition_prob: HashMap<String, Vec<(String, f32)>>
Methods
impl MarkovChain
[src]
pub fn add_state_choice(&mut self, key: &str, probability: (String, f32))
[src]
pub fn increment_state(&mut self, key: &str, state: &str)
[src]
pub fn generate_states(
&self,
current_state: String,
num_of_states: u16
) -> Vec<String>
[src]
&self,
current_state: String,
num_of_states: u16
) -> Vec<String>
pub fn new() -> MarkovChain
[src]
pub fn next_state(&self, current_state: String) -> String
[src]
Trait Implementations
impl Clone for MarkovChain
[src]
fn clone(&self) -> MarkovChain
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for MarkovChain
[src]
impl PartialEq<MarkovChain> for MarkovChain
[src]
fn eq(&self, other: &MarkovChain) -> bool
[src]
fn ne(&self, other: &MarkovChain) -> bool
[src]
impl StructuralPartialEq for MarkovChain
[src]
Auto Trait Implementations
impl RefUnwindSafe for MarkovChain
impl Send for MarkovChain
impl Sync for MarkovChain
impl Unpin for MarkovChain
impl UnwindSafe for MarkovChain
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,