pub struct LinearLayer<T: Float + Debug + ScalarOperand + Send + Sync + 'static> { /* private fields */ }Expand description
Linear layer implementation
Implementations§
Source§impl<T: Float + Debug + ScalarOperand + Send + Sync + 'static> LinearLayer<T>
impl<T: Float + Debug + ScalarOperand + Send + Sync + 'static> LinearLayer<T>
Sourcepub fn new(input_dim: usize, output_dim: usize) -> Result<Self>
pub fn new(input_dim: usize, output_dim: usize) -> Result<Self>
Create new linear layer with Xavier/Glorot uniform weights,
limit sqrt(6 / (fan_in + fan_out)).
Sourcepub fn new_he_init(input_dim: usize, output_dim: usize) -> Result<Self>
pub fn new_he_init(input_dim: usize, output_dim: usize) -> Result<Self>
Create with He initialization (better for ReLU)
Sourcepub fn forward(&self, input: &Array2<T>) -> Result<Array2<T>>
pub fn forward(&self, input: &Array2<T>) -> Result<Array2<T>>
Forward pass through linear layer: input @ weight + bias.
Sourcepub fn backward(
&mut self,
input: &Array2<T>,
grad_output: &Array2<T>,
learning_rate: T,
) -> Result<Array2<T>>
pub fn backward( &mut self, input: &Array2<T>, grad_output: &Array2<T>, learning_rate: T, ) -> Result<Array2<T>>
Backward pass. Returns dL/d(input) and applies an SGD step.
Sourcepub fn parameter_count(&self) -> usize
pub fn parameter_count(&self) -> usize
Get parameter count
Sourcepub fn get_weights(&self) -> &Array2<T>
pub fn get_weights(&self) -> &Array2<T>
Get weight matrix reference
Auto Trait Implementations§
impl<T> Freeze for LinearLayer<T>
impl<T> RefUnwindSafe for LinearLayer<T>
impl<T> Send for LinearLayer<T>
impl<T> Sync for LinearLayer<T>
impl<T> Unpin for LinearLayer<T>
impl<T> UnsafeUnpin for LinearLayer<T>
impl<T> UnwindSafe for LinearLayer<T>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.