Struct fuzzcheck::mutators::vose_alias::VoseAlias[][src]

pub struct VoseAlias {
    pub original_probabilities: Vec<f64>,
    // some fields omitted
}
Expand description

An efficient data structure to sample from a discrete, fixed distribution.

use fuzzcheck::mutators::vose_alias::VoseAlias;

// the discrete distribution is a vector of floats which must add up to 1.0
let probabilities = vec![0.5, 0.1, 0.2, 0.2];
// create the Vose alias. The `probabilities` vector is moved to `alias.original_probabilities`.
let alias = VoseAlias::new(probabilities);

// index has a 50% chance of being 0, 10% chance of being 1, 20% chance of being 2, and 20% chance of being 2
let index = alias.sample();

assert!((0 .. 4).contains(&index));

Fields

original_probabilities: Vec<f64>

Implementations

Create a new Vose alias with the given discrete probability distribution.

Important: the probabilities must sum up to ~ 1.0

Sample the Vose alias.

It returns an index within 0 .. original_probabilities.len().

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.