TimeGrad<T>
Models & Types · AiDotNet.Finance.Forecasting.Foundation
TimeGrad — Autoregressive Denoising Diffusion Model for Time Series Forecasting.
Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → TimeSeriesFoundationModelBase<T> → TimeGrad<T>
For Beginners
TimeGrad predicts time series step by step, where at each step it uses a diffusion process to generate the next value. Think of it as a storyteller who writes one sentence at a time, but for each sentence uses a careful drafting process to get it right. By generating many possible futures, TimeGrad provides not just a single forecast but a range of scenarios with probabilities, helping you understand how confident the prediction is.
How It Works
TimeGrad combines an autoregressive RNN with a conditional diffusion process for probabilistic multi-step forecasting. It generates multiple forecast samples to provide well-calibrated uncertainty estimates.
Reference: Rasul et al., “Autoregressive Denoising Diffusion Models for Multivariate Probabilistic Time Series Forecasting”, ICML 2021.
Example
// Create a TimeGrad autoregressive diffusion model for probabilistic forecasting
// Combines RNN with conditional diffusion for step-by-step forecast generation
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.Regression,
inputHeight: 512, inputWidth: 1, inputDepth: 1, outputSize: 24);
// Training mode with RNN encoder and denoising diffusion decoder
var model = new TimeGrad<double>(architecture);
// ONNX inference mode with pre-trained model
var onnxModel = new TimeGrad<double>(architecture, "timegrad.onnx");
Constructors
| Constructor | Summary |
|---|---|
TimeGrad(NeuralNetworkArchitecture<T> architecture, TimeGradOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Creates a TimeGrad model in native mode for training. |
TimeGrad(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, TimeGradOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Creates a TimeGrad model using a pretrained ONNX model. |
Properties
| Property | Summary |
|---|---|
FoundationModelSize ModelSize { get; } |
|
bool IsChannelIndependent { get; } |
|
bool SupportsTraining { get; } |
|
bool UseNativeMode { get; } |
|
int MaxContextLength { get; } |
|
int MaxPredictionHorizon { get; } |
|
int NumFeatures { get; } |
|
int PatchSize { get; } |
|
int PredictionHorizon { get; } |
|
int SequenceLength { 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) |
|
Tensor<T> ForwardForTraining(Tensor<T> input) |
epsilon_theta(x_k, h_{t-1}, k) for every future step of a pair from PrepareTrainingPair, as [B, ForecastHorizon]: the RNN reads the teacher-forced sequence and its state before each future step conditions the denoiser. |