### 15 unstable releases (6 breaking)

✓ Uses Rust 2018 edition

0.7.0-rc1 | Aug 8, 2019 |
---|---|

0.6.1 | Jun 16, 2019 |

0.5.2 | May 23, 2019 |

0.4.1 | Sep 15, 2018 |

0.1.2 | Jul 15, 2018 |

#**6** in Machine learning

**304** downloads per month

Used in **2** crates

**MIT**license

410KB

11K
SLoC

# rv

Random variables for rust. rv offers basic functionality for many probability distributions.

## Design

Random variables are designed to be flexible. For example, we don't just want a

distribution that works with `Beta`

; we want it to work with a bunch of
things like`f64`

`extern` `crate` rand`;`
`extern` `crate` rv`;`
`use` `rv``::``prelude``::``*``;`
`//` Beta(0.5, 0.5)
`let` beta `=` `Beta``::`jeffreys`(``)``;`
`let` `mut` rng `=` `rand``::`thread_rng`(``)``;`
`//` 100 f64 weights in (0, 1)
`let` f64s`:` `Vec``<``f64``>` `=` beta`.``sample``(``100``,` `&``mut` rng`)``;`
`let` pdf_x `=` beta`.``ln_pdf``(``&`f64s`[``42``]``)``;`
`//` 100 f32 weights in (0, 1)
`let` f32s`:` `Vec``<``f32``>` `=` beta`.``sample``(``100``,` `&``mut` rng`)``;`
`let` pdf_y `=` beta`.``ln_pdf``(``&`f32s`[``42``]``)``;`
`//` 100 Bernoulli distributions -- Beta is a prior on the weight
`let` berns`:` `Vec``<`Bernoulli`>` `=` beta`.``sample``(``100``,` `&``mut` rng`)``;`
`let` pdf_bern `=` beta`.``ln_pdf``(``&`berns`[``42``]``)``;`

For more interesting examples, including use in machine learning, see

.`examples /`

## Contributing

- Please create an issue before starting any work. We're far from stable, so we might actually be working on what you want, or we might be working on something that will change the way you might implement it.
- If you plan on implementing a new distribution, implement at least

,`Rv`

, and either`Support`

or`ContinuousDistr`

. Of course, more is better!`DiscreteDistr` - Implement new distributions for the appropriate types. For example, don't
just implement

, also implement`Rv``<``f64``>`

. Check out other distributions to see how it can be done easily with macros.`Rv``<``f32``>` - Write tests, docs, and doc tests.
- Use

. We've included a`rustfmt`

in the project directory.`.`rustfmt`.`toml

#### Dependencies

~3MB

~62K SLoC