RelationalGCN<T>
Models & Types · AiDotNet.Finance.Graph
RelationalGCN (Relational Graph Convolutional Network) for multi-relational graph learning.
Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → RelationalGCN<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
RelationalGCN is designed for knowledge graphs:
The Key Insight: Standard GCN treats all edges equally, but in knowledge graphs and financial networks, different types of relationships matter differently. A “supplies-to” relationship is fundamentally different from a “competes-with” relationship. R-GCN learns separate transformations for each relation type.
What Problems Does RelationalGCN Solve?
- Entity classification in knowledge graphs (company type, sector classification)
- Link prediction in multi-relational networks (predicting missing relationships)
- Financial network analysis with multiple relationship types
- Supply chain modeling with different connection types
How RelationalGCN Works:
- Relation-Specific Weights: Learns different weights W_r for each relation type r
- Basis Decomposition: W_r = sum_b (a_rb * B_b) shares parameters via learned bases
- Block Decomposition: Alternative using block-diagonal weight matrices
- Self-Connections: Special weight W_0 for a node’s own features
RelationalGCN Architecture:
- Message Passing: h_i^(l+1) = sigma(sum_r sum_j A_r[i,j] * h_j^(l) * W_r + h_i^(l) * W_0)
- Basis Decomposition: W_r = sum_b (a_rb * B_b) with shared bases B
- Block Decomposition: W_r = diag(W_r1, …, W_rB) with block-diagonal structure
Key Benefits:
- Handles heterogeneous graphs with multiple edge types
- Parameter efficient through basis or block decomposition
- Captures relation-specific patterns in the data
- Effective for both entity classification and link prediction
How It Works
RelationalGCN extends Graph Convolutional Networks to handle multi-relational data where different types of edges (relations) exist between nodes, making it ideal for knowledge graphs and heterogeneous networks.
Reference: Schlichtkrull et al., “Modeling Relational Data with Graph Convolutional Networks”, ESWC 2018.
https://arxiv.org/abs/1703.06103
Example
// Define architecture for multi-relational knowledge graph node classification (50 entities, 5 classes)
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.MultiClassClassification,
inputHeight: 50, inputWidth: 16, inputDepth: 1, outputSize: 5);
// Training mode: learns relation-specific transformations with basis decomposition
var model = new RelationalGCN<double>(architecture);
// ONNX inference mode: load pre-trained Relational GCN model
var onnxModel = new RelationalGCN<double>(architecture, "rgcn_knowledge_graph.onnx");
Constructors
| Constructor | Summary |
|---|---|
RelationalGCN(NeuralNetworkArchitecture<T> architecture, RelationalGCNOptions<T> options, Tensor<T> relationAdjacencies, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) |
Initializes a new instance of the RelationalGCN model in native mode for training. |
RelationalGCN(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, RelationalGCNOptions<T> options, Tensor<T> relationAdjacencies) |
Initializes a new instance of the RelationalGCN 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 UseBasisDecomposition { get; } |
Gets whether basis decomposition is used. |
bool UseNativeMode { get; } |
|
int ForecastHorizon { get; } |
Gets the forecast horizon. |
int NumBases { get; } |
Gets the number of basis matrices for basis decomposition. |
int NumFeatures { get; } |
|
int NumNodes { get; } |
Gets the number of nodes (entities) in the knowledge graph. |
int NumRelations { get; } |
Gets the number of relation types. |
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 RelationalGCN model. |
Tensor<T> ApplyInstanceNormalization(Tensor<T> input) |
Applies instance normalization (identity for RelationalGCN). |
Tensor<T> AutoregressiveForecast(Tensor<T> input, int steps) |
Performs autoregressive forecasting for extended horizons. |
Tensor<T> Forward(Tensor<T> input) |
Performs the forward pass: per-node encoder, R-GCN layers, per-node head. |
ValueTuple<Tensor<T>, Tensor<T>, Tensor<T>> ForecastWithIntervals(Tensor<T> input, double confidenceLevel) |
Generates forecasts with prediction intervals. |
void SetTrainingMode(bool isTraining) |