pub struct WarmupTracker { /* private fields */ }Expand description
Bounded-memory warmup state tracker.
Tracks the number of observed samples, the most recent absolute error,
and a baseline error. From these it derives a WarmupState.
§Examples
use rill_ml::diagnostics::WarmupTracker;
let mut tracker = WarmupTracker::default();
assert_eq!(tracker.state().as_str(), "no_data");
for _ in 0..5 {
tracker.observe_sample(None).unwrap();
}
assert!(tracker.state().is_ready());Implementations§
Source§impl WarmupTracker
impl WarmupTracker
Sourcepub fn new(config: WarmupConfig) -> Result<Self, RillError>
pub fn new(config: WarmupConfig) -> Result<Self, RillError>
Create a new tracker with the given configuration.
Returns RillError::InvalidParameter if the thresholds are not ordered
warming_up_threshold < usable_threshold <= stable_threshold or if
degraded_error_ratio is not greater than 1.0.
Sourcepub fn observe_sample(&mut self, error: Option<f64>) -> Result<(), RillError>
pub fn observe_sample(&mut self, error: Option<f64>) -> Result<(), RillError>
Observe a sample, optionally with an error value.
When error is Some, the value must be finite; its absolute value
replaces the stored recent error. When error is None, only the
sample counter is incremented.
Returns RillError::NonFiniteValue if error is Some but not finite.
In that case the tracker state is left unchanged.
Sourcepub fn set_baseline(&mut self, baseline: f64) -> Result<(), RillError>
pub fn set_baseline(&mut self, baseline: f64) -> Result<(), RillError>
Set the baseline error for comparison.
The absolute value is stored, so signed errors are accepted.
Sourcepub fn state(&self) -> WarmupState
pub fn state(&self) -> WarmupState
Compute the current warmup state.
The decision is made in priority order:
- No samples seen →
WarmupState::NoData. - Samples below
warming_up_threshold→WarmupState::WarmingUp. - If both recent and baseline errors are available:
- recent > baseline ×
degraded_error_ratio→WarmupState::Degraded. - samples ≥
stable_thresholdand recent ≤ baseline →WarmupState::Stable.
- recent > baseline ×
- Otherwise →
WarmupState::Usable.
Sourcepub const fn recent_error(&self) -> Option<f64>
pub const fn recent_error(&self) -> Option<f64>
The most recent absolute error, or None if none was recorded.
Sourcepub const fn baseline_error(&self) -> Option<f64>
pub const fn baseline_error(&self) -> Option<f64>
The baseline error, or None if not set.
Trait Implementations§
Source§impl Clone for WarmupTracker
impl Clone for WarmupTracker
Source§fn clone(&self) -> WarmupTracker
fn clone(&self) -> WarmupTracker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more