Skip to main content

ARIMA

Struct ARIMA 

Source
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

Source

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);
Source

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 successfully
  • Err(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");
Source

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 values
  • Err(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);
Source

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);
Source

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);
Source

pub fn intercept(&self) -> f64

Get the model intercept (if fitted).

Source

pub fn order(&self) -> (usize, usize, usize)

Get the model order (p, d, q).

§Examples
use aprender::time_series::ARIMA;

let model = ARIMA::new(1, 1, 1);
assert_eq!(model.order(), (1, 1, 1));

Trait Implementations§

Source§

impl Clone for ARIMA

Source§

fn clone(&self) -> ARIMA

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ARIMA

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,