categorical

Crates.iocategorical
lib.rscategorical
version0.1.3
sourcesrc
created_at2024-09-15 15:47:45.201232
updated_at2024-09-16 17:45:08.737804
descriptioncombining categorical random distributions and computing exact probabilities
homepage
repositoryhttps://github.com/m-mueller678/categorical
max_upload_size
id1375519
size10,910
(m-mueller678)

documentation

README

categorical

This crate provides a type representing a categorical probability distribution: Categorical<T,P>. A Categorical is a collection of objects of type T, each associated with a probability of type P. You can combine two Categoricals and compute the probability of each combination (assuming the two distributions are sampled independently).

use categorical::{Categorical, CategoricalHash};
let die_roll = CategoricalHash::new_uniform(vec![1, 2, 3, 4, 5, 6].into_iter());
// roll two dice and pick the higher number
let max_of_two = CategoricalHash::combined(&die_roll, &die_roll, |&a, &b| a.max(b));
let double_wins: f64 =
    CategoricalHash::combined(&max_of_two, &die_roll, |double, single| double > single)
        .probability_of(&true);
println!("player rolling two dice rolls higher with probability of {double_wins}");

License: MIT OR Apache-2.0

Commit count: 0

cargo fmt