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
impl DenseLayer
sourcepub fn new(
f_in: usize,
f_out: usize,
initializer: Initializer,
activation: Activation
) -> Self
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);
Trait Implementations§
source§impl Clone for DenseLayer
impl Clone for DenseLayer
source§fn clone(&self) -> DenseLayer
fn clone(&self) -> DenseLayer
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for DenseLayer
impl Debug for DenseLayer
source§impl Layer for DenseLayer
impl Layer for DenseLayer
source§fn forward(&mut self, input: &Tensor) -> Tensor
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
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);
fn weights(&self) -> &Tensor
fn biases(&self) -> &Tensor
fn update_parameters(&mut self, optimizer: &mut dyn Optimizer)
fn regularization_loss(&self, reg: &dyn Regularization) -> f64
fn apply_regularization(&mut self, reg: &dyn Regularization)
fn eval(&mut self)
fn train(&mut self)
Auto Trait Implementations§
impl Freeze for DenseLayer
impl RefUnwindSafe for DenseLayer
impl Send for DenseLayer
impl Sync for DenseLayer
impl Unpin for DenseLayer
impl UnwindSafe for DenseLayer
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
Mutably borrows from an owned value. Read more