pub struct ConvergenceDetector { /* private fields */ }Expand description
Convergence detection for federated learning.
Supports two usage modes:
- Legacy:
new(window_size, threshold)+add_loss()+has_converged() - EMA mode:
with_config(cfg)+update(loss)returns bool
Implementations§
Source§impl ConvergenceDetector
impl ConvergenceDetector
Sourcepub fn new(window_size: usize, threshold: f64) -> Self
pub fn new(window_size: usize, threshold: f64) -> Self
Create a new convergence detector (legacy mode).
Sourcepub fn with_config(config: ConvergenceConfig) -> Self
pub fn with_config(config: ConvergenceConfig) -> Self
Create a convergence detector driven by ConvergenceConfig.
Sourcepub fn has_converged(&self) -> bool
pub fn has_converged(&self) -> bool
Check if training has converged (legacy mode).
Sourcepub fn latest_loss(&self) -> Option<f64>
pub fn latest_loss(&self) -> Option<f64>
Get the latest loss (legacy mode).
Sourcepub fn update(&mut self, loss: f32) -> bool
pub fn update(&mut self, loss: f32) -> bool
Record a new loss value and check for convergence (EMA mode).
Returns true when the smoothed gradient norm drops below config.threshold
for config.patience consecutive rounds.
Sourcepub fn smoothed_loss(&self) -> f32
pub fn smoothed_loss(&self) -> f32
Exponentially smoothed loss (EMA mode).
Sourcepub fn gradient_norm(&self) -> f32
pub fn gradient_norm(&self) -> f32
Gradient norm computed as mean |Δloss| over the window (EMA mode).
Sourcepub fn plateau_rounds(&self) -> usize
pub fn plateau_rounds(&self) -> usize
Number of consecutive rounds the gradient norm has been below threshold (EMA mode).
Sourcepub fn config(&self) -> Option<&ConvergenceConfig>
pub fn config(&self) -> Option<&ConvergenceConfig>
Return a reference to the ConvergenceConfig (EMA mode).
Returns None when constructed in legacy mode.
Auto Trait Implementations§
impl Freeze for ConvergenceDetector
impl RefUnwindSafe for ConvergenceDetector
impl Send for ConvergenceDetector
impl Sync for ConvergenceDetector
impl Unpin for ConvergenceDetector
impl UnsafeUnpin for ConvergenceDetector
impl UnwindSafe for ConvergenceDetector
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
Mutably borrows from an owned value. Read more
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>
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 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>
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