VectorAutoRegressionModel<T>
Models & Types · AiDotNet.TimeSeries
Implements a Vector Autoregression (VAR) model for multivariate time series forecasting.
Inheritance: TimeSeriesModelBase<T> → VectorAutoRegressionModel<T>
Implements: IGeneratedParameterRegistrar<T>, IMultivariateForecastModel<T>
Known derived types: VARMAModel<T>
For Beginners
A VAR model helps you forecast multiple related time series at once, accounting for how they influence each other.
For example, if you’re analyzing economic data, a VAR model could simultaneously forecast:
- GDP growth
- Unemployment rate
- Inflation rate
While accounting for relationships like:
- How unemployment affects future GDP
- How GDP affects future inflation
- How each variable’s past values affect its own future
Think of it as a system that recognizes the interconnected nature of multiple time series and uses these connections to make better forecasts for all variables simultaneously.
How It Works
The Vector Autoregression (VAR) model is a multivariate extension of the univariate autoregressive model. It captures linear dependencies among multiple time series variables, where each variable is modeled as a function of past values of itself and past values of other variables in the system.
Example
using AiDotNet;
using AiDotNet.Data.Loaders;
using AiDotNet.TimeSeries;
using AiDotNet.Tensors.LinearAlgebra;
double[] series =
{
120, 135, 148, 160, 155, 170, 180, 195, 210, 198, 220, 235,
140, 155, 165, 178, 172, 190, 200, 215, 230, 218, 245, 260
};
var x = new Matrix<double>(series.Length, 1);
for (int i = 0; i < series.Length; i++) x[i, 0] = i;
var result = await new AiModelBuilder<double, Matrix<double>, Vector<double>>()
.ConfigureModel(new VectorAutoRegressionModel<double>())
.ConfigureDataLoader(DataLoaders.FromMatrixVector(x, new Vector<double>(series)))
.BuildAsync();
var forecast = result.Predict(new Matrix<double>(6, 1));
Console.WriteLine($"VectorAutoRegressionModel: forecast {forecast.Length} steps.");
Constructors
| Constructor | Summary |
|---|---|
VectorAutoRegressionModel() |
Initializes a new instance with default settings. |
VectorAutoRegressionModel(VARModelOptions<T> options) |
Initializes a new instance of the VectorAutoRegressionModel class with the specified options. |
Properties
| Property | Summary |
|---|---|
Matrix<T> Coefficients { get; } |
Gets the coefficient matrix of the VAR model. |
int VariableCount { get; } |
The number of interrelated series this model forecasts (the VAR output dimension). |
Methods
| Method | Summary |
|---|---|
Dictionary<string, Matrix<T>> ImpulseResponseAnalysis(int horizon) |
Analyzes the dynamic relationships between variables in the VAR system. |
Dictionary<string, T> EvaluateModel(Matrix<T> xTest, Vector<T> yTest) |
Evaluates the performance of the trained model on test data. |
Matrix<T> Forecast(Matrix<T> historyMatrix, int steps) |
Generates multi-step forecasts for all variables in the VAR system. |
Matrix<T> ForecastMultivariate(Matrix<T> history, int horizon) |
Forecasts horizon steps for all variables from the multivariate history (the unified facade-forecast entry point). |
ModelMetadata<T> GetModelMetadata() |
Gets metadata about the VAR model. |
T PredictSingle(Vector<T> input) |
Predicts a single value from one of the variables in the VAR system. |
Vector<T> Predict(Matrix<T> input) |
Generates forecasts using the trained VAR model. |
void Reset() |
Resets the VAR model to its untrained state. |