pub struct AdaptiveLearningRateController<A: Float> { /* private fields */ }Expand description
Adaptive learning-rate controller.
O1: this used to be a stub whose every method ignored its arguments — the
rate never moved, compute_adaptation echoed the base rate back and
last_change was hard-coded to None, so the whole AdaptationType:: LearningRate pipeline was a no-op that “applied” the same value forever.
The real controller combines two established online signals, both computed from data the caller already supplies:
- Gradient-norm normalisation (an AdaGrad-style trust region): the rate
is scaled by
1 / (1 + sqrt(accumulated squared gradient norm)), so a burst of large gradients shrinks the step and a quiet stretch restores it. - Performance feedback: the sign of the recent loss trend, estimated by ordinary least squares over the supplied metric window, nudges the rate up while the loss is falling and down while it is rising.
Every update is clamped to [min_rate, max_rate] from the configuration and
recorded, so last_change reports the real delta that was applied.
Implementations§
Source§impl<A: Float> AdaptiveLearningRateController<A>
impl<A: Float> AdaptiveLearningRateController<A>
Sourcepub fn new(config: &StreamingConfig) -> Result<Self, OptimError>
pub fn new(config: &StreamingConfig) -> Result<Self, OptimError>
Builds a controller from the streaming learning-rate configuration.
Sourcepub fn update_learning_rate(&mut self, gradient: &Array1<A>) -> A
pub fn update_learning_rate(&mut self, gradient: &Array1<A>) -> A
Folds a real gradient into the controller and returns the resulting rate.
The gradient’s squared L2 norm feeds an AdaGrad accumulator, so the
effective rate is initial / (1 + sqrt(sum of squared norms)) — large or
repeated gradients genuinely shrink the step.
Sourcepub fn is_cyclical(&self) -> bool
pub fn is_cyclical(&self) -> bool
Whether a cyclical schedule is driving this controller.
Sourcepub fn current_rate(&self) -> A
pub fn current_rate(&self) -> A
Current learning rate.
Sourcepub fn accumulated_squared_gradient_norm(&self) -> A
pub fn accumulated_squared_gradient_norm(&self) -> A
Accumulated squared gradient norm (the AdaGrad state).
Sourcepub fn update_count(&self) -> usize
pub fn update_count(&self) -> usize
Number of updates the controller has applied.
Sourcepub fn compute_adaptation(&self, performance_metrics: &[A]) -> A
pub fn compute_adaptation(&self, performance_metrics: &[A]) -> A
Proposes the next learning rate from a window of recent performance metrics, most-recent-last.
The trend is the ordinary-least-squares slope of the metric against its
index. A falling metric (negative slope) means the current rate is
working, so the rate is grown by 1 + performance_sensitivity; a rising
metric shrinks it by 1 - performance_sensitivity. With fewer than two
samples there is no trend to read and the current rate is returned
unchanged.
Sourcepub fn apply_adaptation(&mut self, adaptation: A)
pub fn apply_adaptation(&mut self, adaptation: A)
Applies a proposed rate, recording the real delta.
Sourcepub fn last_change(&self) -> Option<A>
pub fn last_change(&self) -> Option<A>
Delta applied by the most recent rate change, or None if the rate has
never moved.
Trait Implementations§
Auto Trait Implementations§
impl<A> Freeze for AdaptiveLearningRateController<A>where
A: Freeze,
impl<A> RefUnwindSafe for AdaptiveLearningRateController<A>where
A: RefUnwindSafe,
impl<A> Send for AdaptiveLearningRateController<A>where
A: Send,
impl<A> Sync for AdaptiveLearningRateController<A>where
A: Sync,
impl<A> Unpin for AdaptiveLearningRateController<A>where
A: Unpin,
impl<A> UnsafeUnpin for AdaptiveLearningRateController<A>where
A: UnsafeUnpin,
impl<A> UnwindSafe for AdaptiveLearningRateController<A>where
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.