pub struct TensorBatchNorm {
pub config: BatchNormConfig,
pub gamma: Vec<f64>,
pub beta: Vec<f64>,
pub running_mean: Vec<f64>,
pub running_var: Vec<f64>,
pub mode: NormMode,
pub stats: BatchNormStats,
}Expand description
Batch normalisation layer.
§Layout
Input is expected to have shape [batch_size, num_features].
§Example
use ipfrs_tensorlogic::{TensorBatchNorm, BatchNormConfig, NormMode};
let config = BatchNormConfig::default_for(4);
let mut bn = TensorBatchNorm::new(config);
let batch = vec![
vec![1.0_f64, 2.0, 3.0, 4.0],
vec![5.0_f64, 6.0, 7.0, 8.0],
];
let output = bn.forward(&batch).expect("forward failed");
assert_eq!(output.len(), 2);
assert_eq!(output[0].len(), 4);Fields§
§config: BatchNormConfigLayer configuration.
gamma: Vec<f64>Learnable scale parameters, one per feature (γ, initialised to 1.0).
beta: Vec<f64>Learnable shift parameters, one per feature (β, initialised to 0.0).
running_mean: Vec<f64>Exponential moving average of per-feature batch means.
running_var: Vec<f64>Exponential moving average of per-feature batch variances.
mode: NormModeCurrent execution mode.
stats: BatchNormStatsCollected statistics.
Implementations§
Source§impl TensorBatchNorm
impl TensorBatchNorm
Sourcepub fn new(config: BatchNormConfig) -> Self
pub fn new(config: BatchNormConfig) -> Self
Construct a new TensorBatchNorm from a BatchNormConfig.
Sourcepub fn set_mode(&mut self, mode: NormMode)
pub fn set_mode(&mut self, mode: NormMode)
Switch the layer between training and inference mode.
Sourcepub fn forward(&mut self, input: &[Vec<f64>]) -> Option<Vec<Vec<f64>>>
pub fn forward(&mut self, input: &[Vec<f64>]) -> Option<Vec<Vec<f64>>>
Run a forward pass through the batch normalisation layer.
input— a slice of rows, each of lengthnum_features.
Returns None when:
inputis empty, or- any row does not have exactly
num_featureselements.
Sourcepub fn set_gamma(&mut self, gamma: Vec<f64>) -> bool
pub fn set_gamma(&mut self, gamma: Vec<f64>) -> bool
Replace the gamma (scale) parameters.
Returns false and leaves gamma unchanged when gamma.len() != num_features.
Sourcepub fn set_beta(&mut self, beta: Vec<f64>) -> bool
pub fn set_beta(&mut self, beta: Vec<f64>) -> bool
Replace the beta (shift) parameters.
Returns false and leaves beta unchanged when beta.len() != num_features.
Sourcepub fn stats(&self) -> &BatchNormStats
pub fn stats(&self) -> &BatchNormStats
Borrow the accumulated statistics.
Auto Trait Implementations§
impl Freeze for TensorBatchNorm
impl RefUnwindSafe for TensorBatchNorm
impl Send for TensorBatchNorm
impl Sync for TensorBatchNorm
impl Unpin for TensorBatchNorm
impl UnsafeUnpin for TensorBatchNorm
impl UnwindSafe for TensorBatchNorm
Blanket Implementations§
impl<T> Allocation for T
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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