DirectionalGraphLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
Implements Directional Graph Networks for directed graph processing with separate in/out aggregations.
Inheritance: LayerBase<T> → DirectionalGraphLayer<T>
Implements: IGraphConvolutionLayer<T>, IShapeContract
For Beginners
This layer understands that graph connections can have direction.
Think of different types of directed networks:
Twitter/Social Media:
- You follow someone (outgoing edge)
- Someone follows you (incoming edge)
- These are NOT the same! Celebrities have many incoming, fewer outgoing
Citation Networks:
- Papers you cite (outgoing): Shows your influences
- Papers citing you (incoming): Shows your impact
- Direction matters for understanding importance
Web Pages:
- Links you have (outgoing): What you reference
- Links to you (incoming/backlinks): Your authority
- Google PageRank uses this directionality
Transaction Networks:
- Money sent (outgoing): Your purchases
- Money received (incoming): Your sales
- Different patterns for buyers vs sellers
Why separate in/out aggregation?
- Asymmetric roles: Being cited vs citing have different meanings
- Different patterns: Incoming and outgoing patterns can be very different
- Better expressiveness: Captures more information than treating edges as undirected
The layer learns separate transformations for incoming and outgoing neighbors, then combines them to update each node’s representation.
How It Works
Directional Graph Networks (DGN) explicitly model the directionality of edges in directed graphs. Unlike standard GNNs that often ignore edge direction or treat graphs as undirected, DGNs maintain separate aggregations for incoming and outgoing edges, capturing asymmetric relationships.
The layer computes separate representations for in-neighbors and out-neighbors:
- h_in = AGGREGATE_IN({h_j : j → i})
- h_out = AGGREGATE_OUT({h_j : i → j})
- h_i’ = UPDATE(h_i, h_in, h_out)
This allows the network to learn different patterns for sources and targets of edges.
Constructors
| Constructor | Summary |
|---|---|
DirectionalGraphLayer(int inputFeatures, int outputFeatures, bool useGating, IActivationFunction<T> activationFunction) |
Initializes a new instance of the DirectionalGraphLayer class. |
Properties
| Property | Summary |
|---|---|
bool SupportsTraining { get; } |
|
int InputFeatures { get; } |
|
int OutputFeatures { get; } |
Methods
| Method | Summary |
|---|---|
Dictionary<string, string> GetParameterRoles() |
Returns parameter roles for per-role optimizer configuration (e.g., weight decay exemption for biases). |
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
|
IReadOnlyList<Tensor<T>> GetTrainableParameters() |
Returns all trainable parameter tensors marked with [TrainableParameter]. |
IReadOnlyList<ValueTuple<string, Tensor<T>>> GetRegisteredBuffers() |
|
Tensor<T> GetAdjacencyMatrix() |
|
void ClearGradients() |
|
void ResetState() |
|
void SetAdjacencyMatrix(Tensor<T> adjacencyMatrix) |
|
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) |
Replaces trainable parameter tensors (e.g., with ParameterBuffer views). |
void UpdateParameters(T learningRate) |
|
void ZeroGrad() |
Clears all gradient fields discovered by convention ({paramName}Gradient). |