Struct engram::nn::DenseLayer

source ·
pub struct DenseLayer {
    pub weights: Tensor,
    pub biases: Tensor,
    pub d_weights: Option<Tensor>,
    pub d_biases: Option<Tensor>,
    pub input: Option<Tensor>,
    pub output: Option<Tensor>,
    pub activation: Activation,
    pub eval: bool,
}

Fields§

§weights: Tensor§biases: Tensor§d_weights: Option<Tensor>§d_biases: Option<Tensor>§input: Option<Tensor>§output: Option<Tensor>§activation: Activation§eval: bool

Implementations§

source§

impl DenseLayer

source

pub fn new( f_in: usize, f_out: usize, initializer: Initializer, activation: Activation ) -> Self

Create a new layer with the given number of input and output features.

§Examples
let layer = DenseLayer::new(3, 2, Initializer::Xavier, Activation::ReLU);
source

pub fn default(f_in: usize, f_out: usize) -> Self

Create a new layer with the given number of input and output features, using Xavier initialization and ReLU activation as defaults.

§Examples
let layer = DenseLayer::default(4, 7);

Trait Implementations§

source§

impl Clone for DenseLayer

source§

fn clone(&self) -> DenseLayer

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 Debug for DenseLayer

source§

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

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

impl Layer for DenseLayer

source§

fn forward(&mut self, input: &Tensor) -> Tensor

Forward pass through the layer, returning the output.

§Examples
let mut layer = DenseLayer::default(3, 2);
let input = tensor![1.0, 2.0, 3.0];
let output = layer.forward(&input);
source§

fn backward(&mut self, target: &Tensor, loss_fn: &Loss) -> f64

Backpropagate through the layer, returning the average loss.

§Examples
let mut layer = DenseLayer::default(3, 2);
let input = tensor![1.0, 2.0, 3.0];
let output = layer.forward(&input);
let target = tensor![1.0, 0.0];
let loss = layer.backward(&target, &Loss::MSE);
source§

fn weights(&self) -> &Tensor

source§

fn biases(&self) -> &Tensor

source§

fn update_parameters(&mut self, optimizer: &mut dyn Optimizer)

source§

fn regularization_loss(&self, reg: &dyn Regularization) -> f64

source§

fn apply_regularization(&mut self, reg: &dyn Regularization)

source§

fn eval(&mut self)

source§

fn train(&mut self)

Auto Trait Implementations§

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

§

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>,

§

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>,

§

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.
§

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

§

fn vzip(self) -> V