DeepARModel<T>
Models & Types · AiDotNet.TimeSeries
Implements DeepAR: Probabilistic Forecasting with Autoregressive Recurrent Networks.
Inheritance: TimeSeriesModelBase<T> → DeepARModel<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
DeepAR is like a weather forecaster that doesn’t just say “it will be 70 degrees tomorrow” but rather “there’s a 50% chance it’ll be between 65-75 degrees.” It uses an LSTM (a recurrent neural network good at remembering patterns over time) and predicts a probability distribution (a mean and a spread) for each future step.
How It Works
DeepAR is a probabilistic forecasting model that produces full probability distributions rather than point estimates. Key features include:
Original paper: Salinas et al., “DeepAR: Probabilistic Forecasting with Autoregressive Recurrent Networks” (2020).
The network is the paper’s (DeepARNetwork, shared with the Finance DeepAR and checked against a
PyTorch transcription): an LSTM over the previous value divided by the series scale ν and the covariates, whose top
state parametrizes the likelihood. Training maximizes the log-likelihood over whole windows of conditioning and
prediction range (§3.2); forecasts are medians and quantiles of ancestral sample paths (§2). The paper’s age
covariate is added when UseAgeFeature is set; its time-of-day and calendar
covariates need timestamps, which the time-series interface does not carry, so pass them as covariates.
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 DeepARModel<double>())
.ConfigureDataLoader(DataLoaders.FromMatrixVector(x, new Vector<double>(series)))
.BuildAsync();
var forecast = result.Predict(new Matrix<double>(6, 1));
Console.WriteLine($"DeepARModel: forecast {forecast.Length} steps.");
Constructors
| Constructor | Summary |
|---|---|
DeepARModel(DeepAROptions<T> options) |
Initializes a new instance of the DeepARModel class. |
Methods
| Method | Summary |
|---|---|
Dictionary<double, Vector<T>> ForecastWithCovariates(Vector<T> history, Matrix<T> historyCovariates, Matrix<T> futureCovariates, double[] quantiles) |
The requested quantiles of the ForecastHorizon steps after the history, given the covariates of the history [L, CovariateSize] and of the forecast steps [≥ ForecastHorizon, CovariateSize]. |
Dictionary<double, Vector<T>> ForecastWithQuantiles(Vector<T> history, double[] quantiles) |
The requested quantiles of the ForecastHorizon steps after the history, from NumSamples ancestral sample paths (the history is taken to end where the training series ends, which places the age feature). |
ModelMetadata<T> GetModelMetadata() |
|
T PredictNextWithCovariates(Vector<T> historyWindow, Matrix<T> historyCovariates) |
The median forecast of the value after the history window, given its covariates [L, CovariateSize]; the next step’s covariates are taken to equal the last row’s. |
T PredictSingle(Vector<T> input) |
The median forecast of the value after the given history (its last LookbackWindow values), taken to end where the training series ends. |
Vector<T> Predict(Matrix<T> input) |
Predicts the series: with as many rows as the training series, the median one-step forecast of each observation from the values before it; with one column (time steps), the medians of the next input.Rows steps after the training series, fro… |