DCRNN<T>
Models & Types · AiDotNet.Finance.Graph
DCRNN (Diffusion Convolutional Recurrent Neural Network) for spatial-temporal forecasting.
Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → DCRNN<T>
For Beginners
DCRNN was a breakthrough model for traffic prediction that introduced two key innovations:
The Key Insight: Traffic flow can be modeled as a diffusion process - congestion spreads through a road network similar to how heat diffuses through a material. DCRNN captures this with diffusion convolution while using an encoder-decoder architecture for multi-step forecasting.
What Makes DCRNN Special:
- Diffusion Convolution: Models spatial dependencies as bidirectional random walks on the graph
- DCGRU Cells: GRU cells where matrix multiplications are replaced with diffusion convolution
- Encoder-Decoder: Seq2seq architecture for multi-step prediction
- Scheduled Sampling: Gradually transitions from teacher forcing to autoregressive during training
Mathematical Foundation: Diffusion convolution: X_star = sum_k (theta_k * (D_O^(-1)*W)^k * X + theta’_k * (D_I^(-1)*W^T)^k * X) where D_O, D_I are out/in-degree matrices and W is the adjacency matrix.
Architecture:
- Encoder: Stacked DCGRU layers process input sequence
- Final encoder state becomes initial decoder state
- Decoder: Stacked DCGRU layers generate output autoregressively
- Output: Linear projection to forecast dimension
Key Benefits:
- Captures bidirectional spatial dependencies (upstream and downstream effects)
- Multi-step prediction without error accumulation from teacher forcing
- Effective on large-scale traffic networks
How It Works
DCRNN combines diffusion convolution with sequence-to-sequence architecture for traffic forecasting on road networks and other spatial-temporal prediction tasks.
Reference: Li et al., “Diffusion Convolutional Recurrent Neural Network: Data-Driven Traffic Forecasting”, ICLR 2018.
https://arxiv.org/abs/1707.01926
Example
// Define architecture for spatial-temporal 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: diffusion convolutional recurrent network with graph structure
var model = new DCRNN<double>(architecture);
// ONNX inference mode: load pre-trained DCRNN model
var onnxModel = new DCRNN<double>(architecture, "dcrnn_traffic.onnx");
Constructors
| Constructor | Summary |
|---|---|
DCRNN(NeuralNetworkArchitecture<T> architecture, DCRNNOptions<T> options, double[] adjacencyMatrix, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Initializes a new instance of DCRNN in native training/inference mode. |
DCRNN(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, DCRNNOptions<T> options, double[] adjacencyMatrix, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Initializes a new instance of DCRNN in ONNX inference mode. |
Properties
| Property | Summary |
|---|---|
bool IsChannelIndependent { get; } |
|
bool SupportsTraining { get; } |
Gets whether the model supports training. |
bool UseNativeMode { get; } |
|
int DiffusionSteps { get; } |
Gets the number of diffusion steps. |
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; } |
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. |
Dictionary<string, Tensor<T>> GetNamedLayerActivations(Tensor<T> input) |
|
ModelInputShapeConstraint GetInputShapeConstraint() |
The input DCRNN reads: [numNodes, sequenceLength, featuresPerNode]. |
ModelMetadata<T> GetModelMetadata() |
Gets metadata about the DCRNN model. |
Tensor<T> ApplyInstanceNormalization(Tensor<T> input) |
Applies instance normalization (identity for DCRNN). |
Tensor<T> AutoregressiveForecast(Tensor<T> input, int steps) |
Performs autoregressive forecasting for extended horizons. |
Tensor<T> Forward(Tensor<T> input) |
Performs forward pass through all layers. |
Tensor<T> ForwardForTraining(Tensor<T> input) |
Runs tape training through the same last-step readout and graph-diffusion path used by native forecasting. |
ValueTuple<Tensor<T>, Tensor<T>, Tensor<T>> ForecastWithIntervals(Tensor<T> input, double confidenceLevel) |
Generates forecasts with prediction intervals. |