MTGNN<T>

Models & Types · AiDotNet.Finance.Graph

MTGNN (Multivariate Time-series Graph Neural Network) for automatic graph learning and forecasting.

Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → MTGNN<T>

For Beginners

MTGNN is unique because it LEARNS how variables are connected:

The Key Insight: Unlike other graph models that require you to define the graph upfront, MTGNN automatically discovers which time series influence each other. It learns node embeddings whose similarities form an adaptive graph.

What Problems Does MTGNN Solve?

  • Traffic prediction when road relationships are complex or unknown
  • Multivariate financial forecasting with hidden correlations
  • Sensor networks where dependencies change over time
  • Any multivariate series where inter-variable relationships are important but unknown

How MTGNN Works:

  1. Graph Learning: Learns node embeddings E1, E2; computes A = softmax(E1 * E2^T)
  2. Mix-hop Propagation: Aggregates 1-hop, 2-hop, … K-hop neighbors
  3. Dilated Inception: Captures multi-scale temporal patterns via dilated convolutions
  4. Joint Learning: Graph structure and predictions are optimized together

MTGNN Architecture:

  • Node Embeddings: Two learnable embedding matrices E1, E2
  • Adaptive Adjacency: A = softmax(ReLU(E1 * E2^T - E2 * E1^T))
  • Mix-hop Propagation: H_out = concat(H, AH, A^2H, …, A^K*H) * W
  • Dilated Inception: Parallel convolutions with exponentially increasing dilation
  • Skip Connections: Gated residual connections between layers

Key Benefits:

  • No need to predefine graph structure
  • Discovers hidden variable relationships automatically
  • Captures both unidirectional and bidirectional dependencies
  • Scales to hundreds of variables with subgraph sampling

How It Works

MTGNN automatically discovers the graph structure from data while performing spatio-temporal forecasting, eliminating the need for a predefined adjacency matrix.

Reference: Wu et al., “Connecting the Dots: Multivariate Time Series Forecasting with Graph Neural Networks”, KDD 2020. https://arxiv.org/abs/2005.11650

Example

// Define architecture for multivariate time series with auto-discovered graph (100 variables, 24-step forecast)
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression,
    inputHeight: 60, inputWidth: 100, inputDepth: 1, outputSize: 24);
            
// Training mode: automatically discovers inter-variable relationships
var model = new MTGNN<double>(architecture);
            
// ONNX inference mode: load pre-trained MTGNN model
var onnxModel = new MTGNN<double>(architecture, "mtgnn_forecast.onnx");

Constructors

Constructor Summary
MTGNN(NeuralNetworkArchitecture<T> architecture, MTGNNOptions<T> options, Tensor<T> predefinedAdjacency, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Initializes a new instance of the MTGNN model in native mode for training.
MTGNN(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, MTGNNOptions<T> options, Tensor<T> predefinedAdjacency) Initializes a new instance of the MTGNN model in ONNX mode for inference.

Properties

Property Summary
Tensor<T> LearnedAdjacency { get; } Gets the learned adaptive adjacency matrix (read-only copy).
bool IsChannelIndependent { get; }
bool SupportsTraining { get; } Gets whether the model supports training (native mode only).
bool UseNativeMode { get; }
int ForecastHorizon { get; } Gets the forecast horizon.
int MixHopDepth { get; } Gets the mix-hop propagation depth.
int NodeEmbeddingDim { get; } Gets the node embedding dimension.
int NumFeatures { get; }
int NumNodes { get; } Gets the number of nodes (variables/time series).
int NumSamples { get; } Gets the number of samples for uncertainty estimation.
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) Evaluates forecast quality against actual values.
Dictionary<string, T> GetFinancialMetrics() Gets financial-specific metrics.
ModelMetadata<T> GetModelMetadata() Gets metadata about the MTGNN model.
Tensor<T> ApplyInstanceNormalization(Tensor<T> input) Applies instance normalization (identity for MTGNN).
Tensor<T> AutoregressiveForecast(Tensor<T> input, int steps) Performs autoregressive forecasting for extended horizons.
Tensor<T> Forward(Tensor<T> input) Performs the forward pass through all layers.
ValueTuple<Tensor<T>, Tensor<T>, Tensor<T>> ForecastWithIntervals(Tensor<T> input, double confidenceLevel) Generates forecasts with prediction intervals.