pub struct DenseLayer {
pub weights: Vec<Vec<f64>>,
pub biases: Vec<f64>,
pub activation: Activation,
}Expand description
An affine-plus-activation layer y = activation(Wx + b).
Weights are stored row-major as weights[out][in]. The layer itself
has no learnable state beyond weights and biases; gradient and
optimiser logic lives with the caller
(see crate::deep_kernel::gradient).
Fields§
§weights: Vec<Vec<f64>>Row-major weight matrix with shape [output_dim][input_dim].
biases: Vec<f64>Bias vector with length output_dim.
activation: ActivationElement-wise activation applied to the affine pre-activation.
Implementations§
Source§impl DenseLayer
impl DenseLayer
Sourcepub fn new(
weights: Vec<Vec<f64>>,
biases: Vec<f64>,
activation: Activation,
) -> Result<Self>
pub fn new( weights: Vec<Vec<f64>>, biases: Vec<f64>, activation: Activation, ) -> Result<Self>
Build a layer from raw weights and biases.
Fails when weight rows disagree in width, when the bias vector does not match the weight row count, or when any entry is non-finite.
Sourcepub fn output_dim(&self) -> usize
pub fn output_dim(&self) -> usize
Output dimension (number of weight rows).
Sourcepub fn activation(&self) -> Activation
pub fn activation(&self) -> Activation
Activation attached to this layer.
Sourcepub fn forward(&self, input: &[f64]) -> Result<Vec<f64>>
pub fn forward(&self, input: &[f64]) -> Result<Vec<f64>>
Forward pass returning only the post-activation output.
Sourcepub fn forward_with_preactivation(
&self,
input: &[f64],
) -> Result<(Vec<f64>, Vec<f64>)>
pub fn forward_with_preactivation( &self, input: &[f64], ) -> Result<(Vec<f64>, Vec<f64>)>
Forward pass returning (pre_activation, post_activation).
The pre-activation is retained so callers implementing analytical
gradients can feed it back into Activation::derivative.
Sourcepub fn parameter_count(&self) -> usize
pub fn parameter_count(&self) -> usize
Count of trainable scalar parameters (weights + biases).
Trait Implementations§
Source§impl Clone for DenseLayer
impl Clone for DenseLayer
Source§fn clone(&self) -> DenseLayer
fn clone(&self) -> DenseLayer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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
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