pub struct LinearLayer<const I: usize, const O: usize> { /* private fields */ }Expand description
A linear layer in a neural network, with sigmoid activation.
Implementations§
Source§impl<const I: usize, const O: usize> LinearLayer<I, O>
impl<const I: usize, const O: usize> LinearLayer<I, O>
Sourcepub fn new(learning_rate: f32) -> Self
pub fn new(learning_rate: f32) -> Self
Creates a new linear layer with random weights and biases.
Sourcepub fn feedforward(&self, input: &RowVector<I>) -> (RowVector<O>, RowVector<O>)
pub fn feedforward(&self, input: &RowVector<I>) -> (RowVector<O>, RowVector<O>)
Performs a forward pass through the layer, returning the output and activated output.
Sourcepub fn backpropagate(
&mut self,
input: &RowVector<I>,
output: &RowVector<O>,
error_next: &RowVector<O>,
) -> RowVector<I>
pub fn backpropagate( &mut self, input: &RowVector<I>, output: &RowVector<O>, error_next: &RowVector<O>, ) -> RowVector<I>
Performs backpropagation for this layer, updating weights and biases, and returning the error to propagate to the previous layer.
§Arguments
input: The input to this layer (activated output from previous layer, or raw input for first layer)output: The pre-activation output from the forward passerror_next: The error propagated from the next layer (or output error for final layer)learning_rate: The learning rate for weight updates
§Returns
The error to propagate to the previous layer
Auto Trait Implementations§
impl<const I: usize, const O: usize> Freeze for LinearLayer<I, O>
impl<const I: usize, const O: usize> RefUnwindSafe for LinearLayer<I, O>
impl<const I: usize, const O: usize> Send for LinearLayer<I, O>
impl<const I: usize, const O: usize> Sync for LinearLayer<I, O>
impl<const I: usize, const O: usize> Unpin for LinearLayer<I, O>
impl<const I: usize, const O: usize> UnwindSafe for LinearLayer<I, O>
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<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.