Skip to main content

NoiseInjectionScheduler

Struct NoiseInjectionScheduler 

Source
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>

Source

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 to
  • noise_dist - The noise distribution to use
  • min_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);
Source

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());
}
Source

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.

Source

pub fn seed(&self) -> u64

Seed the scheduler’s RNG was built from

Source

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>

Source§

fn clone(&self) -> NoiseInjectionScheduler<A, S>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A, S> Debug for NoiseInjectionScheduler<A, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<A, S> LearningRateScheduler<A> for NoiseInjectionScheduler<A, S>

Source§

fn get_learning_rate(&self) -> A

Get the learning rate at the current step
Source§

fn step(&mut self) -> A

Update the scheduler state and return the new learning rate
Source§

fn reset(&mut self)

Reset the scheduler state
Source§

fn step_with_metric(&mut self, metric: A) -> A

Update the scheduler state using an observed metric and return the new learning rate Read more
Source§

fn apply_to<D, O>(&self, optimizer: &mut O)
where D: Dimension, O: Optimizer<A, D>, Self: Sized,

Apply the scheduler to an optimizer

Auto Trait Implementations§

§

impl<A, S> Freeze for NoiseInjectionScheduler<A, S>
where S: Freeze, A: Freeze,

§

impl<A, S> RefUnwindSafe for NoiseInjectionScheduler<A, S>

§

impl<A, S> Send for NoiseInjectionScheduler<A, S>
where S: Send, A: Send,

§

impl<A, S> Sync for NoiseInjectionScheduler<A, S>
where S: Sync, A: Sync,

§

impl<A, S> Unpin for NoiseInjectionScheduler<A, S>
where S: Unpin, A: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,