### 39 releases (5 stable)

2.3.0 | May 17, 2023 |
---|---|

2.1.0 | Mar 23, 2023 |

1.0.1 | Mar 9, 2023 |

0.24.0 | Mar 9, 2023 |

0.14.2 | Dec 22, 2022 |

#**532** in Algorithms

**158** downloads per month

**MIT/Apache**

57KB

922 lines

# Entromatica

**Entromatica is a library for constructing, simulating and analyzing markov
chains.**

It is split into two main parts: the

module and the `simulation`

module
collection.`models`

The

module contains primarily the `simulation`

struct, which takes
an initial state and a `Simulation`

. This generator is a function
that takes a state and returns a list of the next states in the markov chain
with their respective relative probabilities.`StateTransitionGenerator`

The

module contains a collection of structs and functions that try
to make constructing the state transition generator easier. Currently this
includes only a single model: `models`

.`rules`

`//` This is a simple onedimensional random walk
`use` `entromatica``::``prelude``::``*``;`
`use` `std``::``sync``::`Arc`;`
`//` The initial state. It has to be Hash + Clone + Send + Sync + PartialEq + Eq + Debug
`let` initial_state`:` `i32` `=` `0``;`
`//` The state transition generator. The simulation panics if the probabilities don't sum up to 1.0
`let` state_transition_generator `=`
`Arc``::`new`(``|``state``:` `i32``|` `vec!``[``(`state `+` `1``,` `"`next`"``,` `0.``5``)``,` `(`state `-` `1``,` `"`previous`"``,` `0.``5``)``]``)``;`
`let` `mut` simulation `=` `Simulation``::`new`(`initial_state`,` state_transition_generator`)``;`
`//` The Shannon-entropy at the given time
`assert_eq!``(`simulation`.``entropy``(``0``)``,` `0.``0``)``;`
simulation`.``next_step``(``)``;`
`assert_eq!``(`simulation`.``entropy``(``1``)``,` `1.``0``)``;`

## License

Licensed under either of

- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

## Contribution

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.

#### Dependencies

~6.5MB

~131K SLoC