PrincipalNeighbourhoodAggregationLayer<T>

Layers · AiDotNet.NeuralNetworks.Layers

Implements Principal Neighbourhood Aggregation (PNA) layer for powerful graph representation learning.

Inheritance: LayerBase<T> → PrincipalNeighbourhoodAggregationLayer<T>

Implements: IGraphConvolutionLayer<T>, IShapeContract

How It Works

Principal Neighbourhood Aggregation (PNA), introduced by Corso et al., addresses limitations of existing GNN architectures by using multiple aggregators and scalers. PNA combines:

  1. Multiple aggregation functions (mean, max, min, sum, std)
  2. Multiple scaling functions to normalize by degree
  3. Learnable combination of all aggregated features

The layer computes: h_i’ = MLP(COMBINE({SCALE(AGGREGATE({h_j : j in N(i)}))})) where AGGREGATE in {mean, max, min, sum, std}, SCALE in {identity, amplification, attenuation}, and COMBINE is a learned linear combination followed by MLP.

Production-Ready Features:

  • Fully vectorized operations using IEngine for GPU acceleration
  • BatchMatMul for efficient batched graph operations
  • Dual backward pass: BackwardManual() for efficiency, BackwardViaAutodiff() for accuracy
  • Full gradient computation through all aggregators and scalers
  • Complete GetParameters()/SetParameters() for model persistence

Constructors

Constructor Summary
PrincipalNeighbourhoodAggregationLayer(int inputFeatures, int outputFeatures, PNAAggregator[] aggregators, PNAScaler[] scalers, double avgDegree, IActivationFunction<T> activationFunction, IInitializationStrategy<T> initializationStrategy) Initializes a new instance of the PrincipalNeighbourhoodAggregationLayer 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).