Beta

Struct Beta 

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

Beta Distribution

§Example

// Create a new Beta distribution with specified random seeds
let mut beta = rand_simple::Beta::new([1192u32, 765u32, 1543u32, 2003u32, 1867u32, 1688u32]);
// Check the initial state
assert_eq!(format!("{beta}"), "Beta(Shape parameter α, Shape parameter β) = Beta(1, 1)");
// Generate a random number
println!("Returns a random number -> {}", beta.sample());

// Change the parameters of the probability variable
let shape_alpha: f64 = 2f64;
let shape_beta: f64 = 1.5f64;
let result: Result<(f64, f64), &str> = beta.try_set_params(shape_alpha, shape_beta);
// Check the updated state
assert_eq!(format!("{beta}"), "Beta(Shape parameter α, Shape parameter β) = Beta(2, 1.5)");
// Generate another random number
println!("Returns a random number -> {}", beta.sample());

Implementations§

Source§

impl Beta

Source

pub fn new(seeds: [u32; 6]) -> Self

  • seeds - Random seeds. Adjusted within the constructor to ensure uniqueness.
Source

pub fn sample(&mut self) -> f64

Returns a random number following the Beta distribution

Source

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

Updates the parameters of the probability variable

  • shape_alpha - Shape parameter α
  • shape_beta - Shape parameter β

Trait Implementations§

Source§

impl Display for Beta

Formatter for displaying Beta distribution using macros like println!

  • Struct type
  • Shape parameter α
  • Shape parameter β
Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Beta

§

impl RefUnwindSafe for Beta

§

impl Send for Beta

§

impl Sync for Beta

§

impl Unpin for Beta

§

impl UnwindSafe for Beta

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.