LayerBase

Struct LayerBase 

Source
pub struct LayerBase<F, P> {
    pub rho: F,
    pub params: P,
}
Expand description

The LayerBase implementation works to provide a generic interface for layers within a neural network by associating an activation function F with a set of parameters P.

Fields§

§rho: F

the activation function of the layer

§params: P

the parameters of the layer; often weights and biases

Implementations§

Source§

impl<F, P, A> LayerBase<F, P>
where P: RawParams<Elem = A>,

Source

pub const fn new(rho: F, params: P) -> Self

create a new LayerBase from the given activation function and parameters.

Source

pub fn from_params(params: P) -> Self
where F: Default,

create a new LayerBase from the given parameters assuming the logical default for the activation of type F.

Source

pub fn from_rho<Sh>(rho: F) -> Self
where P: Default,

create a new LayerBase from the given activation function and shape.

Source

pub const fn params(&self) -> &P

returns an immutable reference to the layer’s parameters

Source

pub const fn params_mut(&mut self) -> &mut P

returns a mutable reference to the layer’s parameters

Source

pub const fn rho(&self) -> &F

returns an immutable reference to the activation function of the layer

Source

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

returns a mutable reference to the activation function of the layer

Source

pub fn with_params<Y>(self, params: Y) -> LayerBase<F, Y>
where F: Activator<Y>,

consumes the current instance and returns another with the given parameters.

Source

pub fn with_rho<G>(self, rho: G) -> LayerBase<G, P>
where G: Activator<P>,

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 activate<X, Y>(&self, input: X) -> Y
where F: Activator<X, Output = Y>,

apply the configured activation function onto some input, producing some output

Source

pub fn forward<U, V>(&self, input: &U) -> V
where Self: Forward<U, Output = V>,

given some input, complete a single forward pass through the layer

Source§

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

Source

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

create a new instance from the given activation function and shape.

Source

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

Source

pub fn raw_dim(&self) -> D

Source

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

Source§

impl<F, S, D, E, A> LayerBase<F, ParamsBase<S, D, A>>
where F: Activator<A, Output = A>, D: Dimension<Smaller = E>, E: Dimension<Larger = D>, S: RawData<Elem = A>,

Source

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

create a new layer from the given activation function and shape.

Source

pub const fn bias(&self) -> &ArrayBase<S, E, A>

Source

pub const fn bias_mut(&mut self) -> &mut ArrayBase<S, E, A>

Source

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

Source

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

Source

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

Source

pub fn raw_dim(&self) -> D

Source

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

Source§

impl<A, P> LayerBase<Linear, P>
where P: RawParams<Elem = A>,

Source

pub const fn linear(params: P) -> Self

initialize a layer using the Linear activation function and the given params.

Source§

impl<A, P> LayerBase<Sigmoid, P>
where P: RawParams<Elem = A>,

Source

pub const fn sigmoid(params: P) -> Self

initialize a layer using the Sigmoid activation function and the given params.

Source§

impl<A, P> LayerBase<HyperbolicTangent, P>
where P: RawParams<Elem = A>,

Source

pub const fn tanh(params: P) -> Self

initialize a new layer using a [TanhActivator] activation function and the given parameters.

Source§

impl<A, P> LayerBase<ReLU, P>
where P: RawParams<Elem = A>,

Source

pub const fn relu(params: P) -> Self

initialize a layer using the Sigmoid activation function and the given params.

Trait Implementations§

Source§

impl<F, P, A, X, Y> Activator<X> for LayerBase<F, P>
where F: Activator<X, Output = Y>, P: RawParams<Elem = A>,

Source§

type Output = <F as Activator<X>>::Output

Source§

fn activate(&self, input: X) -> Self::Output

Applies the activation function to the input tensor.
Source§

impl<F: Clone, P: Clone> Clone for LayerBase<F, P>

Source§

fn clone(&self) -> LayerBase<F, P>

Returns a duplicate 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<F: Debug, P: Debug> Debug for LayerBase<F, P>

Source§

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

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

impl<F: Default, P: Default> Default for LayerBase<F, P>

Source§

fn default() -> LayerBase<F, P>

Returns the “default value” for a type. Read more
Source§

impl<F, P, A, X, Y, Z> Forward<X> for LayerBase<F, P>
where F: Activator<Y, Output = Z>, P: RawParams<Elem = A> + Forward<X, Output = Y>,

Source§

type Output = <F as Activator<Y>>::Output

Source§

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

a single forward step
Source§

fn forward_then<F>(&self, input: &Rhs, then: F) -> Self::Output
where F: FnOnce(Self::Output) -> Self::Output,

this method enables the forward pass to be generically activated using some closure. This is useful for isolating the logic of the forward pass from that of the activation function and is often used by layers and models.
Source§

impl<F: Hash, P: Hash> Hash for LayerBase<F, P>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<F: Ord, P: Ord> Ord for LayerBase<F, P>

Source§

fn cmp(&self, other: &LayerBase<F, P>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<F: PartialEq, P: PartialEq> PartialEq for LayerBase<F, P>

Source§

fn eq(&self, other: &LayerBase<F, P>) -> 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<F: PartialOrd, P: PartialOrd> PartialOrd for LayerBase<F, P>

Source§

fn partial_cmp(&self, other: &LayerBase<F, P>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<F, P, A> RawLayer<F, A> for LayerBase<F, P>
where F: Activator<A>, P: RawParams<Elem = A>,

Source§

type Params<_T> = P

Source§

fn rho(&self) -> &F

the activation function of the layer
Source§

fn params(&self) -> &P

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

fn forward<X, Y, Z>(&self, input: &X) -> Z
where F: Activator<Y, Output = Z>, Self::Params<A>: Forward<X, Output = Y>,

complete a forward pass through the layer
Source§

impl<F, P, A> RawLayerMut<F, A> for LayerBase<F, P>
where F: Activator<A>, P: RawParams<Elem = A>,

Source§

fn params_mut(&mut self) -> &mut P

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

fn backward<X, Y, Z, Dt>(&mut self, input: X, error: Y, gamma: A)
where A: Clone, F: ActivatorGradient<Y, Rel = F, Delta = Dt>, Self::Params<A>: Backward<X, Dt, Elem = A>,

backward propagate error through the layer
Source§

fn set_params(&mut self, params: Self::Params<A>)

update the layer parameters
Source§

fn replace_params(&mut self, params: Self::Params<A>) -> Self::Params<A>

replace the params of the layer, returning the previous value
Source§

fn swap_params(&mut self, other: &mut Self::Params<A>)

swap the params of the layer with another
Source§

impl<F: Eq, P: Eq> Eq for LayerBase<F, P>

Source§

impl<F, P> StructuralPartialEq for LayerBase<F, P>

Auto Trait Implementations§

§

impl<F, P> Freeze for LayerBase<F, P>
where F: Freeze, P: Freeze,

§

impl<F, P> RefUnwindSafe for LayerBase<F, P>

§

impl<F, P> Send for LayerBase<F, P>
where F: Send, P: Send,

§

impl<F, P> Sync for LayerBase<F, P>
where F: Sync, P: Sync,

§

impl<F, P> Unpin for LayerBase<F, P>
where F: Unpin, P: Unpin,

§

impl<F, P> UnwindSafe for LayerBase<F, P>
where F: UnwindSafe, P: UnwindSafe,

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<M, U, V> Predict<U> for M
where M: Forward<U, Output = V>,

Source§

type Output = V

Source§

fn __private__(&self) -> Seal

Source§

fn predict(&self, input: &U) -> <M as Predict<U>>::Output

Source§

impl<M, U, A, D> PredictWithConfidence<U> for M
where A: Float + FromPrimitive + ScalarOperand, D: Dimension, M: Predict<U, Output = ArrayBase<OwnedRepr<A>, D>>,

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.