pub struct DenseLayer64 {
pub weights: Vec<f64>,
pub biases: Vec<f64>,
pub in_features: usize,
pub out_features: usize,
pub activation: ExtActivation,
pub last_pre_act: Vec<f64>,
pub last_output: Vec<f64>,
pub last_input: Vec<f64>,
}Expand description
A fully-connected layer with f64 weights supporting forward pass and gradient computation for backpropagation.
Fields§
§weights: Vec<f64>Weight matrix in row-major layout: weights[out * in_features + in].
biases: Vec<f64>Bias vector of length out_features.
in_features: usizeNumber of input features.
out_features: usizeNumber of output features.
activation: ExtActivationActivation function.
last_pre_act: Vec<f64>Pre-activation outputs from the last forward pass (z = W*x + b).
last_output: Vec<f64>Post-activation outputs from the last forward pass.
last_input: Vec<f64>Last input fed to this layer.
Implementations§
Source§impl DenseLayer64
impl DenseLayer64
Sourcepub fn new(
in_features: usize,
out_features: usize,
activation: ExtActivation,
) -> Self
pub fn new( in_features: usize, out_features: usize, activation: ExtActivation, ) -> Self
Create a new layer with zero-initialised weights and biases.
Sourcepub fn forward(&mut self, input: &[f64]) -> Vec<f64>
pub fn forward(&mut self, input: &[f64]) -> Vec<f64>
Forward pass: computes activation(W * input + b).
Caches pre_act, output, and input for backprop.
Sourcepub fn backward(&self, delta_out: &[f64]) -> (Vec<f64>, Vec<f64>, Vec<f64>)
pub fn backward(&self, delta_out: &[f64]) -> (Vec<f64>, Vec<f64>, Vec<f64>)
Backward pass: computes gradients w.r.t. weights, biases, and input.
delta_out is the gradient of the loss w.r.t. this layer’s output
(same shape as last_output).
Returns (grad_weights, grad_biases, delta_in) where delta_in is the
gradient passed to the previous layer.
Sourcepub fn apply_sgd(&mut self, grad_weights: &[f64], grad_biases: &[f64], lr: f64)
pub fn apply_sgd(&mut self, grad_weights: &[f64], grad_biases: &[f64], lr: f64)
Apply gradient updates using a simple SGD step.
Sourcepub fn num_params(&self) -> usize
pub fn num_params(&self) -> usize
Total number of parameters.
Trait Implementations§
Source§impl Clone for DenseLayer64
impl Clone for DenseLayer64
Source§fn clone(&self) -> DenseLayer64
fn clone(&self) -> DenseLayer64
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DenseLayer64
impl RefUnwindSafe for DenseLayer64
impl Send for DenseLayer64
impl Sync for DenseLayer64
impl Unpin for DenseLayer64
impl UnsafeUnpin for DenseLayer64
impl UnwindSafe for DenseLayer64
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more