Crates.io | categorical |
lib.rs | categorical |
version | 0.1.3 |
source | src |
created_at | 2024-09-15 15:47:45.201232 |
updated_at | 2024-09-16 17:45:08.737804 |
description | combining categorical random distributions and computing exact probabilities |
homepage | |
repository | https://github.com/m-mueller678/categorical |
max_upload_size | |
id | 1375519 |
size | 10,910 |
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