pub struct GradientNoiseInjector { /* private fields */ }Expand description
Injects configurable noise into gradient arrays for training regularization.
Implementations§
Source§impl GradientNoiseInjector
impl GradientNoiseInjector
Sourcepub fn new(config: GradientNoiseConfig) -> Self
pub fn new(config: GradientNoiseConfig) -> Self
Create a new injector from the given configuration.
The internal PRNG is seeded with config.seed (or a fallback value if
the seed is zero, since xorshift64 requires a non-zero state).
Sourcepub fn next_gaussian(&mut self) -> f64
pub fn next_gaussian(&mut self) -> f64
Sample from a standard Gaussian (mean 0, std 1) using the Box-Muller transform.
Sourcepub fn next_uniform(&mut self, low: f64, high: f64) -> f64
pub fn next_uniform(&mut self, low: f64, high: f64) -> f64
Sample from a uniform distribution on [low, high).
Sourcepub fn next_laplacian(&mut self, scale: f64) -> f64
pub fn next_laplacian(&mut self, scale: f64) -> f64
Sample from a Laplacian distribution with location 0 and the given
scale, using the inverse-CDF method.
Sourcepub fn clip_noise(&self, value: f64) -> f64
pub fn clip_noise(&self, value: f64) -> f64
Clip value to [-clip, +clip] if a clip bound is configured,
otherwise return value unchanged.
Sourcepub fn current_scale(&self) -> f64
pub fn current_scale(&self) -> f64
Compute the current effective noise scale, accounting for decay when
using ScheduledGaussian.
Sourcepub fn inject(&mut self, gradients: &mut [f64])
pub fn inject(&mut self, gradients: &mut [f64])
Inject noise into gradients in-place.
Each element of the slice receives an independent noise sample drawn from the configured distribution. Statistics are updated accordingly.
Sourcepub fn sample_noise(&mut self, count: usize) -> NoiseSample
pub fn sample_noise(&mut self, count: usize) -> NoiseSample
Generate count noise samples without applying them to any gradient
array. Returns a NoiseSample with summary statistics.
Sourcepub fn step(&mut self)
pub fn step(&mut self)
Advance the training step counter by one. This affects the noise
scale when using ScheduledGaussian.
Sourcepub fn stats(&self) -> &NoiseStats
pub fn stats(&self) -> &NoiseStats
Read-only access to the accumulated statistics.
Auto Trait Implementations§
impl Freeze for GradientNoiseInjector
impl RefUnwindSafe for GradientNoiseInjector
impl Send for GradientNoiseInjector
impl Sync for GradientNoiseInjector
impl Unpin for GradientNoiseInjector
impl UnsafeUnpin for GradientNoiseInjector
impl UnwindSafe for GradientNoiseInjector
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