MGTSD<T>
Models & Types · AiDotNet.Finance.Forecasting.Foundation
MG-TSD — Multi-Granularity Time Series Diffusion Model with Guided Learning.
Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → TimeSeriesFoundationModelBase<T> → MGTSD<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
MG-TSD forecasts at multiple zoom levels simultaneously. It first makes a rough forecast (like predicting monthly trends), then uses that to guide a more detailed forecast (like daily values). This coarse-to-fine approach is similar to how an artist first sketches the broad outlines before adding fine details, resulting in more coherent and accurate probabilistic predictions.
How It Works
MG-TSD captures temporal patterns at multiple granularities using a coarse-to-fine guidance mechanism where predictions at coarser levels guide fine-grained diffusion.
Reference: Fan et al., “MG-TSD: Multi-Granularity Time Series Diffusion Models with Guided Learning Process”, ICLR 2024.
Example
// Create an MG-TSD multi-granularity time series diffusion model
// Coarse-to-fine guidance: rough forecasts at monthly level guide daily predictions
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.Regression,
inputHeight: 512, inputWidth: 1, inputDepth: 1, outputSize: 24);
// Training mode with multi-granularity guided diffusion
var model = new MGTSD<double>(architecture);
// ONNX inference mode with pre-trained model
var onnxModel = new MGTSD<double>(architecture, "mgtsd.onnx");
Constructors
| Constructor | Summary |
|---|---|
MGTSD(NeuralNetworkArchitecture<T> architecture, MGTSDOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
|
MGTSD(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, MGTSDOptions<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() |
|
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input) |
Override the base class’s naive linear-chain Layers walk because MGTSD’s Layers list isn’t a single pipeline — it’s [inputProjection, denoisingLayers…, outputProjection] where each stage takes a different input shape (contextLength → hi… |
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 training forward: builds x_t from the stored (target, noise, timestep) and runs the denoising network as an x0-predictor over the same [x_t | cond | guidance | t] pack used at inference. |