pub struct DiscreteDistribution {
pub pmf: Vec<f64>,
}Expand description
A discrete probability distribution backed by an explicit PMF table.
Sampling uses an LCG (linear congruential generator) seeded by the caller.
Fields§
§pmf: Vec<f64>PMF values (must sum to 1).
Implementations§
Source§impl DiscreteDistribution
impl DiscreteDistribution
Sourcepub fn from_weights(weights: &[f64]) -> Self
pub fn from_weights(weights: &[f64]) -> Self
Creates a DiscreteDistribution from raw weights, normalising them.
Sourcepub fn sample(&self, u: f64) -> usize
pub fn sample(&self, u: f64) -> usize
Draws a sample using an LCG random number in [0, 1).
Pass successive LCG outputs as u to simulate multiple draws.
Sourcepub fn shannon_entropy(&self) -> f64
pub fn shannon_entropy(&self) -> f64
Computes the Shannon entropy H = -Σ p log p (nats).
Auto Trait Implementations§
impl Freeze for DiscreteDistribution
impl RefUnwindSafe for DiscreteDistribution
impl Send for DiscreteDistribution
impl Sync for DiscreteDistribution
impl Unpin for DiscreteDistribution
impl UnsafeUnpin for DiscreteDistribution
impl UnwindSafe for DiscreteDistribution
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more