BinomialSampler

Struct BinomialSampler 

Source
pub struct BinomialSampler { /* private fields */ }
Expand description

Enables sampling a Z according to the binomial distribution Bin(n, p).

Attributes:

  • distr: defines the binomial distribution with parameters n and p to sample from
  • rng: defines the ThreadRng that’s used to sample from distr

§Examples

use qfall_math::utils::sample::binomial::BinomialSampler;
let n = 2;
let p = 0.5;

let mut bin_sampler = BinomialSampler::init(n, p).unwrap();

let sample = bin_sampler.sample();

assert!(0 <= sample);
assert!(sample <= n);

Implementations§

Source§

impl BinomialSampler

Source

pub fn init(n: impl Into<Z>, p: impl Into<Q>) -> Result<Self, MathError>

Initializes the BinomialSampler with

  • distr as the binomial distribution with n tries and success probability p for each try, and
  • rng as a fresh ThreadRng.

Parameters:

  • n: specifies the number of tries
  • p: specifies the success probability

Returns a BinomialSampler or a MathError if n < 0, p ∉ (0,1), or n does not fit into an i64.

§Examples
use qfall_math::utils::sample::binomial::BinomialSampler;
let n = 2;
let p = 0.5;

let mut bin_sampler = BinomialSampler::init(n, p).unwrap();
§Errors and Failures
Source

pub fn sample(&mut self) -> Z

Samples a Z according to the binomial distribution Bin(n, p).

§Examples
use qfall_math::utils::sample::binomial::BinomialSampler;
let n = 2;
let p = 0.5;

let mut bin_sampler = BinomialSampler::init(n, p).unwrap();

let sample = bin_sampler.sample();

assert!(0 <= sample);
assert!(sample <= n);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V