Skip to main content

RandomState

Struct RandomState 

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

RandomState for managing the state of random number generators

This struct is a wrapper around different types of random number generators. In the current implementation, it uses StdRng, but can be extended to support other RNG types in the future.

Implementations§

Source§

impl RandomState

Extend RandomState with enhanced distribution methods

Source

pub fn truncated_normal<T>( &self, mean: T, std: T, low: T, high: T, shape: &[usize], ) -> Result<Array<T>>
where T: Float + NumCast + Clone + Debug + Display,

Generate random values from a truncated normal distribution

Source

pub fn vonmises<T>(&self, mu: T, kappa: T, shape: &[usize]) -> Result<Array<T>>
where T: Float + NumCast + Clone + Debug + Display,

Generate random values from a von Mises distribution

Source

pub fn noncentral_chisquare<T>( &self, df: T, nonc: T, shape: &[usize], ) -> Result<Array<T>>
where T: Float + NumCast + Clone + Debug + Display,

Generate random values from a non-central chi-square distribution

Source

pub fn noncentral_f<T>( &self, dfnum: T, dfden: T, nonc: T, shape: &[usize], ) -> Result<Array<T>>
where T: Float + NumCast + Clone + Debug + Display,

Generate random values from a non-central F distribution

Source

pub fn maxwell<T>(&self, scale: T, shape: &[usize]) -> Result<Array<T>>
where T: Float + NumCast + Clone + Debug + Display,

Generate random values from a Maxwell distribution

Source

pub fn power<T>(&self, a: T, shape: &[usize]) -> Result<Array<T>>
where T: Float + NumCast + Clone + Debug + Display,

Generate random values from a power distribution

Source

pub fn multivariate_normal_cholesky<T>( &self, means: &[T], cov: &Array<T>, size: usize, ) -> Result<Array<T>>
where T: Float + NumCast + Clone + Debug + Display,

Generate correlated random variables using the Cholesky decomposition

Source

pub fn random_correlation_matrix<T>(&self, n: usize) -> Result<Array<T>>

Generate a random correlation matrix

Source

pub fn mixture_of_normals<T>( &self, weights: &[T], means: &[T], stds: &[T], shape: &[usize], ) -> Result<Array<T>>
where T: Float + NumCast + Clone + Debug + Display,

Generate random samples from a mixture of distributions

Source

pub fn sobol_sequence<T>(&self, dim: usize, n: usize) -> Result<Array<T>>
where T: Float + NumCast + Clone + Debug + Display,

Generate Sobol sequence for quasi-Monte Carlo methods

Source

pub fn latin_hypercube<T>(&self, dim: usize, n: usize) -> Result<Array<T>>
where T: Float + NumCast + Clone + Debug + Display,

Generate Latin Hypercube samples

Source

pub fn copula<T>( &self, corr: &Array<T>, n: usize, copula_type: &str, ) -> Result<Array<T>>
where T: Float + NumCast + Clone + Debug + Display,

Generate copula samples with a specified correlation structure

Source§

impl RandomState

Source

pub fn new() -> Self

Create a new RandomState with a random seed

Source

pub fn with_seed(seed: u64) -> Self

Create a new RandomState with the given seed

Source

pub fn get_rng(&self) -> Result<MutexGuard<'_, StdRng>>

Get a locked reference to the RNG

Source

pub fn random<T>(&self, shape: &[usize]) -> Result<Array<T>>

Generate uniform random values in [0, 1)

Source

pub fn integers<T: Clone + PartialOrd + SampleUniform + Into<i64> + TryFrom<i64> + ToPrimitive>( &self, low: T, high: T, shape: &[usize], ) -> Result<Array<T>>
where <T as TryFrom<i64>>::Error: Debug,

Generate integers in the range [low, high)

§Arguments
  • low - Lower bound (inclusive)
  • high - Upper bound (exclusive)
  • shape - Shape of the output array
§Returns

An array of random integers.

Source

pub fn normal<T: Float + NumCast + Clone + Debug + Display>( &self, mean: T, std: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a normal (Gaussian) distribution

Source

pub fn lognormal<T: Float + NumCast + Clone + Debug + Display>( &self, mean: T, sigma: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a log-normal distribution

Source

pub fn beta<T: Float + NumCast + Clone + Debug + Display>( &self, a: T, b: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Beta distribution

Source

pub fn chisquare<T: Float + NumCast + Clone + Debug + Display>( &self, df: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Chi-Square distribution

Source

pub fn dirichlet<T: Float + NumCast + Clone + Debug + Display>( &self, alpha: &[T], shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Dirichlet distribution

Source

pub fn student_t<T: Float + NumCast + Clone + Debug + Display>( &self, df: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Student’s t-distribution

Source

pub fn poisson<T: NumCast + Clone + Debug>( &self, lam: f64, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Poisson distribution

Source

pub fn binomial<T: NumCast + Clone + Debug>( &self, n: u64, p: f64, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Binomial distribution

Source

pub fn cauchy<T: Float + NumCast + Clone + Debug + Display>( &self, loc: T, scale: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Cauchy (Lorentz) distribution

Source

pub fn uniform<T: Clone + PartialOrd + SampleUniform + ToPrimitive + NumCast>( &self, low: T, high: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a uniform distribution

Source

pub fn bernoulli<T: Float + NumCast + Clone + Debug + Display>( &self, p: T, shape: &[usize], ) -> Result<Array<T>>

Generate binary random values with given probability of success

Source

pub fn gamma<T: Float + NumCast + Clone + Debug + Display>( &self, shape_param: T, scale: T, size_shape: &[usize], ) -> Result<Array<T>>

Generate random values from a gamma distribution

Source

pub fn exponential<T: Float + NumCast + Clone + Debug + Display>( &self, scale: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from an exponential distribution

Source

pub fn weibull<T: Float + NumCast + Clone + Debug + Display>( &self, shape_param: T, scale: T, size_shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Weibull distribution

Source

pub fn shuffle<T: Clone>(&self, array: &mut Array<T>) -> Result<()>

Shuffle an array in-place

Source

pub fn choice<T: Clone>( &self, array: &Array<T>, size: Option<usize>, replace: Option<bool>, ) -> Result<Array<T>>

Random choice from elements in an array

Source

pub fn permutation<T: NumCast + Clone>(&self, n: usize) -> Result<Array<T>>

Generate a permutation of integers from 0 to n-1

Source

pub fn standard_normal<T: Float + NumCast + Clone + Debug + Display>( &self, shape: &[usize], ) -> Result<Array<T>>

Generate a standard normal distribution

Source

pub fn pareto<T: Float + NumCast + Clone + Debug + Display>( &self, alpha: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Pareto distribution

Source

pub fn triangular<T: Float + NumCast + Clone + Debug + Display>( &self, low: T, mode: T, high: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Triangular distribution

Source

pub fn pert<T: Float + NumCast + Clone + Debug + Display>( &self, min: T, mode: T, max: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a PERT distribution

Source§

impl RandomState

Source

pub fn multivariate_normal<T: Float + NumCast + Clone + Debug + Display>( &self, mean: &[T], cov: &Array<T>, size: Option<&[usize]>, ) -> Result<Array<T>>

Generate random values from a multivariate normal distribution

Source

pub fn multivariate_normal_with_rotation<T: Float + NumCast + Clone + Debug + Display>( &self, mean: &[T], cov: &Array<T>, size: Option<&[usize]>, rotation: Option<&Array<T>>, ) -> Result<Array<T>>

Generate random values from a multivariate normal distribution with rotation

§Arguments
  • mean - Mean vector
  • cov - Covariance matrix
  • size - Optional shape of the output array
  • rotation - Optional rotation matrix
§Returns

An array of random values from the multivariate normal distribution with rotation

Source

pub fn laplace<T: Float + NumCast + Clone + Debug + Display>( &self, loc: T, scale: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Laplace (double exponential) distribution

Source

pub fn gumbel<T: Float + NumCast + Clone + Debug + Display>( &self, loc: T, scale: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Gumbel distribution

Source

pub fn logistic<T: Float + NumCast + Clone + Debug + Display>( &self, loc: T, scale: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a logistic distribution

Source

pub fn rayleigh<T: Float + NumCast + Clone + Debug + Display>( &self, scale: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a rayleigh distribution

Source

pub fn wald<T: Float + NumCast + Clone + Debug + Display>( &self, mean: T, scale: T, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Wald (inverse Gaussian) distribution

Source

pub fn negative_binomial<T: NumCast + Clone + Debug>( &self, n: f64, p: f64, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a negative binomial distribution

Source

pub fn geometric<T: NumCast + Clone + Debug>( &self, p: f64, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a geometric distribution

Source

pub fn multinomial<T: NumCast + Clone + Debug>( &self, n: usize, pvals: &[f64], shape: Option<&[usize]>, ) -> Result<Array<T>>

Generate random values from a multinomial distribution

Source

pub fn hypergeometric<T: NumCast + Clone + Debug>( &self, ngood: usize, nbad: usize, nsample: usize, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a hypergeometric distribution

Source

pub fn zipf<T: NumCast + Clone + Debug>( &self, a: f64, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a zipf distribution

Source

pub fn logseries<T: NumCast + Clone + Debug>( &self, p: f64, shape: &[usize], ) -> Result<Array<T>>

Generate random values from a logseries distribution

Source

pub fn multivariate_t<T: Float + NumCast + Clone + Debug + Display>( &self, mean: &[T], cov: &Array<T>, df: T, size: Option<&[usize]>, ) -> Result<Array<T>>

Generate random values from a multivariate t-distribution

The multivariate t-distribution is a generalization of the Student’s t-distribution to multiple dimensions. It’s characterized by a mean vector, covariance matrix, and degrees of freedom parameter.

§Arguments
  • mean - Mean vector (length n)
  • cov - Covariance matrix (n x n, must be positive definite)
  • df - Degrees of freedom (must be positive)
  • size - Optional shape of the output array
§Returns

An array of random values from the multivariate t-distribution

§Errors

Returns an error if:

  • Mean vector is empty
  • Covariance matrix is not square or doesn’t match mean vector dimensions
  • Covariance matrix is not positive definite
  • Degrees of freedom is not positive
Source

pub fn wishart<T: Float + NumCast + Clone + Debug + Display>( &self, df: T, scale: &Array<T>, size: Option<&[usize]>, ) -> Result<Array<T>>

Generate random values from a Wishart distribution

The Wishart distribution is a generalization of the chi-squared distribution to positive-definite matrices. It’s commonly used as the conjugate prior for the precision matrix (inverse covariance) in multivariate normal distributions.

§Arguments
  • df - Degrees of freedom (must be >= dimension of scale matrix)
  • scale - Scale matrix (positive definite, p x p)
  • size - Optional shape of the output array
§Returns

An array of random positive-definite matrices from the Wishart distribution

§Errors

Returns an error if:

  • Scale matrix is not square
  • Scale matrix is not positive definite
  • Degrees of freedom is less than the dimension
Source

pub fn frechet<T: Float + NumCast + Clone + Debug + Display>( &self, shape: T, loc: T, scale: T, output_shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Frechet distribution

The Frechet distribution (Type II extreme value distribution) is used in extreme value theory to model the maximum of a large sample of random variables.

§Arguments
  • shape - Shape parameter (alpha, must be positive)
  • loc - Location parameter
  • scale - Scale parameter (must be positive)
  • output_shape - Shape of the output array
§Returns

An array of random values from the Frechet distribution

§Errors

Returns an error if:

  • Shape parameter is not positive
  • Scale parameter is not positive
Source

pub fn gev<T: Float + NumCast + Clone + Debug + Display>( &self, shape: T, loc: T, scale: T, output_shape: &[usize], ) -> Result<Array<T>>

Generate random values from a Generalized Extreme Value (GEV) distribution

The GEV distribution combines three types of extreme value distributions:

  • Type I (Gumbel): xi = 0
  • Type II (Frechet): xi > 0
  • Type III (Weibull): xi < 0
§Arguments
  • shape - Shape parameter (xi)
  • loc - Location parameter (mu)
  • scale - Scale parameter (sigma, must be positive)
  • output_shape - Shape of the output array
§Returns

An array of random values from the GEV distribution

§Errors

Returns an error if:

  • Scale parameter is not positive

Trait Implementations§

Source§

impl Default for RandomState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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