4 releases
0.1.3 | Sep 16, 2024 |
---|---|
0.1.2 | Sep 16, 2024 |
0.1.1 | Sep 15, 2024 |
0.1.0 | Sep 15, 2024 |
#384 in Simulation
76 downloads per month
11KB
200 lines
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
lib.rs
:
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}");
Dependencies
~150KB