GraphAttentionLayerCore<T>
Models & Types · AiDotNet.Finance.Portfolio
The graph attention computation used by GraphAttentionPortfolio
(Korangi, Mues and Bravo, arXiv:2407.15532, following Velickovic et al.):
a(u,v) = softmax_v( LeakyReLU( a^T [W x_u || W x_v] ) ), aggregated over neighbours and
CONCATENATED across heads.
For Beginners
Each company looks only at the companies it is connected to in the network, decides how much attention to pay to each, and builds a summary from them.
How It Works
What separates this from ordinary dense attention is the MASK. Each node attends only over its graph neighbourhood, and the softmax is normalized within that neighbourhood — so the sparsity that TMFG filtering produced is what the attention actually operates on. Attending over all pairs would discard the filtered graph entirely and reduce the model to a plain transformer over assets.
Heads are CONCATENATED, not averaged, following the paper’s || operator. Averaging would
collapse the heads into a single representation of the same width and lose the distinct relational
views the heads learn.
Constructors
| Constructor | Summary |
|---|---|
GraphAttentionLayerCore(double slope) |
Creates the attention core. |
Properties
| Property | Summary |
|---|---|
double Slope { get; } |
Gets the LeakyReLU negative slope. |
Methods
| Method | Summary |
|---|---|
Tensor<T> Aggregate(Tensor<T> coefficients, Tensor<T> projected) |
Aggregates neighbour features under the attention coefficients: h_u = sum_v alpha_uv * (W x_v), then applies ReLU. |
Tensor<T> AttentionCoefficients(Tensor<T> projected, Vector<T> attentionVector, Tensor<T> adjacency) |
Attention coefficients over a masked graph, one row per node, normalized within each neighbourhood. |
Tensor<T> ConcatenateHeads(IReadOnlyList<Tensor<T>> headOutputs) |
Concatenates per-head outputs along the feature axis, as the paper’s || operator does. |
double LeakyReLU(double x) |
LeakyReLU. |
Fields
| Field | Summary |
|---|---|
double LeakyReLUSlope |
The paper’s LeakyReLU negative slope. |