pub struct QuantileForecaster { /* private fields */ }Expand description
Wraps a ForecastModel with empirical, horizon-aware quantile intervals.
§Example
use chronix_analytics::forecast::{
HoltWintersModel, QuantileConfig, QuantileForecaster,
};
let config = QuantileConfig::central(0.9, 24);
let mut qf = QuantileForecaster::new(
|| Box::new(HoltWintersModel::new(Some(0.3), Some(0.1), Some(0.1), Some(24), false)),
config,
);
qf.fit(×tamps, &values)?;
let forecast = qf.predict(24)?;
let p05 = forecast.level(0.05).expect("requested level");Implementations§
Source§impl QuantileForecaster
impl QuantileForecaster
Sourcepub fn new<F>(factory: F, config: QuantileConfig) -> Self
pub fn new<F>(factory: F, config: QuantileConfig) -> Self
Build a forecaster from a model factory.
factory must return a fresh, unfitted model on every call.
Sourcepub fn fit(
&mut self,
timestamps: &[i64],
values: &[f64],
) -> Result<(), ForecastError>
pub fn fit( &mut self, timestamps: &[i64], values: &[f64], ) -> Result<(), ForecastError>
Fit the underlying model and calibrate the residual distribution.
§Errors
Returns ForecastError::InvalidInput if the configuration is
invalid or the series is too short to produce a single rolling origin,
or propagates the underlying model’s fit errors.
Sourcepub fn predict(&self, horizon: usize) -> Result<QuantileForecast, ForecastError>
pub fn predict(&self, horizon: usize) -> Result<QuantileForecast, ForecastError>
Produce point forecasts plus calibrated quantiles for horizon steps.
Horizons beyond the calibrated range reuse the last calibrated step’s residual distribution, which is the most conservative available estimate rather than a silent extrapolation.
§Errors
Returns ForecastError::NotFitted if fit has not
been called, or propagates the underlying model’s prediction errors.
Sourcepub fn predict_interval(
&self,
horizon: usize,
level: f64,
) -> Result<ForecastResult, ForecastError>
pub fn predict_interval( &self, horizon: usize, level: f64, ) -> Result<ForecastResult, ForecastError>
Rewrite a ForecastResult’s bounds using the calibrated empirical
quantiles, keeping the existing API shape.
§Errors
As predict.
Sourcepub fn calibration_size(&self, h: usize) -> usize
pub fn calibration_size(&self, h: usize) -> usize
Number of calibration residuals collected for horizon step h
(1-based). Returns 0 for uncalibrated horizons.
Sourcepub fn model(&self) -> &dyn ForecastModel
pub fn model(&self) -> &dyn ForecastModel
The wrapped model.
Auto Trait Implementations§
impl !RefUnwindSafe for QuantileForecaster
impl !UnwindSafe for QuantileForecaster
impl Freeze for QuantileForecaster
impl Send for QuantileForecaster
impl Sync for QuantileForecaster
impl Unpin for QuantileForecaster
impl UnsafeUnpin for QuantileForecaster
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
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> ⓘ
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