pub struct BatchNormLayer {
pub running_mean: Vec<f32>,
pub running_var: Vec<f32>,
pub gamma: Vec<f32>,
pub beta: Vec<f32>,
pub epsilon: f32,
pub n_features: usize,
}Expand description
Batch normalization layer (inference mode).
Normalizes input features using stored running mean and variance, then applies learned scale (gamma) and shift (beta).
Fields§
§running_mean: Vec<f32>Running mean for each feature.
running_var: Vec<f32>Running variance for each feature.
gamma: Vec<f32>Learned scale parameter (gamma).
beta: Vec<f32>Learned shift parameter (beta).
epsilon: f32Small constant for numerical stability.
n_features: usizeNumber of features.
Implementations§
Source§impl BatchNormLayer
impl BatchNormLayer
Sourcepub fn new(n_features: usize) -> Self
pub fn new(n_features: usize) -> Self
Create a new batch norm layer with identity transform (gamma=1, beta=0).
Sourcepub fn forward(&self, input: &[f32]) -> Vec<f32>
pub fn forward(&self, input: &[f32]) -> Vec<f32>
Apply batch normalization in inference mode.
output[i] = gamma[i] * (input[i] - mean[i]) / sqrt(var[i] + eps) + beta[i]
Sourcepub fn set_affine(&mut self, gamma: &[f32], beta: &[f32])
pub fn set_affine(&mut self, gamma: &[f32], beta: &[f32])
Set the affine parameters.
Source§impl BatchNormLayer
impl BatchNormLayer
Sourcepub fn update_running_stats(&mut self, batch: &[Vec<f32>], momentum: f32)
pub fn update_running_stats(&mut self, batch: &[Vec<f32>], momentum: f32)
Update running statistics from a mini-batch (training mode).
Uses exponential moving average:
running_mean = (1-momentum) * running_mean + momentum * batch_mean
§Panics
Panics if batch is empty or if any sample has the wrong feature count.
Trait Implementations§
Source§impl Clone for BatchNormLayer
impl Clone for BatchNormLayer
Source§fn clone(&self) -> BatchNormLayer
fn clone(&self) -> BatchNormLayer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BatchNormLayer
impl RefUnwindSafe for BatchNormLayer
impl Send for BatchNormLayer
impl Sync for BatchNormLayer
impl Unpin for BatchNormLayer
impl UnsafeUnpin for BatchNormLayer
impl UnwindSafe for BatchNormLayer
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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