pub struct LayerBase<F, S, D = Ix2>{ /* private fields */ }Expand description
The LayerBase struct is a base representation of a neural network layer, essentially
binding an activation function, F, to a set of parameters, ParamsBase<S, D>.
Implementations§
Source§impl<S, D> LayerBase<Linear, S, D>
impl<S, D> LayerBase<Linear, S, D>
Sourcepub const fn linear(params: ParamsBase<S, D>) -> Self
pub const fn linear(params: ParamsBase<S, D>) -> Self
Source§impl<S, D> LayerBase<Sigmoid, S, D>
impl<S, D> LayerBase<Sigmoid, S, D>
Sourcepub const fn sigmoid(params: ParamsBase<S, D>) -> Self
pub const fn sigmoid(params: ParamsBase<S, D>) -> Self
Source§impl<F, S, A, D> LayerBase<F, S, D>
impl<F, S, A, D> LayerBase<F, S, D>
Sourcepub const fn new(rho: F, params: ParamsBase<S, D>) -> Self
pub const fn new(rho: F, params: ParamsBase<S, D>) -> Self
create a new LayerBase from the given activation function and parameters.
Sourcepub fn from_params(params: ParamsBase<S, D>) -> Selfwhere
F: Default,
pub fn from_params(params: ParamsBase<S, D>) -> Selfwhere
F: Default,
create a new LayerBase from the given parameters assuming the logical default for
the activation of type F.
Sourcepub fn from_rho<Sh>(rho: F, shape: Sh) -> Self
pub fn from_rho<Sh>(rho: F, shape: Sh) -> Self
create a new LayerBase from the given activation function and shape.
Sourcepub const fn params(&self) -> &ParamsBase<S, D>
pub const fn params(&self) -> &ParamsBase<S, D>
returns an immutable reference to the layer’s parameters
Sourcepub const fn params_mut(&mut self) -> &mut ParamsBase<S, D>
pub const fn params_mut(&mut self) -> &mut ParamsBase<S, D>
returns a mutable reference to the layer’s parameters
Sourcepub const fn rho(&self) -> &F
pub const fn rho(&self) -> &F
returns an immutable reference to the activation function of the layer
Sourcepub const fn rho_mut(&mut self) -> &mut F
pub const fn rho_mut(&mut self) -> &mut F
returns a mutable reference to the activation function of the layer
Sourcepub fn with_params<S2, D2>(
self,
params: ParamsBase<S2, D2>,
) -> LayerBase<F, S2, D2>
pub fn with_params<S2, D2>( self, params: ParamsBase<S2, D2>, ) -> LayerBase<F, S2, D2>
consumes the current instance and returns another with the given parameters.
Sourcepub fn with_rho<G>(self, rho: G) -> LayerBase<G, S, D>
pub fn with_rho<G>(self, rho: G) -> LayerBase<G, S, D>
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.
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>>§
Sourcepub fn bias(&self) -> &ArrayBase<S, <D as Dimension>::Smaller>
pub fn bias(&self) -> &ArrayBase<S, <D as Dimension>::Smaller>
returns an immutable reference to the bias
Sourcepub fn bias_mut(&mut self) -> &mut ArrayBase<S, <D as Dimension>::Smaller>
pub fn bias_mut(&mut self) -> &mut ArrayBase<S, <D as Dimension>::Smaller>
returns a mutable reference to the bias
Sourcepub fn weights_mut(&mut self) -> &mut ArrayBase<S, D>
pub fn weights_mut(&mut self) -> &mut ArrayBase<S, D>
returns a mutable reference to the weights
Sourcepub fn assign_bias(
&mut self,
bias: &ArrayBase<S, <D as Dimension>::Smaller>,
) -> &mut ParamsBase<S, D>
pub fn assign_bias( &mut self, bias: &ArrayBase<S, <D as Dimension>::Smaller>, ) -> &mut ParamsBase<S, D>
assign the bias
Sourcepub fn assign_weights(
&mut self,
weights: &ArrayBase<S, D>,
) -> &mut ParamsBase<S, D>
pub fn assign_weights( &mut self, weights: &ArrayBase<S, D>, ) -> &mut ParamsBase<S, D>
assign the weights
Sourcepub fn replace_bias(
&mut self,
bias: ArrayBase<S, <D as Dimension>::Smaller>,
) -> ArrayBase<S, <D as Dimension>::Smaller>
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
Sourcepub fn replace_weights(&mut self, weights: ArrayBase<S, D>) -> ArrayBase<S, D>
pub fn replace_weights(&mut self, weights: ArrayBase<S, D>) -> ArrayBase<S, D>
replace the weights and return the previous state; uses replace
Sourcepub fn set_bias(
&mut self,
bias: ArrayBase<S, <D as Dimension>::Smaller>,
) -> &mut ParamsBase<S, D>
pub fn set_bias( &mut self, bias: ArrayBase<S, <D as Dimension>::Smaller>, ) -> &mut ParamsBase<S, D>
set the bias
Sourcepub fn set_weights(&mut self, weights: ArrayBase<S, D>) -> &mut ParamsBase<S, D>
pub fn set_weights(&mut self, weights: ArrayBase<S, D>) -> &mut ParamsBase<S, D>
set the weights
Sourcepub fn backward<X, Y, Z>(
&mut self,
input: &X,
grad: &Y,
lr: A,
) -> Result<Z, Error>
pub fn backward<X, Y, Z>( &mut self, input: &X, grad: &Y, lr: A, ) -> Result<Z, Error>
perform a single backpropagation step
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
returns true if both the weights and bias are empty; uses is_empty
Sourcepub fn is_weights_empty(&self) -> bool
pub fn is_weights_empty(&self) -> bool
returns true if the weights are empty
Sourcepub fn is_bias_empty(&self) -> bool
pub fn is_bias_empty(&self) -> bool
returns true if the bias is empty
Sourcepub fn count_weight(&self) -> usize
pub fn count_weight(&self) -> usize
the total number of elements within the weight tensor
Sourcepub fn count_bias(&self) -> usize
pub fn count_bias(&self) -> usize
the total number of elements within the bias tensor
Sourcepub fn shape(&self) -> &[usize]
pub fn shape(&self) -> &[usize]
returns the shape of the parameters; uses the shape of the weight tensor
Sourcepub fn shape_bias(&self) -> &[usize]
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
Sourcepub fn to_owned(&self) -> ParamsBase<OwnedRepr<A>, D>
pub fn to_owned(&self) -> ParamsBase<OwnedRepr<A>, D>
returns an owned instance of the parameters
Sourcepub fn to_shape<Sh>(
&self,
shape: Sh,
) -> Result<ParamsBase<CowRepr<'_, A>, <Sh as ShapeBuilder>::Dim>, Error>
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
returns a new ParamsBase instance with the same paramaters, but using a shared
representation of the data;
Sourcepub fn view(&self) -> ParamsBase<ViewRepr<&A>, D>where
S: Data,
pub fn view(&self) -> ParamsBase<ViewRepr<&A>, D>where
S: Data,
returns a “view” of the parameters; see view for more information
Sourcepub fn view_mut(&mut self) -> ParamsBase<ViewRepr<&mut A>, D>where
S: DataMut,
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
Sourcepub fn iter(&self) -> Iter<'_, A, D>where
D: RemoveAxis,
S: Data,
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
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, A, D>where
D: RemoveAxis,
S: DataMut,
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
Sourcepub fn iter_bias(&self) -> Iter<'_, A, <D as Dimension>::Smaller>where
S: Data,
pub fn iter_bias(&self) -> Iter<'_, A, <D as Dimension>::Smaller>where
S: Data,
returns an iterator over the bias
Sourcepub fn iter_bias_mut(&mut self) -> IterMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
pub fn iter_bias_mut(&mut self) -> IterMut<'_, A, <D as Dimension>::Smaller>where
S: DataMut,
returns a mutable iterator over the bias
Sourcepub fn iter_weights(&self) -> Iter<'_, A, D>where
S: Data,
pub fn iter_weights(&self) -> Iter<'_, A, D>where
S: Data,
returns an iterator over the weights
Sourcepub fn iter_weights_mut(&mut self) -> IterMut<'_, A, D>where
S: DataMut,
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
Sourcepub fn apply_gradient<Delta, Z>(
&mut self,
grad: &Delta,
lr: A,
) -> Result<Z, Error>
pub fn apply_gradient<Delta, Z>( &mut self, grad: &Delta, lr: A, ) -> Result<Z, Error>
a convenience method used to apply a gradient to the parameters using the given learning rate.
pub fn apply_gradient_with_decay<Grad, Z>( &mut self, grad: &Grad, lr: A, decay: A, ) -> Result<Z, Error>
pub fn apply_gradient_with_momentum<Grad, V, Z>( &mut self, grad: &Grad, lr: A, momentum: A, velocity: &mut V, ) -> Result<Z, Error>
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>
Trait Implementations§
Source§impl<U, F, S, D> ActivatorGradient<U> for LayerBase<F, S, D>
impl<U, F, S, D> ActivatorGradient<U> for LayerBase<F, S, D>
type Input = <F as ActivatorGradient<U>>::Input
type Delta = <F as ActivatorGradient<U>>::Delta
Source§fn activate_gradient(&self, inputs: F::Input) -> F::Delta
fn activate_gradient(&self, inputs: F::Input) -> F::Delta
Source§impl<A, X, Y, F, S, D> Forward<X> for LayerBase<F, S, D>
impl<A, X, Y, F, S, D> Forward<X> for LayerBase<F, S, D>
type Output = Y
Source§fn forward_then<F>(&self, input: &Rhs, then: F) -> Result<Self::Output, Error>
fn forward_then<F>(&self, input: &Rhs, then: F) -> Result<Self::Output, Error>
Source§impl<A, F, S, D> Layer<S, D> for LayerBase<F, S, D>
impl<A, F, S, D> Layer<S, D> for LayerBase<F, S, D>
Source§type Rho = F
type Rho = F
ActivatorGradientfn rho(&self) -> &Self::Rho
Source§fn params(&self) -> &ParamsBase<S, D>
fn params(&self) -> &ParamsBase<S, D>
Source§fn params_mut(&mut self) -> &mut ParamsBase<S, D>
fn params_mut(&mut self) -> &mut ParamsBase<S, D>
Auto Trait Implementations§
impl<F, S, D> Freeze for LayerBase<F, S, D>
impl<F, S, D> RefUnwindSafe for LayerBase<F, S, D>where
F: RefUnwindSafe,
S: RefUnwindSafe,
<D as Dimension>::Smaller: RefUnwindSafe,
D: RefUnwindSafe,
<S as RawData>::Elem: RefUnwindSafe,
impl<F, S, D> Send for LayerBase<F, S, D>
impl<F, S, D> Sync for LayerBase<F, S, D>
impl<F, S, D> Unpin for LayerBase<F, S, D>
impl<F, S, D> UnwindSafe for LayerBase<F, S, D>where
F: UnwindSafe,
S: UnwindSafe,
<D as Dimension>::Smaller: UnwindSafe,
D: UnwindSafe,
<S as RawData>::Elem: RefUnwindSafe,
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> CallInPlace<T> for Twhere
T: CallInto<T>,
impl<T> CallInPlace<T> for Twhere
T: CallInto<T>,
Source§fn call_inplace<F>(&mut self, f: F) -> <T as CallInto<T>>::Output
fn call_inplace<F>(&mut self, f: F) -> <T as CallInto<T>>::Output
call_on_mut method allows an object to be passed onto a function that takes a mutable reference
to the object. This is useful for cases where you want to perform an operation on
an object and mutate it in the process.Source§impl<T> CallInto<T> for T
impl<T> CallInto<T> for T
Source§impl<T> CallOn<T> for Twhere
T: CallInto<T>,
impl<T> CallOn<T> for Twhere
T: CallInto<T>,
Source§fn call_on<F>(&self, f: F) -> <T as CallInto<T>>::Output
fn call_on<F>(&self, f: F) -> <T as CallInto<T>>::Output
call_on method allows an object to be passed onto a function that takes a reference
to the object. This is useful for cases where you want to perform an operation on
an object without needing to extract it from a container or context.