pub struct BaselineComparator { /* private fields */ }Expand description
Compares multiple models by their rolling error and tracks the current best.
Each entry is identified by a name and maintains its own RollingMae.
The comparator does not store models, only error metrics, so it can be
used alongside any predictor.
Implementations§
Source§impl BaselineComparator
impl BaselineComparator
Sourcepub fn new(names: &[&str], window_size: usize) -> Result<Self, RillError>
pub fn new(names: &[&str], window_size: usize) -> Result<Self, RillError>
Create a new comparator with one entry per name and the given window size.
§Errors
Returns RillError::EmptyFeatures if names is empty, and
RillError::InvalidParameter if names contains duplicates.
A window_size of zero propagates RillError::InvalidWindowSize
from the underlying RollingMae.
Sourcepub fn record(
&mut self,
index: usize,
truth: f64,
prediction: f64,
) -> Result<(), RillError>
pub fn record( &mut self, index: usize, truth: f64, prediction: f64, ) -> Result<(), RillError>
Record a single (truth, prediction) observation against the entry at index.
§Errors
Returns RillError::DimensionMismatch if index is out of bounds,
and propagates any finiteness error from the underlying metric.
Sourcepub fn update_best(&mut self) -> Option<usize>
pub fn update_best(&mut self) -> Option<usize>
Recompute the best entry and return the new best index if it changed.
The best entry is the one with the lowest rolling MAE among entries
that have at least one observation. If all entries are empty, the best
index is cleared and the last switch reason is set to
SwitchReason::InsufficientData.
Returns Some(new_index) when the best entry changes, and None
otherwise.
Sourcepub const fn best_index(&self) -> Option<usize>
pub const fn best_index(&self) -> Option<usize>
Index of the current best entry, or None if no entry has data.
Sourcepub fn best_name(&self) -> Option<&str>
pub fn best_name(&self) -> Option<&str>
Name of the current best entry, or None if no entry has data.
Sourcepub fn best_error(&self) -> Option<f64>
pub fn best_error(&self) -> Option<f64>
Rolling MAE of the current best entry, or None if unavailable.
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Number of tracked entries.
Sourcepub const fn switch_count(&self) -> u64
pub const fn switch_count(&self) -> u64
How many times the best entry has changed since construction or last reset.
Sourcepub const fn last_switch_reason(&self) -> Option<SwitchReason>
pub const fn last_switch_reason(&self) -> Option<SwitchReason>
The reason for the most recent best-entry change (or InsufficientData).
Sourcepub fn entry(&self, index: usize) -> Option<&ComparatorEntry>
pub fn entry(&self, index: usize) -> Option<&ComparatorEntry>
Borrow the entry at index, or None if out of bounds.
Trait Implementations§
Source§impl Clone for BaselineComparator
impl Clone for BaselineComparator
Source§fn clone(&self) -> BaselineComparator
fn clone(&self) -> BaselineComparator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more