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
impl RandomState
Extend RandomState with enhanced distribution methods
Sourcepub fn truncated_normal<T>(
&self,
mean: T,
std: T,
low: T,
high: T,
shape: &[usize],
) -> Result<Array<T>>
pub fn truncated_normal<T>( &self, mean: T, std: T, low: T, high: T, shape: &[usize], ) -> Result<Array<T>>
Generate random values from a truncated normal distribution
Sourcepub fn vonmises<T>(&self, mu: T, kappa: T, shape: &[usize]) -> Result<Array<T>>
pub fn vonmises<T>(&self, mu: T, kappa: T, shape: &[usize]) -> Result<Array<T>>
Generate random values from a von Mises distribution
Sourcepub fn noncentral_chisquare<T>(
&self,
df: T,
nonc: T,
shape: &[usize],
) -> Result<Array<T>>
pub fn noncentral_chisquare<T>( &self, df: T, nonc: T, shape: &[usize], ) -> Result<Array<T>>
Generate random values from a non-central chi-square distribution
Sourcepub fn noncentral_f<T>(
&self,
dfnum: T,
dfden: T,
nonc: T,
shape: &[usize],
) -> Result<Array<T>>
pub fn noncentral_f<T>( &self, dfnum: T, dfden: T, nonc: T, shape: &[usize], ) -> Result<Array<T>>
Generate random values from a non-central F distribution
Sourcepub fn maxwell<T>(&self, scale: T, shape: &[usize]) -> Result<Array<T>>
pub fn maxwell<T>(&self, scale: T, shape: &[usize]) -> Result<Array<T>>
Generate random values from a Maxwell distribution
Sourcepub fn power<T>(&self, a: T, shape: &[usize]) -> Result<Array<T>>
pub fn power<T>(&self, a: T, shape: &[usize]) -> Result<Array<T>>
Generate random values from a power distribution
Sourcepub fn multivariate_normal_cholesky<T>(
&self,
means: &[T],
cov: &Array<T>,
size: usize,
) -> Result<Array<T>>
pub fn multivariate_normal_cholesky<T>( &self, means: &[T], cov: &Array<T>, size: usize, ) -> Result<Array<T>>
Generate correlated random variables using the Cholesky decomposition
Sourcepub fn random_correlation_matrix<T>(&self, n: usize) -> Result<Array<T>>
pub fn random_correlation_matrix<T>(&self, n: usize) -> Result<Array<T>>
Generate a random correlation matrix
Sourcepub fn mixture_of_normals<T>(
&self,
weights: &[T],
means: &[T],
stds: &[T],
shape: &[usize],
) -> Result<Array<T>>
pub fn mixture_of_normals<T>( &self, weights: &[T], means: &[T], stds: &[T], shape: &[usize], ) -> Result<Array<T>>
Generate random samples from a mixture of distributions
Sourcepub fn sobol_sequence<T>(&self, dim: usize, n: usize) -> Result<Array<T>>
pub fn sobol_sequence<T>(&self, dim: usize, n: usize) -> Result<Array<T>>
Generate Sobol sequence for quasi-Monte Carlo methods
Source§impl RandomState
impl RandomState
Sourcepub fn get_rng(&self) -> Result<MutexGuard<'_, StdRng>>
pub fn get_rng(&self) -> Result<MutexGuard<'_, StdRng>>
Get a locked reference to the RNG
Sourcepub fn random<T>(&self, shape: &[usize]) -> Result<Array<T>>
pub fn random<T>(&self, shape: &[usize]) -> Result<Array<T>>
Generate uniform random values in [0, 1)
Sourcepub fn integers<T: Clone + PartialOrd + SampleUniform + Into<i64> + TryFrom<i64> + ToPrimitive>(
&self,
low: T,
high: T,
shape: &[usize],
) -> Result<Array<T>>
pub fn integers<T: Clone + PartialOrd + SampleUniform + Into<i64> + TryFrom<i64> + ToPrimitive>( &self, low: T, high: T, shape: &[usize], ) -> Result<Array<T>>
Sourcepub fn normal<T: Float + NumCast + Clone + Debug + Display>(
&self,
mean: T,
std: T,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn lognormal<T: Float + NumCast + Clone + Debug + Display>(
&self,
mean: T,
sigma: T,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn beta<T: Float + NumCast + Clone + Debug + Display>(
&self,
a: T,
b: T,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn chisquare<T: Float + NumCast + Clone + Debug + Display>(
&self,
df: T,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn dirichlet<T: Float + NumCast + Clone + Debug + Display>(
&self,
alpha: &[T],
shape: &[usize],
) -> Result<Array<T>>
pub fn dirichlet<T: Float + NumCast + Clone + Debug + Display>( &self, alpha: &[T], shape: &[usize], ) -> Result<Array<T>>
Generate random values from a Dirichlet distribution
Sourcepub fn student_t<T: Float + NumCast + Clone + Debug + Display>(
&self,
df: T,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn poisson<T: NumCast + Clone + Debug>(
&self,
lam: f64,
shape: &[usize],
) -> Result<Array<T>>
pub fn poisson<T: NumCast + Clone + Debug>( &self, lam: f64, shape: &[usize], ) -> Result<Array<T>>
Generate random values from a Poisson distribution
Sourcepub fn binomial<T: NumCast + Clone + Debug>(
&self,
n: u64,
p: f64,
shape: &[usize],
) -> Result<Array<T>>
pub fn binomial<T: NumCast + Clone + Debug>( &self, n: u64, p: f64, shape: &[usize], ) -> Result<Array<T>>
Generate random values from a Binomial distribution
Sourcepub fn cauchy<T: Float + NumCast + Clone + Debug + Display>(
&self,
loc: T,
scale: T,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn uniform<T: Clone + PartialOrd + SampleUniform + ToPrimitive + NumCast>(
&self,
low: T,
high: T,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn bernoulli<T: Float + NumCast + Clone + Debug + Display>(
&self,
p: T,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn gamma<T: Float + NumCast + Clone + Debug + Display>(
&self,
shape_param: T,
scale: T,
size_shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn exponential<T: Float + NumCast + Clone + Debug + Display>(
&self,
scale: T,
shape: &[usize],
) -> Result<Array<T>>
pub fn exponential<T: Float + NumCast + Clone + Debug + Display>( &self, scale: T, shape: &[usize], ) -> Result<Array<T>>
Generate random values from an exponential distribution
Sourcepub fn weibull<T: Float + NumCast + Clone + Debug + Display>(
&self,
shape_param: T,
scale: T,
size_shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn choice<T: Clone>(
&self,
array: &Array<T>,
size: Option<usize>,
replace: Option<bool>,
) -> Result<Array<T>>
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
Sourcepub fn permutation<T: NumCast + Clone>(&self, n: usize) -> Result<Array<T>>
pub fn permutation<T: NumCast + Clone>(&self, n: usize) -> Result<Array<T>>
Generate a permutation of integers from 0 to n-1
Sourcepub fn standard_normal<T: Float + NumCast + Clone + Debug + Display>(
&self,
shape: &[usize],
) -> Result<Array<T>>
pub fn standard_normal<T: Float + NumCast + Clone + Debug + Display>( &self, shape: &[usize], ) -> Result<Array<T>>
Generate a standard normal distribution
Sourcepub fn pareto<T: Float + NumCast + Clone + Debug + Display>(
&self,
alpha: T,
shape: &[usize],
) -> Result<Array<T>>
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§impl RandomState
impl RandomState
Sourcepub fn multivariate_normal<T: Float + NumCast + Clone + Debug + Display>(
&self,
mean: &[T],
cov: &Array<T>,
size: Option<&[usize]>,
) -> Result<Array<T>>
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
Sourcepub 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>>
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>>
Sourcepub fn laplace<T: Float + NumCast + Clone + Debug + Display>(
&self,
loc: T,
scale: T,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn gumbel<T: Float + NumCast + Clone + Debug + Display>(
&self,
loc: T,
scale: T,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn logistic<T: Float + NumCast + Clone + Debug + Display>(
&self,
loc: T,
scale: T,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn rayleigh<T: Float + NumCast + Clone + Debug + Display>(
&self,
scale: T,
shape: &[usize],
) -> Result<Array<T>>
pub fn rayleigh<T: Float + NumCast + Clone + Debug + Display>( &self, scale: T, shape: &[usize], ) -> Result<Array<T>>
Generate random values from a rayleigh distribution
Sourcepub fn wald<T: Float + NumCast + Clone + Debug + Display>(
&self,
mean: T,
scale: T,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn negative_binomial<T: NumCast + Clone + Debug>(
&self,
n: f64,
p: f64,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn geometric<T: NumCast + Clone + Debug>(
&self,
p: f64,
shape: &[usize],
) -> Result<Array<T>>
pub fn geometric<T: NumCast + Clone + Debug>( &self, p: f64, shape: &[usize], ) -> Result<Array<T>>
Generate random values from a geometric distribution
Sourcepub fn multinomial<T: NumCast + Clone + Debug>(
&self,
n: usize,
pvals: &[f64],
shape: Option<&[usize]>,
) -> Result<Array<T>>
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
Sourcepub fn hypergeometric<T: NumCast + Clone + Debug>(
&self,
ngood: usize,
nbad: usize,
nsample: usize,
shape: &[usize],
) -> Result<Array<T>>
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
Sourcepub fn zipf<T: NumCast + Clone + Debug>(
&self,
a: f64,
shape: &[usize],
) -> Result<Array<T>>
pub fn zipf<T: NumCast + Clone + Debug>( &self, a: f64, shape: &[usize], ) -> Result<Array<T>>
Generate random values from a zipf distribution
Sourcepub fn logseries<T: NumCast + Clone + Debug>(
&self,
p: f64,
shape: &[usize],
) -> Result<Array<T>>
pub fn logseries<T: NumCast + Clone + Debug>( &self, p: f64, shape: &[usize], ) -> Result<Array<T>>
Generate random values from a logseries distribution
Sourcepub fn multivariate_t<T: Float + NumCast + Clone + Debug + Display>(
&self,
mean: &[T],
cov: &Array<T>,
df: T,
size: Option<&[usize]>,
) -> Result<Array<T>>
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
Sourcepub fn wishart<T: Float + NumCast + Clone + Debug + Display>(
&self,
df: T,
scale: &Array<T>,
size: Option<&[usize]>,
) -> Result<Array<T>>
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
Sourcepub fn frechet<T: Float + NumCast + Clone + Debug + Display>(
&self,
shape: T,
loc: T,
scale: T,
output_shape: &[usize],
) -> Result<Array<T>>
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 parameterscale- 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
Sourcepub fn gev<T: Float + NumCast + Clone + Debug + Display>(
&self,
shape: T,
loc: T,
scale: T,
output_shape: &[usize],
) -> Result<Array<T>>
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§
Auto Trait Implementations§
impl Freeze for RandomState
impl RefUnwindSafe for RandomState
impl Send for RandomState
impl Sync for RandomState
impl Unpin for RandomState
impl UnsafeUnpin for RandomState
impl UnwindSafe for RandomState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.