pub struct NoiseInjectionScheduler<A, S>{ /* private fields */ }Expand description
A learning rate scheduler that injects noise into the base learning rate
The noise sample is drawn once per LearningRateScheduler::step and cached, so
LearningRateScheduler::get_learning_rate is idempotent between steps: reading the
learning rate twice without stepping returns the same value.
The scheduler owns a seeded, reproducible RNG. Use NoiseInjectionScheduler::with_seed
(or NoiseInjectionScheduler::new_seeded) to pin the seed; two schedulers built with
the same seed produce byte-identical learning rate sequences.
Implementations§
Source§impl<A, S> NoiseInjectionScheduler<A, S>
impl<A, S> NoiseInjectionScheduler<A, S>
Sourcepub fn new(
base_scheduler: S,
noise_dist: NoiseDistribution<A>,
min_lr: A,
) -> NoiseInjectionScheduler<A, S>
pub fn new( base_scheduler: S, noise_dist: NoiseDistribution<A>, min_lr: A, ) -> NoiseInjectionScheduler<A, S>
Create a new noise injection scheduler with a randomly chosen seed
§Arguments
base_scheduler- The base scheduler to add noise tonoise_dist- The noise distribution to usemin_lr- The minimum learning rate allowed (to ensure stability)
§Example
use optirs_core::schedulers::{
ExponentialDecay, NoiseDistribution, NoiseInjectionScheduler, LearningRateScheduler
};
// Create a base scheduler
let base_scheduler = ExponentialDecay::new(0.1, 0.9, 10);
// Create a noise injection scheduler with uniform noise
let mut scheduler = NoiseInjectionScheduler::new(
base_scheduler,
NoiseDistribution::Uniform { min: -0.01, max: 0.01 },
0.001, // Minimum learning rate
);
// Get the learning rate (will be 0.1 plus some noise)
let lr = scheduler.get_learning_rate();
assert!(lr >= 0.001); // Learning rate should be at least min_lr
// Reading again without stepping yields exactly the same value
assert_eq!(lr, scheduler.get_learning_rate());
assert!(scheduler.step() >= 0.001);Sourcepub fn new_seeded(
base_scheduler: S,
noise_dist: NoiseDistribution<A>,
min_lr: A,
seed: u64,
) -> NoiseInjectionScheduler<A, S>
pub fn new_seeded( base_scheduler: S, noise_dist: NoiseDistribution<A>, min_lr: A, seed: u64, ) -> NoiseInjectionScheduler<A, S>
Create a new noise injection scheduler with an explicit seed
Two schedulers created with the same seed, the same distribution and the same base scheduler produce identical learning rate sequences.
§Example
use optirs_core::schedulers::{
ConstantScheduler, NoiseDistribution, NoiseInjectionScheduler, LearningRateScheduler
};
let dist = NoiseDistribution::Uniform { min: -0.01f64, max: 0.01 };
let mut a = NoiseInjectionScheduler::new_seeded(ConstantScheduler::new(0.1), dist, 0.001, 7);
let mut b = NoiseInjectionScheduler::new_seeded(ConstantScheduler::new(0.1), dist, 0.001, 7);
for _ in 0..16 {
assert_eq!(a.step(), b.step());
}Sourcepub fn with_seed(self, seed: u64) -> NoiseInjectionScheduler<A, S>
pub fn with_seed(self, seed: u64) -> NoiseInjectionScheduler<A, S>
Re-seed the scheduler’s RNG
The cached noise sample is re-derived from the new seed so the very first
LearningRateScheduler::get_learning_rate is already deterministic.
Sourcepub fn current_noise(&self) -> A
pub fn current_noise(&self) -> A
Noise sample currently applied to the base learning rate
Trait Implementations§
Source§impl<A, S> Clone for NoiseInjectionScheduler<A, S>
impl<A, S> Clone for NoiseInjectionScheduler<A, S>
Source§fn clone(&self) -> NoiseInjectionScheduler<A, S>
fn clone(&self) -> NoiseInjectionScheduler<A, S>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<A, S> Debug for NoiseInjectionScheduler<A, S>
impl<A, S> Debug for NoiseInjectionScheduler<A, S>
Source§impl<A, S> LearningRateScheduler<A> for NoiseInjectionScheduler<A, S>
impl<A, S> LearningRateScheduler<A> for NoiseInjectionScheduler<A, S>
Source§fn get_learning_rate(&self) -> A
fn get_learning_rate(&self) -> A
Source§fn step_with_metric(&mut self, metric: A) -> A
fn step_with_metric(&mut self, metric: A) -> A
Auto Trait Implementations§
impl<A, S> Freeze for NoiseInjectionScheduler<A, S>
impl<A, S> RefUnwindSafe for NoiseInjectionScheduler<A, S>where
S: RefUnwindSafe,
A: RefUnwindSafe,
impl<A, S> Send for NoiseInjectionScheduler<A, S>
impl<A, S> Sync for NoiseInjectionScheduler<A, S>
impl<A, S> Unpin for NoiseInjectionScheduler<A, S>
impl<A, S> UnsafeUnpin for NoiseInjectionScheduler<A, S>where
S: UnsafeUnpin,
A: UnsafeUnpin,
impl<A, S> UnwindSafe for NoiseInjectionScheduler<A, S>where
S: UnwindSafe,
A: UnwindSafe,
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.