Skip to content

Aggregation Layers

The k3_node.layers.aggr module provides 26 basic, statistical, scaled, and neural aggregation operators for neighborhood messaging and graph readout.


Aggregation Base Class

k3_node.layers.aggr.Aggregation

Bases: Layer

An abstract base class for implementing custom aggregations.

reduce(x, index=None, ptr=None, dim_size=None, dim=-2, reduce='sum')

Reduces features along groups specified by index or ptr.

reset_parameters()

Resets all learnable parameters of the module.


Basic Aggregations

SumAggregation

k3_node.layers.aggr.SumAggregation

Bases: Aggregation

An aggregation operator that sums up features across a set of elements.

MeanAggregation

k3_node.layers.aggr.MeanAggregation

Bases: Aggregation

An aggregation operator that averages features across a set of elements.

MaxAggregation

k3_node.layers.aggr.MaxAggregation

Bases: Aggregation

An aggregation operator that takes the feature-wise maximum across a set of elements.

MinAggregation

k3_node.layers.aggr.MinAggregation

Bases: Aggregation

An aggregation operator that takes the feature-wise minimum across a set of elements.

MulAggregation

k3_node.layers.aggr.MulAggregation

Bases: Aggregation

An aggregation operator that multiplies features across a set of elements.


Statistical & Scaled Aggregations

SoftmaxAggregation

k3_node.layers.aggr.SoftmaxAggregation

Bases: Aggregation

The softmax aggregation operator based on a temperature term.

PowerMeanAggregation

k3_node.layers.aggr.PowerMeanAggregation

Bases: Aggregation

The powermean aggregation operator based on a power term.

StdAggregation

k3_node.layers.aggr.StdAggregation

Bases: Aggregation

An aggregation operator that takes the feature-wise standard deviation across a set of elements.

VarAggregation

k3_node.layers.aggr.VarAggregation

Bases: Aggregation

An aggregation operator that takes the feature-wise variance across a set of elements.

MedianAggregation

k3_node.layers.aggr.MedianAggregation

Bases: QuantileAggregation

An aggregation operator that returns the feature-wise median of a set.

QuantileAggregation

k3_node.layers.aggr.QuantileAggregation

Bases: Aggregation

An aggregation operator that returns the feature-wise :math:q-th quantile of a set :math:\mathcal{X}.

DegreeScalerAggregation

k3_node.layers.aggr.DegreeScalerAggregation

Bases: Aggregation

Combines one or more aggregators and transforms its output with one or more scalers as introduced in the "Principal Neighbourhood Aggregation for Graph Nets" <https://arxiv.org/abs/2004.05718>_ paper.


Neural & Multi-Aggregations

MultiAggregation

k3_node.layers.aggr.MultiAggregation

Bases: Aggregation

Performs aggregations with one or more aggregators and combines aggregated results, as described in the "Principal Neighbourhood Aggregation for Graph Nets" <https://arxiv.org/abs/2004.05718> and "Adaptive Filters and Aggregator Fusion for Efficient Graph Convolutions" <https://arxiv.org/abs/2104.01481> papers.

AttentionalAggregation

k3_node.layers.aggr.AttentionalAggregation

Bases: Aggregation

The soft attention aggregation layer from the "Graph Matching Networks for Learning the Similarity of Graph Structured Objects" <https://arxiv.org/abs/1904.12787>_ paper.

Set2Set

k3_node.layers.aggr.Set2Set

Bases: Aggregation

The Set2Set aggregation operator based on iterative content-based attention, as described in the "Order Matters: Sequence to sequence for Sets" <https://arxiv.org/abs/1511.06391>_ paper.

DeepSetsAggregation

k3_node.layers.aggr.DeepSetsAggregation

Bases: Aggregation

Performs Deep Sets aggregation in which the elements to aggregate are first transformed by a Multi-Layer Perceptron (MLP) :math:\phi_{\mathbf{\Theta}}, summed, and then transformed by another MLP :math:\rho_{\mathbf{\Theta}}.

MLPAggregation

k3_node.layers.aggr.MLPAggregation

Bases: Aggregation

Performs MLP aggregation in which the elements to aggregate are flattened into a single vectorial representation, and are then processed by a Multi-Layer Perceptron (MLP).

LSTMAggregation

k3_node.layers.aggr.LSTMAggregation

Bases: Aggregation

Performs LSTM-style aggregation in which the elements to aggregate are interpreted as a sequence, as described in the "Inductive Representation Learning on Large Graphs" <https://arxiv.org/abs/1706.02216>_ paper.

GRUAggregation

k3_node.layers.aggr.GRUAggregation

Bases: Aggregation

Performs GRU aggregation in which the elements to aggregate are interpreted as a sequence, as described in the "Graph Neural Networks with Adaptive Readouts" <https://arxiv.org/abs/2211.04952>_ paper.

SetTransformerAggregation

k3_node.layers.aggr.SetTransformerAggregation

Bases: Aggregation

Performs "Set Transformer" aggregation in which the elements to aggregate are processed by multi-head attention blocks, as described in the "Graph Neural Networks with Adaptive Readouts" <https://arxiv.org/abs/2211.04952>_ paper.

GraphMultisetTransformer

k3_node.layers.aggr.GraphMultisetTransformer

Bases: Aggregation

The Graph Multiset Transformer pooling operator from the "Accurate Learning of Graph Representations with Graph Multiset Pooling" <https://arxiv.org/abs/2102.11533>_ paper.

SortAggregation

k3_node.layers.aggr.SortAggregation

Bases: Aggregation

The pooling operator from the "An End-to-End Deep Learning Architecture for Graph Classification" <https://www.cse.wustl.edu/~muhan/papers/AAAI_2018_DGCNN.pdf>_ paper, where node features are sorted in descending order based on their last feature channel. The first :math:k nodes form the output of the layer.

VariancePreservingAggregation

k3_node.layers.aggr.VariancePreservingAggregation

Bases: Aggregation

Performs the Variance Preserving Aggregation (VPA) from the "GNN-VPA: A Variance-Preserving Aggregation Strategy for Graph Neural Networks" <https://arxiv.org/abs/2403.04747>_ paper.

PatchTransformerAggregation

k3_node.layers.aggr.PatchTransformerAggregation

Bases: Aggregation

Performs patch transformer aggregation in which the elements to aggregate are processed by multi-head attention blocks across patches.

LCMAggregation

k3_node.layers.aggr.LCMAggregation

Bases: Aggregation

The Learnable Commutative Monoid aggregation from the "Learnable Commutative Monoids for Graph Neural Networks" <https://arxiv.org/abs/2212.08541>_ paper.

EquilibriumAggregation

k3_node.layers.aggr.EquilibriumAggregation

Bases: Aggregation

The equilibrium aggregation layer from the "Equilibrium Aggregation: Encoding Sets via Optimization" <https://arxiv.org/abs/2202.12795>_ paper.

FusedAggregation

k3_node.layers.aggr.FusedAggregation

Bases: Aggregation

Helper class to fuse computation of multiple aggregations together.