Table of Contents

Class VARMAModel<T>

Namespace
AiDotNet.TimeSeries
Assembly
AiDotNet.dll

Implements a Vector Autoregressive Moving Average (VARMA) model for multivariate time series forecasting.

public class VARMAModel<T> : VectorAutoRegressionModel<T>, ITimeSeriesModel<T>, IFullModel<T, Matrix<T>, Vector<T>>, IModel<Matrix<T>, Vector<T>, ModelMetadata<T>>, IModelSerializer, ICheckpointableModel, IParameterizable<T, Matrix<T>, Vector<T>>, IFeatureAware, IFeatureImportance<T>, ICloneable<IFullModel<T, Matrix<T>, Vector<T>>>, IGradientComputable<T, Matrix<T>, Vector<T>>, IJitCompilable<T>

Type Parameters

T

The numeric data type used for calculations (e.g., float, double).

Inheritance
VARMAModel<T>
Implements
IFullModel<T, Matrix<T>, Vector<T>>
IModel<Matrix<T>, Vector<T>, ModelMetadata<T>>
IParameterizable<T, Matrix<T>, Vector<T>>
ICloneable<IFullModel<T, Matrix<T>, Vector<T>>>
IGradientComputable<T, Matrix<T>, Vector<T>>
Inherited Members
Extension Methods

Remarks

The VARMA model extends the Vector Autoregressive (VAR) model by incorporating Moving Average (MA) terms, allowing it to capture more complex dynamics in multivariate time series data. It models the relationships between multiple time series variables and their past values, as well as past error terms.

For Beginners: A VARMA model helps you forecast multiple related time series at once, accounting for:

  • How each variable depends on its own past values
  • How each variable depends on other variables' past values
  • How past prediction errors affect current values

For example, if you're analyzing economic data, a VARMA model could simultaneously forecast:

  • GDP growth
  • Unemployment rate
  • Inflation rate

While accounting for how these variables affect each other and incorporating information from past prediction errors to improve accuracy.

Think of it as a sophisticated forecasting system that recognizes both the interconnections between different variables and learns from its own mistakes.

Constructors

VARMAModel(VARMAModelOptions<T>)

Initializes a new instance of the VARMAModel class with the specified options.

public VARMAModel(VARMAModelOptions<T> options)

Parameters

options VARMAModelOptions<T>

The configuration options for the VARMA model.

Remarks

For Beginners: When you create a VARMA model, you need to specify several options:

  • Output Dimension: How many different time series you're modeling together
  • AR Lag: How many past time periods to consider for the autoregressive part
  • MA Lag: How many past time periods to consider for the moving average part

For example, if you're modeling quarterly economic indicators with:

  • 3 variables (GDP, unemployment, inflation)
  • AR Lag of 4 (consider the past year of data)
  • MA Lag of 2 (consider prediction errors from the past two quarters)

The constructor initializes the model structure based on these specifications. The MA coefficients matrix will have dimensions based on the output dimension and MA lag.

Methods

DeserializeCore(BinaryReader)

Deserializes the model's core parameters from a binary reader.

protected override void DeserializeCore(BinaryReader reader)

Parameters

reader BinaryReader

The binary reader to read from.

Remarks

For Beginners: Deserialization is the process of loading a previously saved model from disk. This method reads the model's parameters from a file and reconstructs the model exactly as it was when it was saved.

This method:

  1. First calls the base class's deserialization method to load the VAR part of the model
  2. Then loads the VARMA-specific options (like the MA lag)
  3. Finally loads the MA coefficients matrix

The MA coefficients are read in the same order they were written: row by row, column by column.

After deserialization, the model is ready to make predictions without needing to be retrained. This is particularly useful when:

  • You have a complex model that took a long time to train
  • You want to ensure consistent predictions across different runs or applications
  • You're deploying a model to a production environment where training isn't feasible

Predict(Matrix<T>)

Generates forecasts using the trained VARMA model.

public override Vector<T> Predict(Matrix<T> input)

Parameters

input Matrix<T>

The input features matrix.

Returns

Vector<T>

A vector of forecasted values.

Remarks

For Beginners: When making predictions with a VARMA model, two components are combined:

  1. The AR (autoregressive) prediction:

    • This comes from the VAR part of the model
    • It's based on past values of all variables
  2. The MA (moving average) prediction:

    • This is based on past prediction errors
    • It helps correct for systematic errors the AR part might make

The final prediction is the sum of these two components.

For example, if the AR part predicts economic growth of 2.5%, but the model has consistently underestimated growth by about 0.3% recently, the MA part might add that 0.3% correction, resulting in a final prediction of 2.8% growth.

SerializeCore(BinaryWriter)

Serializes the model's core parameters to a binary writer.

protected override void SerializeCore(BinaryWriter writer)

Parameters

writer BinaryWriter

The binary writer to write to.

Remarks

For Beginners: Serialization is the process of converting the model's state into a format that can be saved to disk. This allows you to save a trained model and load it later without having to retrain it.

This method:

  1. First calls the base class's serialization method to save the VAR part of the model
  2. Then saves the VARMA-specific options (like the MA lag)
  3. Finally saves the MA coefficients matrix

The MA coefficients are saved row by row, column by column, as double values. This ensures that when the model is loaded later, it will make exactly the same predictions as it did before being saved.

Serialization is particularly useful for:

  • Deploying models to production environments
  • Sharing models between different applications
  • Saving computation time by not having to retrain complex models