pub struct DifferentiableDenseLayer {
pub layer: DenseLayer,
pub surrogate: SurrogateType,
input_cache: Vec<f64>,
output_cache: Vec<f64>,
}Expand description
Dense SC layer with surrogate gradient backward pass.
Fields§
§layer: DenseLayer§surrogate: SurrogateType§input_cache: Vec<f64>§output_cache: Vec<f64>Implementations§
Source§impl DifferentiableDenseLayer
impl DifferentiableDenseLayer
Sourcepub fn new(
n_inputs: usize,
n_neurons: usize,
length: usize,
seed: u64,
surrogate: SurrogateType,
) -> Self
pub fn new( n_inputs: usize, n_neurons: usize, length: usize, seed: u64, surrogate: SurrogateType, ) -> Self
Construct a differentiable dense SC layer.
Sourcepub fn forward(
&mut self,
input_values: &[f64],
seed: u64,
) -> Result<Vec<f64>, String>
pub fn forward( &mut self, input_values: &[f64], seed: u64, ) -> Result<Vec<f64>, String>
Forward pass and cache activations for backward pass.
Sourcepub fn backward(
&self,
grad_output: &[f64],
) -> Result<(Vec<f64>, Vec<Vec<f64>>), String>
pub fn backward( &self, grad_output: &[f64], ) -> Result<(Vec<f64>, Vec<Vec<f64>>), String>
Backward pass producing input and weight gradients.
Sourcepub fn update_weights(&mut self, weight_grads: &[Vec<f64>], lr: f64)
pub fn update_weights(&mut self, weight_grads: &[Vec<f64>], lr: f64)
Apply gradient descent update and clamp weights to [0, 1].
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Clear cached forward tensors.
Auto Trait Implementations§
impl Freeze for DifferentiableDenseLayer
impl RefUnwindSafe for DifferentiableDenseLayer
impl Send for DifferentiableDenseLayer
impl Sync for DifferentiableDenseLayer
impl Unpin for DifferentiableDenseLayer
impl UnsafeUnpin for DifferentiableDenseLayer
impl UnwindSafe for DifferentiableDenseLayer
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> 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