rust-random / rand

A Rust library for random number generation.
https://crates.io/crates/rand
Other
1.65k stars 430 forks source link

Markov Chains module or rand_iterator? #966

Closed saona-raimundo closed 4 years ago

saona-raimundo commented 4 years ago

Background

What is your motivation? Simulate stochastic processes, starting for finite space and discrete-time Markov Chains, going to countable space and discrete-time, then countable space and continuous-time (exponential clocks) Markov Chains.

There are various Markov Chains types out there, just as there are various distributions for random variables, namely: branching processes, coalescent process, etc.

What type of application is this? (E.g. cryptography, game, numerical simulation) Numerical simulation.

Feature request

Implementation of finite-state and discrete-time Markov chains as part of the rand project.

Markov chains are, at least in mathematics, stochastic processes defined by a transition matrix and an initial distribution. A realization of a Markov Chain is, in principle, an infinite path over the state space (an iterator). Therefore, I thought that a suitable implementation model would be: Markov Chain is a state and random iterator: - Created based on either a concrete state or a distribution over the states and a transition matrix. - Initialized in a concrete state according to the initial distribution (or the given state). - Being at a state, one can think of the (current) Markov Chain as a random variable, whose samples are possible transitions. Therefore, this state iterator also should implement the Distribution trait, to sample possible transitions. - As a (random) iterator, one should be able to apply `next` method. This method would simulate a transition, change the state of the iterator to that new state and return the new state (just as an iterator). To do this possible, I propose to ask in the creation of a Markov chain an RNG, which is exclusively used for the random transitions of the next method. An approach or first sketch of this is the [markovian](https://crates.io/crates/markovian) crate, in active development, that deals with countable states and possibly continuous Markov Chains. I am the author and would be happy to make a solid implementation for the rand crate in the future.
dhardy commented 4 years ago

I guess no one commented on this since it is less obvious how this fits into the family of Rand crates — it's less a core component than an application (or a support layer for applications). Perhaps best then to keep this as an independent crate?

Potentially you could add a chapter to the book about Markov Chains or just a section about related crates. I imagine users looking specifically for MC abstractions will find your work anyway.

saona-raimundo commented 4 years ago

Thanks for the answer!!

I will keep it as a separated crate then.