entromatica/lib.rs
1//! Entromatica is a library for constructing, simulating and analyzing markov
2//! chains.
3//!
4//! It is split into two main parts: the [simulation](./simulation/index.html)
5//! module and the [models](./models/index.html) module collection.
6//!
7//! The [simulation](./simulation/index.html) module contains primarily the
8//! [Simulation](./simulation/struct.Simulation.html) struct, which takes an
9//! initial state and a
10//! [StateTransitionGenerator](./simulation/type.StateTransitionGenerator.html).
11//! This generator is a function that takes a state and returns a list of the
12//! next states in the markov chain with their respective relative
13//! probabilities.
14//!
15//! The [models](./models/index.html) module contains a collection of of structs
16//! and functions that try to make constructing the state transition generator
17//! easier. As of v1.0.1 this includes only a single model: [rules](./models/rules/index.html).
18//!
19//! ```rust
20//! // This is a simple onedimensional random walk
21//! use entromatica::prelude::*;
22//! use std::sync::Arc;
23//!
24//! // The initial state. It has to be Hash + Clone + Send + Sync + PartialEq + Eq + Debug
25//! let initial_state: i32 = 0;
26//!
27//! // The state transition generator. The simulation panics if the probabilities don't sum to 1.0
28//! let state_transition_generator =
29//! Arc::new(|state: i32| vec![(state + 1, "next", 0.5), (state - 1, "previous", 0.5)]);
30//!
31//! let mut simulation = Simulation::new(initial_state, state_transition_generator);
32//!
33//! // The Shannon-entropy at the given time
34//! assert_eq!(simulation.entropy(0), 0.0);
35//! simulation.next_step();
36//! assert_eq!(simulation.entropy(1), 1.0);
37//! ```
38
39mod cached_function;
40mod hash;
41pub mod models;
42pub mod prelude;
43pub mod simulation;