TemporalGCN<T>

Models & Types · AiDotNet.Finance.Graph

TemporalGCN (Temporal Graph Convolutional Network) for time series forecasting on graph-structured data.

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

For Beginners

TemporalGCN learns two types of patterns simultaneously:

The Key Insight: Many time series exist on networks: traffic sensors on roads, users in social networks, weather stations across regions. TemporalGCN captures both HOW these entities are connected (spatial) and HOW they change over time (temporal).

What Problems Does TemporalGCN Solve?

  • Traffic flow prediction (sensors connected by roads)
  • Social network activity forecasting (users connected by friendships)
  • Epidemiological prediction (regions connected geographically)
  • Financial network analysis (assets connected by correlations)

How TemporalGCN Works:

  1. Graph Convolution: Aggregate information from neighboring nodes
  2. Temporal Recurrence: Process time sequences with GRU cells
  3. Interleaved Processing: Alternate between spatial and temporal layers
  4. Prediction: Output forecasts for all nodes simultaneously

TemporalGCN Architecture:

  • GCN Layers: Chebyshev spectral graph convolution for neighbor aggregation
  • GRU Layers: Gated recurrent units for temporal sequence modeling
  • Batch Normalization: Stabilizes training across layers
  • Residual Connections: Helps gradients flow through deep networks

Key Benefits:

  • Jointly learns spatial and temporal dependencies
  • Handles variable graph structures (nodes can have different numbers of neighbors)
  • Computationally efficient with Chebyshev polynomial approximation
  • Works with both static and dynamic graphs

How It Works

TemporalGCN combines graph convolutional networks with recurrent neural networks (GRU/LSTM) to capture both spatial dependencies and temporal dynamics in graph-structured time series.

Reference: Zhao et al., “T-GCN: A Temporal Graph Convolutional Network for Traffic Prediction”, 2019. https://arxiv.org/abs/1811.05320

Example

// Define architecture for temporal graph-based traffic prediction (156 sensors, 12-step horizon)
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression,
    inputHeight: 12, inputWidth: 156, inputDepth: 1, outputSize: 12);
            
// Training mode: combines GCN spatial aggregation with GRU temporal modeling
var model = new TemporalGCN<double>(architecture);
            
// ONNX inference mode: load pre-trained T-GCN model
var onnxModel = new TemporalGCN<double>(architecture, "tgcn_traffic.onnx");

Constructors

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

Properties

Property Summary
bool IsChannelIndependent { get; }
bool SupportsTraining { get; } Gets whether the model supports training (native mode only).
bool UseNativeMode { get; }
int ChebyshevOrder { get; } Gets the Chebyshev polynomial order for graph convolution.
int ForecastHorizon { get; } Gets the forecast horizon.
int NumFeatures { get; }
int NumNodes { get; } Gets the number of nodes in the graph.
int NumSamples { get; } Gets the number of samples for uncertainty estimation.
int PatchSize { get; }
int PredictionHorizon { get; }
int SequenceLength { get; }
int Stride { get; }
string TemporalCellType { get; } Gets the type of temporal recurrent cell used.

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 TemporalGCN model.
Tensor<T> ApplyInstanceNormalization(Tensor<T> input) Applies instance normalization (identity for TemporalGCN).
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.