pub struct TensorOptimizationHistory {
pub steps: Vec<OptimizationStep>,
pub config: OptimizationHistoryConfig,
pub best_loss: f64,
pub best_step: u64,
pub consecutive_no_progress: usize,
}Expand description
Records and analyzes a history of optimization steps.
§Convergence detection
After each record call the tracker
compares the new loss against the previous best. If the improvement
(previous_best − new_loss) is below
OptimizationHistoryConfig::convergence_threshold the
consecutive_no_progress counter is incremented; otherwise it is reset to
zero. Once the counter reaches
OptimizationHistoryConfig::convergence_patience the status transitions
to ConvergenceStatus::Converged; once it reaches patience / 2
(integer division) it transitions to
ConvergenceStatus::PossiblyConverged.
Fields§
§steps: Vec<OptimizationStep>Retained optimization steps (oldest first).
config: OptimizationHistoryConfigConfiguration.
best_loss: f64Best (lowest) loss seen so far.
best_step: u64Step index that achieved best_loss.
consecutive_no_progress: usizeNumber of consecutive steps that did not improve loss by at least
convergence_threshold.
Implementations§
Source§impl TensorOptimizationHistory
impl TensorOptimizationHistory
Sourcepub fn new(config: OptimizationHistoryConfig) -> Self
pub fn new(config: OptimizationHistoryConfig) -> Self
Creates a new history tracker with the given configuration.
Sourcepub fn record(&mut self, step: OptimizationStep)
pub fn record(&mut self, step: OptimizationStep)
Records a new optimization step.
If the history buffer is full the oldest entry is evicted. Best loss tracking and consecutive-no-progress counting are updated accordingly.
Sourcepub fn convergence_status(&self) -> ConvergenceStatus
pub fn convergence_status(&self) -> ConvergenceStatus
Returns the current ConvergenceStatus based on the consecutive
no-progress counter.
Sourcepub fn recent_improvement(&self, n: usize) -> f64
pub fn recent_improvement(&self, n: usize) -> f64
Computes the total loss improvement over the last n steps.
Returns first_loss_in_window − last_loss_in_window; a positive value
means the loss is decreasing (improving). Returns 0.0 when fewer
than two steps are available.
Sourcepub fn avg_gradient_norm(&self) -> f64
pub fn avg_gradient_norm(&self) -> f64
Returns the arithmetic mean of all recorded gradient_norm values.
Returns 0.0 when no steps have been recorded.
Sourcepub fn stats(&self) -> HistoryStats
pub fn stats(&self) -> HistoryStats
Computes and returns aggregated HistoryStats for the current
history buffer.
Sourcepub fn last_step(&self) -> Option<&OptimizationStep>
pub fn last_step(&self) -> Option<&OptimizationStep>
Returns a reference to the most recently recorded step, or None if
the history is empty.
Auto Trait Implementations§
impl Freeze for TensorOptimizationHistory
impl RefUnwindSafe for TensorOptimizationHistory
impl Send for TensorOptimizationHistory
impl Sync for TensorOptimizationHistory
impl Unpin for TensorOptimizationHistory
impl UnsafeUnpin for TensorOptimizationHistory
impl UnwindSafe for TensorOptimizationHistory
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