DeepAR<T>
Models & Types · AiDotNet.Finance.Forecasting.Neural
DeepAR probabilistic autoregressive forecasting model using LSTM networks.
Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → DeepAR<T>
For Beginners
DeepAR is special because it doesn’t just predict a single value - it predicts a probability distribution. This means you get:
- A most likely value (the median of simulated futures)
- A measure of confidence (the spread of those futures)
- The ability to generate prediction intervals (e.g., 95% confidence bounds)
Key features:
- Autoregressive: Each prediction depends on previous predictions
- Probabilistic: Outputs full distributions, not just point forecasts
- Multi-series: Can learn patterns across many related time series
- Covariates: Can include additional features like holidays or promotions
How It Works
DeepAR is a probabilistic forecasting model that produces forecast distributions rather than point predictions. It uses autoregressive recurrent neural networks to learn temporal patterns and outputs distribution parameters (e.g., mean and standard deviation for Gaussian).
Reference: Salinas et al., “DeepAR: Probabilistic Forecasting with Autoregressive
Recurrent Networks”, International Journal of Forecasting 2020.
https://arxiv.org/abs/1704.04110
The network is the paper’s (DeepARNetwork, shared with
DeepARModel and checked against a PyTorch transcription). Each input column is a
series; with several, a learned item embedding tells them apart (§3.4). Training maximizes the likelihood of the
whole window, input then target (§3.2); forecasts are medians or quantiles of ancestral sample paths.
Example
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.Regression,
inputSize: 1, outputSize: 1); // one series; [batch, LookbackWindow, 1] in, [batch, ForecastHorizon, 1] out
var model = new DeepAR<double>(architecture);
var onnxModel = new DeepAR<double>(architecture, "deepar.onnx");
Constructors
| Constructor | Summary |
|---|---|
DeepAR() |
Creates a DeepAR with the paper’s defaults for a single series. |
DeepAR(NeuralNetworkArchitecture<T> architecture, DeepAROptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Creates a trainable DeepAR. |
DeepAR(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, DeepAROptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Creates a DeepAR that runs a pre-trained ONNX model. |
Properties
| Property | Summary |
|---|---|
bool IsChannelIndependent { get; } |
Each input column is its own series: DeepAR is one global model over many series. |
bool SupportsTraining { get; } |
|
int PatchSize { get; } |
|
int Stride { get; } |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> Evaluate(Tensor<T> predictions, Tensor<T> actuals) |
|
Dictionary<string, T> GetFinancialMetrics() |
|
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input) |
|
ModelMetadata<T> GetModelMetadata() |
|
Tensor<T> ApplyInstanceNormalization(Tensor<T> input) |
|
Tensor<T> AutoregressiveForecast(Tensor<T> input, int steps) |