pub struct DenseLayer {
pub weights: Vec<f32>,
pub bias: Vec<f32>,
pub input_size: usize,
pub output_size: usize,
}Expand description
A simple dense layer for demonstration purposes
Fields§
§weights: Vec<f32>Weight matrix (flattened: input_size * output_size)
bias: Vec<f32>Bias vector
input_size: usizeInput size
output_size: usizeOutput size
Implementations§
Source§impl DenseLayer
impl DenseLayer
Sourcepub fn new(input_size: usize, output_size: usize, seed: u64) -> Self
pub fn new(input_size: usize, output_size: usize, seed: u64) -> Self
Creates a new dense layer with Xavier initialization
Sourcepub fn backward(
&self,
input: &[f32],
grad_output: &[f32],
) -> (Vec<f32>, Vec<f32>, Vec<f32>)
pub fn backward( &self, input: &[f32], grad_output: &[f32], ) -> (Vec<f32>, Vec<f32>, Vec<f32>)
Backward pass computing gradients w.r.t. weights, bias, and input
Sourcepub fn num_params(&self) -> usize
pub fn num_params(&self) -> usize
Returns the total number of parameters
Sourcepub fn get_params(&self) -> Vec<f32>
pub fn get_params(&self) -> Vec<f32>
Gets all parameters as a flat vector
Sourcepub fn set_params(&mut self, params: &[f32])
pub fn set_params(&mut self, params: &[f32])
Sets parameters from a flat vector
Trait Implementations§
Source§impl Clone for DenseLayer
impl Clone for DenseLayer
Source§fn clone(&self) -> DenseLayer
fn clone(&self) -> DenseLayer
Returns a duplicate 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 moreAuto Trait Implementations§
impl Freeze for DenseLayer
impl RefUnwindSafe for DenseLayer
impl Send for DenseLayer
impl Sync for DenseLayer
impl Unpin for DenseLayer
impl UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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