Chi

Struct Chi 

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

Chi Distribution

This struct represents the Chi distribution, which is a special case of the gamma distribution with a shape parameter equal to half the degrees of freedom. It is useful in various statistical applications, including hypothesis testing and confidence interval estimation.

§Example

let mut chi = rand_simple::Chi::new([1192_u32, 765_u32, 1543_u32, 2003_u32]);

// Verify the initial state
assert_eq!(format!("{chi}"), "χ(Degree of Freedom parameter) = χ(1)");

// Generate a random number from the Chi distribution with 1 degree of freedom
println!("Initial setting: Random number from Chi distribution with 1 degree of freedom -> {}", chi.sample());

// Change the degrees of freedom
let degree_of_freedom: u64 = 2_u64;
let result: Result<u64, &str> = chi.try_set_params(degree_of_freedom);

// Verify the new state
assert_eq!(format!("{chi}"), "χ(Degree of Freedom parameter) = χ(2)");

// Generate a random number from the Chi distribution with the updated degrees of freedom
println!("Updated setting: Random number from Chi distribution with {} degrees of freedom -> {}", degree_of_freedom, chi.sample());

§Fields

  • xyzuv_u_gamma - State variable for gamma distribution random number generation
  • xyzuv_n_0_gamma - State variable for gamma distribution random number generation
  • xyzuv_n_1_gamma - State variable for gamma distribution random number generation
  • xyzuv_uniform - State variable for uniform distribution random number generation
  • degree_of_freedom - Degrees of freedom, must be a positive integer

Implementations§

Source§

impl Chi

Source

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

Constructor for the Chi struct

§Arguments
  • seeds - An array of 4 unsigned 32-bit integers used as seeds for the random number generators. The seeds are adjusted to ensure they are unique and suitable for the random number generation.
Source

pub fn sample(&mut self) -> f64

Generates a random number following the Chi distribution.

Source

pub fn try_set_params(&mut self, degree_of_freedom: u64) -> Result<u64, &str>

Updates the parameters of the random variable.

§Parameters
  • degree_of_freedom - The degrees of freedom r (should be a natural number).

Trait Implementations§

Source§

impl Display for Chi

Source§

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

Formatter for displaying in macros like println!

Auto Trait Implementations§

§

impl Freeze for Chi

§

impl RefUnwindSafe for Chi

§

impl Send for Chi

§

impl Sync for Chi

§

impl Unpin for Chi

§

impl UnwindSafe for Chi

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.