GraphWaveNet<T>
Models & Types · AiDotNet.Finance.Graph
GraphWaveNet (Graph WaveNet) for deep spatial-temporal graph modeling.
Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → GraphWaveNet<T>
For Beginners
GraphWaveNet achieves top performance on traffic forecasting by combining:
The Key Insight: Traditional methods either use a fixed graph structure OR learn it separately from forecasting. GraphWaveNet jointly learns the graph structure AND the forecasting model, allowing them to inform each other during training.
What Problems Does GraphWaveNet Solve?
- Traffic speed/flow prediction on road networks
- Air quality forecasting across sensor networks
- Electricity demand prediction across power grids
- Any spatial-temporal forecasting with underlying graph structure
How GraphWaveNet Works:
- Adaptive Graph: Learns A = softmax(ReLU(E1 * E2^T)) from node embeddings
- Diffusion Conv: H’ = sum_k(P_f^k * H * W_k + P_b^k * H * V_k) for bidirectional propagation
- Gated TCN: tanh(conv_f) ⊙ sigmoid(conv_g) with exponentially increasing dilation
- Skip Connections: Sum outputs from all layers for multi-scale features
GraphWaveNet Architecture:
- Node Embeddings E1, E2: Learnable [num_nodes, embedding_dim] matrices
- Diffusion Convolution: Forward (A) and backward (A^T) random walk diffusion
- Gated TCN: Filter-Gate mechanism with dilated causal convolutions
- Skip Connections: Residual learning + skip from each layer to output
- Output: ReLU + Linear projection to forecast dimension
Key Benefits:
- Learns graph structure without prior knowledge
- Captures complex spatial dependencies via bidirectional diffusion
- Efficient training via parallel dilated convolutions
- State-of-the-art on METR-LA and PEMS-BAY traffic datasets
How It Works
GraphWaveNet combines adaptive graph learning with WaveNet-style dilated causal convolutions for state-of-the-art traffic and time series forecasting.
Reference: Wu et al., “Graph WaveNet for Deep Spatial-Temporal Graph Modeling”, IJCAI 2019.
https://arxiv.org/abs/1906.00121
Example
// Define architecture for adaptive graph traffic forecasting (207 sensors, 12-step horizon)
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.Regression,
inputHeight: 12, inputWidth: 207, inputDepth: 2, outputSize: 12);
// Training mode: learns graph structure adaptively via node embeddings
var model = new GraphWaveNet<double>(architecture);
// ONNX inference mode: load pre-trained Graph WaveNet model
var onnxModel = new GraphWaveNet<double>(architecture, "graphwavenet.onnx");
Constructors
| Constructor | Summary |
|---|---|
GraphWaveNet(NeuralNetworkArchitecture<T> architecture, GraphWaveNetOptions<T> options, Tensor<T> predefinedAdjacency, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Initializes a new instance of the GraphWaveNet model in native mode for training. |
GraphWaveNet(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, GraphWaveNetOptions<T> options, Tensor<T> predefinedAdjacency) |
Initializes a new instance of the GraphWaveNet model in ONNX mode for inference. |
Properties
| Property | Summary |
|---|---|
Tensor<T> LearnedAdjacency { get; } |
Gets the learned adaptive adjacency matrix. |
bool IsChannelIndependent { get; } |
|
bool SupportsTraining { get; } |
Gets whether the model supports training. |
bool UseAdaptiveGraph { get; } |
Gets whether adaptive graph learning is enabled. |
bool UseNativeMode { get; } |
|
int DiffusionSteps { get; } |
Gets the number of diffusion steps (K). |
int ForecastHorizon { get; } |
Gets the forecast horizon. |
int NumBlocks { get; } |
Gets the number of WaveNet blocks. |
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; } |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> Evaluate(Tensor<T> predictions, Tensor<T> actuals) |
Evaluates forecast quality. |
Dictionary<string, T> GetFinancialMetrics() |
Gets financial metrics. |
ModelMetadata<T> GetModelMetadata() |
Gets model metadata. |
Tensor<T> ApplyInstanceNormalization(Tensor<T> input) |
Applies instance normalization (identity for GraphWaveNet). |
Tensor<T> AutoregressiveForecast(Tensor<T> input, int steps) |
Performs autoregressive forecasting. |
Tensor<T> Forward(Tensor<T> input) |
Performs the forward pass. |
ValueTuple<Tensor<T>, Tensor<T>, Tensor<T>> ForecastWithIntervals(Tensor<T> input, double confidenceLevel) |
Generates forecasts with prediction intervals. |