TimeDiff<T>

Models & Types · AiDotNet.Finance.Forecasting.Foundation

TimeDiff — Non-autoregressive Conditional Diffusion Models for Time Series Prediction.

Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → TimeSeriesFoundationModelBase<T> → TimeDiff<T>

Implements: IGeneratedParameterRegistrar<T>

For Beginners

TimeDiff improves diffusion-based forecasting with two clever tricks. During training, it mixes future values into the input (future-mixup) to help the model learn what comes next. During prediction, it uses an initial rough forecast to guide the diffusion process, producing all future values at once rather than one at a time, which is both faster and more consistent.

How It Works

TimeDiff extends DDPM with future-mixup training augmentation and autoregressive initialization at inference for high-quality non-autoregressive time series forecasting.

Reference: Shen & Kwok, “Non-autoregressive Conditional Diffusion Models for Time Series Prediction”, ICML 2023.

Example

// Create a TimeDiff non-autoregressive conditional diffusion model
// Uses future-mixup training and autoregressive initialization for consistent forecasts
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression,
    inputHeight: 512, inputWidth: 1, inputDepth: 1, outputSize: 24);
            
// Training mode with future-mixup augmentation
var model = new TimeDiff<double>(architecture);
            
// ONNX inference mode with pre-trained model
var onnxModel = new TimeDiff<double>(architecture, "timediff.onnx");

Constructors

Constructor Summary
TimeDiff(NeuralNetworkArchitecture<T> architecture, TimeDiffOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction)
TimeDiff(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, TimeDiffOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction)

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()
ModelMetadata<T> GetModelMetadata()
Tensor<T> ApplyInstanceNormalization(Tensor<T> input)
Tensor<T> AutoregressiveForecast(Tensor<T> input, int steps)
Tensor<T> ForwardForTraining(Tensor<T> input) Tape-aware forward over the denoiser graph, at the last diffusion step.