pub struct PrequentialEvaluator { /* private fields */ }Expand description
Prequential (test-then-train) evaluator for streaming regression models.
For each sample:
- Predict – query the model before it sees this sample.
- Record – update metrics with (target, prediction) if past warmup and on the evaluation step interval.
- Train – feed the sample to the model.
This ensures the model is always evaluated on unseen data, which is the correct methodology for streaming ML (as opposed to train-then-test which leaks information).
§Metric Backends
- Cumulative (
RegressionMetrics) – always active, tracks MAE/MSE/RMSE/R-squared over all evaluated samples. - Rolling (
RollingRegressionMetrics) – optional, windowed metrics over the last N evaluated samples. - EWMA (
EwmaRegressionMetrics) – optional, exponentially weighted metrics with configurable span.
§Example
use irithyll::evaluation::{PrequentialEvaluator, PrequentialConfig};
use irithyll::learner::{SGBTLearner, StreamingLearner};
use irithyll::SGBTConfig;
let config = SGBTConfig::builder()
.n_steps(5)
.learning_rate(0.1)
.grace_period(10)
.build()
.unwrap();
let mut model = SGBTLearner::from_config(config);
let mut eval = PrequentialEvaluator::new()
.with_rolling_window(50)
.with_ewma(20);
// Simulate a data stream
for i in 0..200 {
let x = [i as f64, (i as f64).sin()];
let y = i as f64 * 0.5 + 1.0;
eval.step(&mut model, &x, y);
}
assert!(eval.regression_metrics().n_samples() > 0);Implementations§
Source§impl PrequentialEvaluator
impl PrequentialEvaluator
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new evaluator with default configuration (warmup=0, step_interval=1).
Sourcepub fn with_config(config: PrequentialConfig) -> Self
pub fn with_config(config: PrequentialConfig) -> Self
Create a new evaluator with the given configuration.
Sourcepub fn with_rolling_window(self, window_size: usize) -> Self
pub fn with_rolling_window(self, window_size: usize) -> Self
Enable rolling (windowed) regression metrics.
Metrics will be computed over the last window_size evaluated samples.
§Panics
Panics if window_size is zero.
Sourcepub fn with_ewma(self, span: usize) -> Self
pub fn with_ewma(self, span: usize) -> Self
Enable EWMA (exponentially weighted) regression metrics.
The decay factor is alpha = 2 / (span + 1).
§Panics
Panics if span is zero.
Sourcepub fn step(
&mut self,
model: &mut dyn StreamingLearner,
features: &[f64],
target: f64,
) -> f64
pub fn step( &mut self, model: &mut dyn StreamingLearner, features: &[f64], target: f64, ) -> f64
Process a single sample through the test-then-train protocol.
- Predict using the current model state.
- If past warmup and on the step interval, record metrics.
- Train the model on this sample.
- Return the prediction (made before training).
The model always trains on every sample, regardless of warmup or step interval. Only metric recording is gated.
Sourcepub fn evaluate<O: Observation>(
&mut self,
model: &mut dyn StreamingLearner,
data: &[O],
)
pub fn evaluate<O: Observation>( &mut self, model: &mut dyn StreamingLearner, data: &[O], )
Run the full test-then-train protocol over a slice of observations.
Iterates over data, calling step for each observation.
Sourcepub fn regression_metrics(&self) -> &RegressionMetrics
pub fn regression_metrics(&self) -> &RegressionMetrics
Reference to the cumulative regression metrics.
Sourcepub fn rolling_metrics(&self) -> Option<&RollingRegressionMetrics>
pub fn rolling_metrics(&self) -> Option<&RollingRegressionMetrics>
Reference to the rolling regression metrics, if enabled.
Sourcepub fn ewma_metrics(&self) -> Option<&EwmaRegressionMetrics>
pub fn ewma_metrics(&self) -> Option<&EwmaRegressionMetrics>
Reference to the EWMA regression metrics, if enabled.
Sourcepub fn samples_seen(&self) -> u64
pub fn samples_seen(&self) -> u64
Total number of samples processed (both warmup and evaluated).
Sourcepub fn samples_evaluated(&self) -> u64
pub fn samples_evaluated(&self) -> u64
Number of samples that were actually evaluated (past warmup, on step interval).
Trait Implementations§
Source§impl Clone for PrequentialEvaluator
impl Clone for PrequentialEvaluator
Source§fn clone(&self) -> PrequentialEvaluator
fn clone(&self) -> PrequentialEvaluator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PrequentialEvaluator
impl Debug for PrequentialEvaluator
Auto Trait Implementations§
impl Freeze for PrequentialEvaluator
impl RefUnwindSafe for PrequentialEvaluator
impl Send for PrequentialEvaluator
impl Sync for PrequentialEvaluator
impl Unpin for PrequentialEvaluator
impl UnsafeUnpin for PrequentialEvaluator
impl UnwindSafe for PrequentialEvaluator
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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