Skip to main content

chronix_analytics/forecast/
traits.rs

1//! ForecastModel trait definition.
2
3use crate::forecast::error::ForecastError;
4use crate::forecast::result::{ForecastResult, ModelParams, ModelType};
5
6/// Core forecasting abstraction.
7///
8/// All forecast models implement this trait for uniform dispatch, persistence,
9/// and online updating.
10pub trait ForecastModel: Send + Sync {
11    /// Fit the model on historical data.
12    fn fit(&mut self, timestamps: &[i64], values: &[f64]) -> Result<(), ForecastError>;
13
14    /// Predict `horizon` steps ahead.
15    fn predict(&self, horizon: usize) -> Result<ForecastResult, ForecastError>;
16
17    /// Online update with a single new observation.
18    fn update(&mut self, timestamp: i64, value: f64) -> Result<(), ForecastError>;
19
20    /// Returns the model type.
21    fn model_type(&self) -> ModelType;
22
23    /// Returns the fitted parameters.
24    fn params(&self) -> &ModelParams;
25}