pub struct ResidualInterval { /* private fields */ }Expand description
Residual-based prediction interval estimator.
Tracks the exponentially weighted mean of absolute prediction errors and
forms intervals as prediction ± k × recent_error. Does not store raw
samples.
§Examples
use rill_ml::diagnostics::{PredictionInterval, ResidualInterval};
let mut ri = ResidualInterval::default();
ri.observe(10.0, 11.0).unwrap();
ri.observe(10.0, 9.0).unwrap();
let interval: PredictionInterval = ri.interval(10.0).unwrap();
assert!(interval.contains(10.5));Implementations§
Source§impl ResidualInterval
impl ResidualInterval
Sourcepub fn new(config: ResidualIntervalConfig) -> Result<Self, RillError>
pub fn new(config: ResidualIntervalConfig) -> Result<Self, RillError>
Create a new residual interval estimator with the given configuration.
Returns an error if k is not finite or not strictly positive, or if
alpha is not in (0, 1] (the latter is validated by
ExponentiallyWeightedMean::new).
Sourcepub fn observe(&mut self, prediction: f64, truth: f64) -> Result<(), RillError>
pub fn observe(&mut self, prediction: f64, truth: f64) -> Result<(), RillError>
Observe a prediction and its ground truth, updating the error estimate.
The absolute residual |truth - prediction| is fed to the internally
tracked exponentially weighted mean. Non-finite inputs are rejected.
Sourcepub fn interval(&self, prediction: f64) -> Result<PredictionInterval, RillError>
pub fn interval(&self, prediction: f64) -> Result<PredictionInterval, RillError>
Compute the prediction interval centred on prediction.
Returns RillError::InsufficientData if no observations have been
recorded yet, and RillError::NonFiniteValue if prediction is not
finite.
Sourcepub fn recent_error(&self) -> Option<f64>
pub fn recent_error(&self) -> Option<f64>
Recent average absolute error, or None if no observations recorded.
Sourcepub fn samples_seen(&self) -> u64
pub fn samples_seen(&self) -> u64
Number of observations recorded so far.
Trait Implementations§
Source§impl Clone for ResidualInterval
impl Clone for ResidualInterval
Source§fn clone(&self) -> ResidualInterval
fn clone(&self) -> ResidualInterval
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more