Struct ParamsBase

Source
pub struct ParamsBase<S, D = Ix2>
where D: Dimension, S: RawData,
{ /* private fields */ }
Expand description

this structure extends the ArrayBase type to include bias

Implementations§

Source§

impl<A, S, D> ParamsBase<S, D>
where D: Dimension, S: RawData<Elem = A>,

Source

pub fn new(bias: ArrayBase<S, D::Smaller>, weights: ArrayBase<S, D>) -> Self
where A: Clone, S: DataOwned,

Source

pub fn from_elems<Sh>(shape: Sh, elem: A) -> Self
where A: Clone, D: RemoveAxis, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

Source

pub fn default<Sh>(shape: Sh) -> Self
where A: Clone + Default, D: RemoveAxis, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

create an instance of the parameters with all values set to the default value

Source

pub fn ones<Sh>(shape: Sh) -> Self
where A: Clone + One, D: RemoveAxis, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

initialize the parameters with all values set to zero

Source

pub fn zeros<Sh>(shape: Sh) -> Self
where A: Clone + Zero, D: RemoveAxis, S: DataOwned, Sh: ShapeBuilder<Dim = D>,

create an instance of the parameters with all values set to zero

Source

pub const fn bias(&self) -> &ArrayBase<S, D::Smaller>

returns an immutable reference to the bias

Source

pub fn bias_mut(&mut self) -> &mut ArrayBase<S, D::Smaller>

returns a mutable reference to the bias

Source

pub const fn weights(&self) -> &ArrayBase<S, D>

returns an immutable reference to the weights

Source

pub fn weights_mut(&mut self) -> &mut ArrayBase<S, D>

returns a mutable reference to the weights

Source

pub fn backward<X, Y, Z>(&mut self, input: &X, grad: &Y, lr: A) -> Result<Z>
where A: Clone, S: Data, Self: Backward<X, Y, HParam = A, Output = Z>,

perform a single backpropagation step

Source

pub fn forward<X, Y>(&self, input: &X) -> Result<Y>
where A: Clone, S: Data, Self: Forward<X, Output = Y>,

forward propagation

Source

pub fn dim(&self) -> D::Pattern

returns the dimensions of the weights

Source

pub fn iter(&self) -> Iter<'_, A, D>
where D: RemoveAxis, S: Data,

an iterator of the parameters; the created iterator zips together an axis iterator over the columns of the weights and an iterator over the bias

Source

pub fn iter_mut( &mut self, ) -> Zip<AxisIterMut<'_, A, D::Smaller>, IterMut<'_, A, D::Smaller>>
where D: RemoveAxis, S: DataMut,

a mutable iterator of the parameters

Source

pub fn iter_bias(&self) -> Iter<'_, A, D::Smaller>
where S: Data,

returns an iterator over the bias

Source

pub fn iter_bias_mut(&mut self) -> IterMut<'_, A, D::Smaller>
where S: DataMut,

returns a mutable iterator over the bias

Source

pub fn iter_weights(&self) -> Iter<'_, A, D>
where S: Data,

returns an iterator over the weights

Source

pub fn iter_weights_mut(&mut self) -> IterMut<'_, A, D>
where S: DataMut,

returns a mutable iterator over the weights; see iter_mut for more

Source

pub fn len(&self) -> usize

the total number of elements within the weight tensor

Source

pub fn raw_dim(&self) -> D

returns the raw dimensions of the weights;

Source

pub fn shape(&self) -> &[usize]

returns the shape of the parameters; uses the shape of the weight tensor

Source

pub fn shape_bias(&self) -> &[usize]

returns the shape of the bias tensor; the shape should be equivalent to that of the weight tensor minus the “zero-th” axis

Source

pub fn to_owned(&self) -> ParamsBase<OwnedRepr<A>, D>
where A: Clone, S: DataOwned,

returns an owned instance of the parameters

Source

pub fn to_shape<Sh>( &self, shape: Sh, ) -> Result<ParamsBase<CowRepr<'_, A>, Sh::Dim>>
where A: Clone, S: DataOwned, Sh: ShapeBuilder, Sh::Dim: Dimension + RemoveAxis,

change the shape of the parameters; the shape of the bias parameters is determined by removing the “zero-th” axis of the given shape

Source

pub fn view(&self) -> ParamsBase<ViewRepr<&A>, D>
where S: Data,

returns a “view” of the parameters; see view for more information

Source

pub fn view_mut(&mut self) -> ParamsBase<ViewRepr<&mut A>, D>
where S: DataMut,

returns mutable view of the parameters; see view_mut for more information

Source§

impl<A, S> ParamsBase<S, Ix1>
where S: RawData<Elem = A>,

Source

pub fn from_scalar_bias(bias: A, weights: ArrayBase<S, Ix1>) -> Self
where A: Clone, S: DataOwned,

Source

pub fn nrows(&self) -> usize

Source§

impl<A, S> ParamsBase<S, Ix2>
where S: RawData<Elem = A>,

Source

pub fn ncols(&self) -> usize

Source

pub fn nrows(&self) -> usize

Source§

impl<A, S, D> ParamsBase<S, D>
where A: ScalarOperand + Float + FromPrimitive, D: Dimension, S: Data<Elem = A>,

Source

pub fn l1_norm(&self) -> A

Returns the L1 norm of the parameters (bias and weights).

Source

pub fn l2_norm(&self) -> A

Returns the L2 norm of the parameters (bias and weights).

Source

pub fn apply_gradient<Grad, Z>(&mut self, grad: &Grad, lr: A) -> Result<Z>
where S: DataMut, Self: ApplyGradient<Grad, A, Output = Z>,

Source

pub fn apply_gradient_with_decay<Grad, Z>( &mut self, grad: &Grad, lr: A, decay: A, ) -> Result<Z>
where S: DataMut, Self: ApplyGradient<Grad, A, Output = Z>,

Source

pub fn apply_gradient_with_momentum<Grad, V, Z>( &mut self, grad: &Grad, lr: A, momentum: A, velocity: &mut V, ) -> Result<Z>
where S: DataMut, Self: ApplyGradientExt<Grad, A, Output = Z, Velocity = V>,

Source

pub fn apply_gradient_with_decay_and_momentum<Grad, V, Z>( &mut self, grad: &Grad, lr: A, decay: A, momentum: A, velocity: &mut V, ) -> Result<Z>
where S: DataMut, Self: ApplyGradientExt<Grad, A, Output = Z, Velocity = V>,

Trait Implementations§

Source§

impl<A, S, T, D> ApplyGradient<ParamsBase<T, D>, A> for ParamsBase<S, D>
where A: Float + FromPrimitive + ScalarOperand, S: DataMut<Elem = A>, T: Data<Elem = A>, D: Dimension,

Source§

type Output = ()

Source§

fn apply_gradient( &mut self, grad: &ParamsBase<T, D>, lr: A, ) -> Result<Self::Output>

Source§

fn apply_gradient_with_decay( &mut self, grad: &ParamsBase<T, D>, lr: A, decay: A, ) -> Result<Self::Output>

Source§

impl<A, S, T, D> ApplyGradientExt<ParamsBase<T, D>, A> for ParamsBase<S, D>
where A: Float + FromPrimitive + ScalarOperand, S: DataMut<Elem = A>, T: Data<Elem = A>, D: Dimension,

Source§

type Velocity = ParamsBase<OwnedRepr<A>, D>

Source§

fn apply_gradient_with_momentum( &mut self, grad: &ParamsBase<T, D>, lr: A, momentum: A, velocity: &mut Self::Velocity, ) -> Result<()>

Source§

fn apply_gradient_with_decay_and_momentum( &mut self, grad: &ParamsBase<T, D>, lr: A, decay: A, momentum: A, velocity: &mut Self::Velocity, ) -> Result<()>

Source§

impl<A, S, D> Clone for ParamsBase<S, D>
where D: Dimension, S: RawDataClone<Elem = A>, A: Clone,

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A, S, D> Debug for ParamsBase<S, D>
where D: Dimension, S: Data<Elem = A>, A: Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<A, X, Y, Z, S, D> Forward<X> for ParamsBase<S, D>
where A: Clone, D: Dimension, S: Data<Elem = A>, for<'a> X: Dot<ArrayBase<S, D>, Output = Y>, Y: for<'a> Add<&'a ArrayBase<S, D::Smaller>, Output = Z>,

Source§

type Output = Z

Source§

fn forward(&self, input: &X) -> Result<Self::Output>

Source§

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

Source§

type Data = S

Source§

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

Source§

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

Source§

impl<A, S, D> PartialEq for ParamsBase<S, D>
where D: Dimension, S: Data<Elem = A>, A: PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A, S, D> Copy for ParamsBase<S, D>
where D: Dimension + Copy, <D as Dimension>::Smaller: Copy, S: RawDataClone<Elem = A> + Copy, A: Copy,

Source§

impl<A, S, D> Eq for ParamsBase<S, D>
where D: Dimension, S: Data<Elem = A>, A: Eq,

Auto Trait Implementations§

§

impl<S, D> Freeze for ParamsBase<S, D>
where S: Freeze, <D as Dimension>::Smaller: Freeze, D: Freeze,

§

impl<S, D> RefUnwindSafe for ParamsBase<S, D>

§

impl<S, D> Send for ParamsBase<S, D>
where S: Send + Data,

§

impl<S, D> Sync for ParamsBase<S, D>
where S: Sync + Data,

§

impl<S, D> Unpin for ParamsBase<S, D>
where S: Unpin, <D as Dimension>::Smaller: Unpin, D: Unpin,

§

impl<S, D> UnwindSafe for ParamsBase<S, D>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<K, S> Id<K> for S
where S: Borrow<K>, K: Identifier,

Source§

type Item = S

Source§

fn get(&self) -> &<S as Id<K>>::Item

Source§

impl<U, A, S, D> InitializeExt<A, D> for U
where A: Clone, D: Dimension, S: DataOwned<Elem = A>, U: Initialize<A, D, Data = S>,

Source§

fn bernoulli<Sh: ShapeBuilder<Dim = D>>( shape: Sh, p: f64, ) -> Result<Self, BernoulliError>

Source§

fn glorot_normal<Sh>(shape: Sh, inputs: usize, outputs: usize) -> Self
where A: Float + FromPrimitive, Sh: ShapeBuilder<Dim = D>, StandardNormal: Distribution<A>, Self::Data: DataOwned<Elem = A>,

Initialize the object according to the Glorot Initialization scheme.
Source§

fn glorot_uniform<Sh>( shape: Sh, inputs: usize, outputs: usize, ) -> Result<Self, Error>
where A: Float + FromPrimitive + SampleUniform, Sh: ShapeBuilder<Dim = D>, <A as SampleUniform>::Sampler: Clone, Self::Data: DataOwned<Elem = A>,

Initialize the object according to the Glorot Initialization scheme.
Source§

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

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: ShapeBuilder<Dim = D>>( shape: Sh, mean: A, std: A, ) -> Result<Self, NormalError>
where A: Float, StandardNormal: Distribution<A>, Self::Data: DataOwned<Elem = A>,

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

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

Source§

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

Generate a random array using the StandardNormal distribution
Source§

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

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

fn truncnorm<Sh: ShapeBuilder<Dim = D>>( shape: Sh, mean: A, std: A, ) -> Result<Self, NormalError>
where A: Float, StandardNormal: Distribution<A>, Self::Data: DataOwned<Elem = A>,

Initialize the object using the TruncatedNormal distribution
Source§

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

A uniform generator with values between u(-dk, dk)
Source§

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

Source§

fn uniform_along<Sh>(shape: Sh, axis: usize) -> Result<Self, Error>
where A: Copy + Float + SampleUniform, Sh: ShapeBuilder<Dim = D>, <A as SampleUniform>::Sampler: Clone, Self::Data: DataOwned<Elem = A>,

Generate a random array with values between u(-a, a) where a is the reciprocal of the value at the given axis
Source§

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

A uniform generator with values between u(-dk, dk)
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IsType for T
where T: 'static,

Source§

fn of<T>() -> bool
where T: 'static,

Source§

fn is<T>(&self) -> bool
where T: 'static,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more