Trait Initialize

Source
pub trait Initialize<S, D>: Sized
where D: Dimension, S: RawData,
{
Show 15 methods // Required methods fn rand<Sh, Ds>(shape: Sh, distr: Ds) -> Self where Ds: Distribution<<S as RawData>::Elem>, Sh: ShapeBuilder<Dim = D>, S: DataOwned; fn rand_with<Sh, Ds, R>(shape: Sh, distr: Ds, rng: &mut R) -> Self where R: RngCore + ?Sized, Ds: Distribution<<S as RawData>::Elem>, Sh: ShapeBuilder<Dim = D>, S: DataOwned; // Provided methods fn bernoulli<Sh>(shape: Sh, p: f64) -> Result<Self, BernoulliError> where Bernoulli: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D> { ... } fn glorot_normal<Sh>(shape: Sh) -> Self where Sh: ShapeBuilder<Dim = D>, StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, <S as RawData>::Elem: Float + FromPrimitive { ... } fn glorot_uniform<Sh>(shape: Sh) -> Result<Self, InitError> where S: DataOwned, Sh: ShapeBuilder<Dim = D>, <S as RawData>::Elem: Float + FromPrimitive + SampleUniform, <<S as RawData>::Elem as SampleUniform>::Sampler: Clone { ... } fn lecun_normal<Sh>(shape: Sh) -> Self where StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D>, <S as RawData>::Elem: Float { ... } fn normal<Sh>( shape: Sh, mean: <S as RawData>::Elem, std: <S as RawData>::Elem, ) -> Result<Self, Error> where StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D>, <S as RawData>::Elem: Float { ... } fn randc<Sh>( shape: Sh, re: <S as RawData>::Elem, im: <S as RawData>::Elem, ) -> Self where S: DataOwned, Sh: ShapeBuilder<Dim = D>, ComplexDistribution<<S as RawData>::Elem>: Distribution<<S as RawData>::Elem> { ... } fn stdnorm<Sh>(shape: Sh) -> Self where StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D> { ... } fn stdnorm_from_seed<Sh>(shape: Sh, seed: u64) -> Self where StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D> { ... } fn truncnorm<Sh>( shape: Sh, mean: <S as RawData>::Elem, std: <S as RawData>::Elem, ) -> Result<Self, InitError> where StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D>, <S as RawData>::Elem: Float { ... } fn uniform<Sh>( shape: Sh, dk: <S as RawData>::Elem, ) -> Result<Self, InitError> where S: DataOwned, Sh: ShapeBuilder<Dim = D>, <S as RawData>::Elem: Clone + Neg<Output = <S as RawData>::Elem> + SampleUniform, <<S as RawData>::Elem as SampleUniform>::Sampler: Clone { ... } fn uniform_from_seed<Sh>( shape: Sh, start: <S as RawData>::Elem, stop: <S as RawData>::Elem, key: u64, ) -> Result<Self, InitError> where S: DataOwned, Sh: ShapeBuilder<Dim = D>, <S as RawData>::Elem: Clone + SampleUniform, <<S as RawData>::Elem as SampleUniform>::Sampler: Clone { ... } fn uniform_along<Sh>(shape: Sh, axis: usize) -> Result<Self, InitError> where Sh: ShapeBuilder<Dim = D>, S: DataOwned, <S as RawData>::Elem: Float + FromPrimitive + SampleUniform, <<S as RawData>::Elem as SampleUniform>::Sampler: Clone { ... } fn uniform_between<Sh>( shape: Sh, a: <S as RawData>::Elem, b: <S as RawData>::Elem, ) -> Result<Self, InitError> where Sh: ShapeBuilder<Dim = D>, S: DataOwned, <S as RawData>::Elem: Clone + SampleUniform, <<S as RawData>::Elem as SampleUniform>::Sampler: Clone { ... }
}
Expand description

This trait provides the base methods required for initializing tensors with random values. The trait is similar to the RandomExt trait provided by the ndarray_rand crate, however, it is designed to be more generic, extensible, and optimized for neural network initialization routines. Initialize is implemented for ArrayBase as well as ParamsBase allowing you to randomly initialize new tensors and parameters.

Required Methods§

Source

fn rand<Sh, Ds>(shape: Sh, distr: Ds) -> Self
where Ds: Distribution<<S as RawData>::Elem>, Sh: ShapeBuilder<Dim = D>, S: DataOwned,

Source

fn rand_with<Sh, Ds, R>(shape: Sh, distr: Ds, rng: &mut R) -> Self
where R: RngCore + ?Sized, Ds: Distribution<<S as RawData>::Elem>, Sh: ShapeBuilder<Dim = D>, S: DataOwned,

Provided Methods§

Source

fn bernoulli<Sh>(shape: Sh, p: f64) -> Result<Self, BernoulliError>
where Bernoulli: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

Source

fn glorot_normal<Sh>(shape: Sh) -> Self

Initialize the object according to the Glorot Initialization scheme.

Source

fn glorot_uniform<Sh>(shape: Sh) -> Result<Self, InitError>

Initialize the object according to the Glorot Initialization scheme.

Source

fn lecun_normal<Sh>(shape: Sh) -> Self
where StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D>, <S as RawData>::Elem: Float,

Initialize the object according to the Lecun Initialization scheme. LecunNormal distributions are truncated Normal distributions centered at 0 with a standard deviation equal to the square root of the reciprocal of the number of inputs.

Source

fn normal<Sh>( shape: Sh, mean: <S as RawData>::Elem, std: <S as RawData>::Elem, ) -> Result<Self, Error>
where StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D>, <S as RawData>::Elem: Float,

Given a shape, mean, and standard deviation generate a new object using the Normal distribution

Source

fn randc<Sh>( shape: Sh, re: <S as RawData>::Elem, im: <S as RawData>::Elem, ) -> Self
where S: DataOwned, Sh: ShapeBuilder<Dim = D>, ComplexDistribution<<S as RawData>::Elem>: Distribution<<S as RawData>::Elem>,

Source

fn stdnorm<Sh>(shape: Sh) -> Self
where StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

Generate a random array using the StandardNormal distribution

Source

fn stdnorm_from_seed<Sh>(shape: Sh, seed: u64) -> Self
where StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

Generate a random array using the StandardNormal distribution with a given seed

Source

fn truncnorm<Sh>( shape: Sh, mean: <S as RawData>::Elem, std: <S as RawData>::Elem, ) -> Result<Self, InitError>
where StandardNormal: Distribution<<S as RawData>::Elem>, S: DataOwned, Sh: ShapeBuilder<Dim = D>, <S as RawData>::Elem: Float,

Initialize the object using the TruncatedNormal distribution

Source

fn uniform<Sh>(shape: Sh, dk: <S as RawData>::Elem) -> Result<Self, InitError>
where S: DataOwned, Sh: ShapeBuilder<Dim = D>, <S as RawData>::Elem: Clone + Neg<Output = <S as RawData>::Elem> + SampleUniform, <<S as RawData>::Elem as SampleUniform>::Sampler: Clone,

initialize the object using the Uniform distribution with values bounded by +/- dk

Source

fn uniform_from_seed<Sh>( shape: Sh, start: <S as RawData>::Elem, stop: <S as RawData>::Elem, key: u64, ) -> Result<Self, InitError>
where S: DataOwned, Sh: ShapeBuilder<Dim = D>, <S as RawData>::Elem: Clone + SampleUniform, <<S as RawData>::Elem as SampleUniform>::Sampler: Clone,

randomly initialize the object using the Uniform distribution with values between the start and stop params using some random seed.

Source

fn uniform_along<Sh>(shape: Sh, axis: usize) -> Result<Self, InitError>

initialize the object using the Uniform distribution with values bounded by the size of the specified axis. The values are bounded by +/- dk where dk = 1 / size(axis).

Source

fn uniform_between<Sh>( shape: Sh, a: <S as RawData>::Elem, b: <S as RawData>::Elem, ) -> Result<Self, InitError>
where Sh: ShapeBuilder<Dim = D>, S: DataOwned, <S as RawData>::Elem: Clone + SampleUniform, <<S as RawData>::Elem as SampleUniform>::Sampler: Clone,

initialize the object using the Uniform distribution with values between then given bounds, a and b.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<A, S, D> Initialize<S, D> for ArrayBase<S, D>
where D: Dimension, S: RawData<Elem = A>,

Source§

fn rand<Sh, Ds>(shape: Sh, distr: Ds) -> ArrayBase<S, D>
where Ds: Distribution<<S as RawData>::Elem>, Sh: ShapeBuilder<Dim = D>, S: DataOwned,

Source§

fn rand_with<Sh, Ds, R>(shape: Sh, distr: Ds, rng: &mut R) -> ArrayBase<S, D>
where R: Rng + ?Sized, Ds: Distribution<<S as RawData>::Elem>, Sh: ShapeBuilder<Dim = D>, S: DataOwned,

Implementors§

Source§

impl<A, S, D> Initialize<S, D> for ParamsBase<S, D>
where D: RemoveAxis, S: RawData<Elem = A>,