pub struct ArrayRng<A> { /* private fields */ }Expand description
Random number generator for ndarray
Uses ChaCha8Rng internally because StdRng does not implement Clone in rand 0.10.
Implementations§
Source§impl<A: Float> ArrayRng<A>
impl<A: Float> ArrayRng<A>
Sourcepub fn from_seed(seed: u64) -> Self
pub fn from_seed(seed: u64) -> Self
Creates a new random number generator with the specified seed.
Sourcepub fn as_rng(&self) -> &ChaCha8Rng
pub fn as_rng(&self) -> &ChaCha8Rng
Returns a reference to the internal RNG
Sourcepub fn as_rng_mut(&mut self) -> &mut ChaCha8Rng
pub fn as_rng_mut(&mut self) -> &mut ChaCha8Rng
Returns a mutable reference to the internal RNG
Sourcepub fn random(&mut self, shape: &[usize]) -> NdArray<A>
pub fn random(&mut self, shape: &[usize]) -> NdArray<A>
Creates a uniform random array in the specified shape. Values are in the range [0, 1)
Sourcepub fn normal(&mut self, shape: &[usize], mean: f64, std: f64) -> NdArray<A>
pub fn normal(&mut self, shape: &[usize], mean: f64, std: f64) -> NdArray<A>
Creates a normal random array in the specified shape. Values are drawn from a normal distribution with the specified mean and standard deviation.
Sourcepub fn uniform(&mut self, shape: &[usize], low: f64, high: f64) -> NdArray<A>
pub fn uniform(&mut self, shape: &[usize], low: f64, high: f64) -> NdArray<A>
Creates a uniform random array in the specified shape. Values are in the range [low, high).
Sourcepub fn glorot_uniform(&mut self, shape: &[usize]) -> NdArray<A>
pub fn glorot_uniform(&mut self, shape: &[usize]) -> NdArray<A>
Creates a random array with Glorot/Xavier uniform initialization. For a tensor with shape (in_features, out_features), samples are drawn from Uniform(-sqrt(6/(in_features+out_features)), sqrt(6/(in_features+out_features))).
Sourcepub fn glorot_normal(&mut self, shape: &[usize]) -> NdArray<A>
pub fn glorot_normal(&mut self, shape: &[usize]) -> NdArray<A>
Creates a random array with Glorot/Xavier normal initialization. For a tensor with shape (in_features, out_features), samples are drawn from Normal(0, sqrt(2/(in_features+out_features))).
Sourcepub fn he_uniform(&mut self, shape: &[usize]) -> NdArray<A>
pub fn he_uniform(&mut self, shape: &[usize]) -> NdArray<A>
Creates a random array with He/Kaiming uniform initialization. For a tensor with shape (in_features, out_features), samples are drawn from Uniform(-sqrt(6/in_features), sqrt(6/in_features)).
Sourcepub fn he_normal(&mut self, shape: &[usize]) -> NdArray<A>
pub fn he_normal(&mut self, shape: &[usize]) -> NdArray<A>
Creates a random array with He/Kaiming normal initialization. For a tensor with shape (in_features, out_features), samples are drawn from Normal(0, sqrt(2/in_features)).
Sourcepub fn standard_normal(&mut self, shape: &[usize]) -> NdArray<A>
pub fn standard_normal(&mut self, shape: &[usize]) -> NdArray<A>
Creates a random array from the standard normal distribution.
Sourcepub fn standard_uniform(&mut self, shape: &[usize]) -> NdArray<A>
pub fn standard_uniform(&mut self, shape: &[usize]) -> NdArray<A>
Creates a random array from the standard uniform distribution.
Sourcepub fn bernoulli(&mut self, shape: &[usize], p: f64) -> NdArray<A>
pub fn bernoulli(&mut self, shape: &[usize], p: f64) -> NdArray<A>
Creates a random array from the bernoulli distribution.
Sourcepub fn exponential(&mut self, shape: &[usize], lambda: f64) -> NdArray<A>
pub fn exponential(&mut self, shape: &[usize], lambda: f64) -> NdArray<A>
Creates a random array from the exponential distribution.
Trait Implementations§
Auto Trait Implementations§
impl<A> Freeze for ArrayRng<A>
impl<A> RefUnwindSafe for ArrayRng<A>where
A: RefUnwindSafe,
impl<A> Send for ArrayRng<A>where
A: Send,
impl<A> Sync for ArrayRng<A>where
A: Sync,
impl<A> Unpin for ArrayRng<A>where
A: Unpin,
impl<A> UnsafeUnpin for ArrayRng<A>
impl<A> UnwindSafe for ArrayRng<A>where
A: UnwindSafe,
Blanket Implementations§
Source§impl<R> TryRngCore for Rwhere
R: TryRng,
impl<R> TryRngCore for Rwhere
R: TryRng,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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<R> RngExt for R
impl<R> RngExt for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T> ⓘ
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T> ⓘ
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
numerator/denominator of being
true. Read more