Bernoulli

Struct Bernoulli 

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

Bernoulli Distribution

§Example Usage

let mut bernoulli = rand_simple::Bernoulli::new(1192u32);

// Default parameters
assert_eq!(format!("{bernoulli}"), "Bernoulli(Probability) = Bernoulli(0.5)");
println!("Does the event occur (1) or not (0) with a probability θ = 0.5? -> {}", bernoulli.sample());

// Updating the probability parameter
let probability: f64 = 0.8f64;
let result: Result<f64, &str> = bernoulli.try_set_params(probability);
assert_eq!(format!("{bernoulli}"), "Bernoulli(Probability) = Bernoulli(0.8)");
println!("Does the event occur (1) or not (0) with a probability θ = {}? -> {}", probability, bernoulli.sample());

Implementations§

Source§

impl Bernoulli

Source

pub fn new(_seed: u32) -> Self

コンストラクタ

  • _seed - 乱数の種
Source

pub fn sample(&mut self) -> u64

ある確率の事象が生じたか(1u64)、否か(0u64)を返す

Source

pub fn try_set_params(&mut self, probability: f64) -> Result<f64, &str>

確率変数のパラメータを変更する

  • probability - 尺度母数

Trait Implementations§

Source§

impl Display for Bernoulli

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formatter for displaying in functions like println! macro

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.