pub struct ARIMA { /* private fields */ }Expand description
ARIMA (Auto-Regressive Integrated Moving Average) model.
ARIMA(p, d, q) model for time series forecasting:
- p: Order of auto-regressive (AR) component
- d: Degree of differencing (I) for stationarity
- q: Order of moving average (MA) component
§Examples
use aprender::time_series::ARIMA;
use aprender::primitives::Vector;
// Create ARIMA(1, 1, 1) model
let mut model = ARIMA::new(1, 1, 1);
// Fit to time series data
let data = Vector::from_slice(&[10.0, 12.0, 13.0, 15.0, 14.0, 16.0, 18.0]);
model.fit(&data).expect("fit should succeed");
// Forecast next period
let forecast = model.forecast(1).expect("forecast should succeed");
assert!(forecast.len() == 1);Implementations§
Source§impl ARIMA
impl ARIMA
Sourcepub fn new(p: usize, d: usize, q: usize) -> ARIMA
pub fn new(p: usize, d: usize, q: usize) -> ARIMA
Create a new ARIMA model with specified orders.
§Arguments
p- AR order (number of lagged observations)d- Differencing order (degree of differencing)q- MA order (number of lagged forecast errors)
§Examples
use aprender::time_series::ARIMA;
// ARIMA(1, 1, 1) - simple model
let model = ARIMA::new(1, 1, 1);
// ARIMA(2, 1, 0) - AR(2) with differencing
let ar_model = ARIMA::new(2, 1, 0);
// ARIMA(0, 1, 1) - MA(1) with differencing (equivalent to exponential smoothing)
let ma_model = ARIMA::new(0, 1, 1);Sourcepub fn fit(&mut self, data: &Vector<f64>) -> Result<(), AprenderError>
pub fn fit(&mut self, data: &Vector<f64>) -> Result<(), AprenderError>
Fit the ARIMA model to time series data.
This performs differencing (if d > 0) and estimates AR/MA parameters using least squares estimation.
§Arguments
data- Time series observations
§Returns
Ok(())- Model fitted successfullyErr(AprenderError)- If fitting fails (insufficient data, etc.)
§Examples
use aprender::time_series::ARIMA;
use aprender::primitives::Vector;
let mut model = ARIMA::new(1, 1, 1);
let data = Vector::from_slice(&[10.0, 12.0, 13.0, 15.0, 14.0, 16.0]);
model.fit(&data).expect("fit should succeed");Sourcepub fn forecast(&self, n_periods: usize) -> Result<Vector<f64>, AprenderError>
pub fn forecast(&self, n_periods: usize) -> Result<Vector<f64>, AprenderError>
Forecast future values.
Generates forecasts for the next n_periods using the fitted model.
§Arguments
n_periods- Number of periods to forecast
§Returns
Ok(Vector)- Forecasted valuesErr(AprenderError)- If model hasn’t been fitted or forecasting fails
§Examples
use aprender::time_series::ARIMA;
use aprender::primitives::Vector;
let mut model = ARIMA::new(1, 1, 1);
let data = Vector::from_slice(&[10.0, 12.0, 13.0, 15.0, 14.0, 16.0]);
model.fit(&data).expect("fit should succeed");
// Forecast next 3 periods
let forecast = model.forecast(3).expect("forecast should succeed");
assert_eq!(forecast.len(), 3);Sourcepub fn ar_coefficients(&self) -> Option<&Vector<f64>>
pub fn ar_coefficients(&self) -> Option<&Vector<f64>>
Get the AR coefficients (if fitted).
§Examples
use aprender::time_series::ARIMA;
use aprender::primitives::Vector;
let mut model = ARIMA::new(2, 0, 0);
let data = Vector::from_slice(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
model.fit(&data).expect("fit should succeed");
let ar_coef = model.ar_coefficients().expect("should have AR coefficients");
assert_eq!(ar_coef.len(), 2);Sourcepub fn ma_coefficients(&self) -> Option<&Vector<f64>>
pub fn ma_coefficients(&self) -> Option<&Vector<f64>>
Get the MA coefficients (if fitted).
§Examples
use aprender::time_series::ARIMA;
use aprender::primitives::Vector;
let mut model = ARIMA::new(0, 0, 1);
let data = Vector::from_slice(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
model.fit(&data).expect("fit should succeed");
let ma_coef = model.ma_coefficients().expect("should have MA coefficients");
assert_eq!(ma_coef.len(), 1);Trait Implementations§
Auto Trait Implementations§
impl Freeze for ARIMA
impl RefUnwindSafe for ARIMA
impl Send for ARIMA
impl Sync for ARIMA
impl Unpin for ARIMA
impl UnsafeUnpin for ARIMA
impl UnwindSafe for ARIMA
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
Converts
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> ⓘ
Converts
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