Struct LayerBase

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

Implementations§

Source§

impl<S, D> LayerBase<Linear, S, D>
where D: Dimension, S: RawData<Elem = f32>,

Source

pub fn linear(params: ParamsBase<S, D>) -> Self

Source§

impl<S, D> LayerBase<Sigmoid, S, D>
where D: Dimension, S: RawData<Elem = f32>,

Source

pub fn sigmoid(params: ParamsBase<S, D>) -> Self

Source§

impl<S, D> LayerBase<Tanh, S, D>
where D: Dimension, S: RawData<Elem = f32>,

Source

pub fn tanh(params: ParamsBase<S, D>) -> Self

Source§

impl<S, D> LayerBase<ReLU, S, D>
where D: Dimension, S: RawData<Elem = f32>,

Source

pub fn relu(params: ParamsBase<S, D>) -> Self

Source§

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

Source

pub fn new(rho: F, params: ParamsBase<S, D>) -> Self

Source

pub fn params(&self) -> &ParamsBase<S, D>

returns an immutable reference to the layer’s parameters

Source

pub fn params_mut(&mut self) -> &mut ParamsBase<S, D>

returns a mutable reference to the layer’s parameters

Source

pub fn rho(&self) -> &F

returns an immutable reference to the activation function of the layer

Source

pub fn rho_mut(&mut self) -> &mut F

returns a mutable reference to the activation function of the layer

Source

pub fn with_rho<G>(self, rho: G) -> LayerBase<G, S, D>
where G: Activator<S::Elem>, F: Activator<S::Elem>, S: RawData<Elem = A>,

consumes the current instance and returns another with the given activation function. This is useful during the creation of the model, when the activation function is not known yet.

Source

pub fn forward<X, Y>(&self, input: &X) -> Result<Y>
where F: Activator<<ParamsBase<S, D> as Forward<X>>::Output, Output = Y>, ParamsBase<S, D>: Forward<X, Output = Y>, X: Clone, Y: Clone,

Methods from Deref<Target = ParamsBase<S, D>>§

Source

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

returns an immutable reference to the bias

Source

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

returns a mutable reference to the bias

Source

pub 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 assign_bias( &mut self, bias: &ArrayBase<S, <D as Dimension>::Smaller>, ) -> &mut ParamsBase<S, D>
where A: Clone, S: DataMut,

assign the bias

Source

pub fn assign_weights( &mut self, weights: &ArrayBase<S, D>, ) -> &mut ParamsBase<S, D>
where A: Clone, S: DataMut,

assign the weights

Source

pub fn replace_bias( &mut self, bias: ArrayBase<S, <D as Dimension>::Smaller>, ) -> ArrayBase<S, <D as Dimension>::Smaller>

replace the bias and return the previous state; uses replace

Source

pub fn replace_weights(&mut self, weights: ArrayBase<S, D>) -> ArrayBase<S, D>

replace the weights and return the previous state; uses replace

Source

pub fn set_bias( &mut self, bias: ArrayBase<S, <D as Dimension>::Smaller>, ) -> &mut ParamsBase<S, D>

set the bias

Source

pub fn set_weights(&mut self, weights: ArrayBase<S, D>) -> &mut ParamsBase<S, D>

set the weights

Source

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

perform a single backpropagation step

Source

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

forward propagation

Source

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

returns the dimensions of the weights

Source

pub fn is_empty(&self) -> bool

returns true if both the weights and bias are empty; uses is_empty

Source

pub fn is_weights_empty(&self) -> bool

returns true if the weights are empty

Source

pub fn is_bias_empty(&self) -> bool

returns true if the bias is empty

Source

pub fn count_weight(&self) -> usize

the total number of elements within the weight tensor

Source

pub fn count_bias(&self) -> usize

the total number of elements within the bias 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 size(&self) -> usize

returns the total number of parameters within the layer

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 as ShapeBuilder>::Dim>, Error>

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 to_shared(&self) -> ParamsBase<OwnedArcRepr<A>, D>
where A: Clone, S: Data,

returns a new ParamsBase instance with the same paramaters, but using a shared representation of the data;

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

pub fn ncols(&self) -> usize

returns the number of columns in the weights matrix

Source

pub fn nrows(&self) -> usize

returns the number of rows in the weights matrix

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) -> IterMut<'_, A, D>
where D: RemoveAxis, S: DataMut,

returns a mutable iterator of the parameters, IterMut, which essentially zips together a mutable axis iterator over the columns of the weights against a mutable iterator over the elements of the bias

Source

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

returns an iterator over the bias

Source

pub fn iter_bias_mut(&mut self) -> IterMut<'_, A, <D as Dimension>::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 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<Delta, Z>( &mut self, grad: &Delta, lr: A, ) -> Result<Z, Error>
where S: DataMut, ParamsBase<S, D>: ApplyGradient<Delta, A, Output = Z>,

a convenience method used to apply a gradient to the parameters using the given learning rate.

Source

pub fn apply_gradient_with_decay<Grad, Z>( &mut self, grad: &Grad, lr: A, decay: A, ) -> Result<Z, Error>
where S: DataMut, ParamsBase<S, D>: 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, Error>
where S: DataMut, ParamsBase<S, D>: 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, Error>
where S: DataMut, ParamsBase<S, D>: ApplyGradientExt<Grad, A, Output = Z, Velocity = V>,

Trait Implementations§

Source§

impl<U, V, F, S, D> Activator<U> for LayerBase<F, S, D>
where F: Activator<U, Output = V>, D: Dimension, S: RawData,

Source§

type Output = V

Source§

fn activate(&self, x: U) -> Self::Output

Applies the activation function to the input tensor.
Source§

impl<U, F, S, D> ActivatorGradient<U> for LayerBase<F, S, D>
where F: ActivatorGradient<U>, D: Dimension, S: RawData,

Source§

type Input = <F as ActivatorGradient<U>>::Input

Source§

type Delta = <F as ActivatorGradient<U>>::Delta

Source§

fn activate_gradient(&self, inputs: F::Input) -> F::Delta

compute the gradient of some input
Source§

impl<F, S, D> Deref for LayerBase<F, S, D>
where D: Dimension, S: RawData,

Source§

type Target = ParamsBase<S, D>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<F, S, D> DerefMut for LayerBase<F, S, D>
where D: Dimension, S: RawData,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<A, F, S, D> Layer<S, D> for LayerBase<F, S, D>
where F: ActivatorGradient<A>, D: Dimension, S: RawData<Elem = A>,

Source§

type Scalar = A

Source§

fn params(&self) -> &ParamsBase<S, D>

returns an immutable reference to the parameters of the layer
Source§

fn params_mut(&mut self) -> &mut ParamsBase<S, D>

returns a mutable reference to the parameters of the layer
Source§

fn set_params(&mut self, params: ParamsBase<S, D>)

update the layer parameters
Source§

fn backward<X, Y, Z, Delta>( &mut self, input: X, error: Y, gamma: Self::Scalar, ) -> Result<Z>
where S: Data, Self: ActivatorGradient<X, Input = Y, Delta = Delta>, Self::Scalar: Clone, ParamsBase<S, D>: Backward<X, Delta, Elem = Self::Scalar, Output = Z>,

backward propagate error through the layer
Source§

fn forward<X, Y>(&self, input: &X) -> Result<Y>
where Y: NdTensor<S::Elem, D, Repr = S>, ParamsBase<S, D>: Forward<X, Output = Y>, Self: Activator<Y, Output = Y>,

complete a forward pass through the layer

Auto Trait Implementations§

§

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

§

impl<F, S, D> RefUnwindSafe for LayerBase<F, S, D>

§

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

§

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

§

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

§

impl<F, S, D> UnwindSafe for LayerBase<F, 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

type Item = S

Source§

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

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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