SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Generalised  $f$ -Mean Aggregation for Graph Neural Networks
Ryan Kortvelesy, Steven Morad and Amanda Prorok
{rk627, sm2558, asp45}  $@$  cam.ac.uk
Graph Neural Network (GNN) architectures are defined by their implementations of update and aggregation modules. While many works focus on new ways to parametrisse the update modules, the aggregation modules receive comparatively little attention. Because it is difficult to parametrisse aggregation functions, currently most methods select a "standard aggregator" such as mean, sum, or max. While this selection is often made without any reasoning, it has been shown that the choice in aggregator has a significant impact on performance, and the best choice in aggregator is problem-dependent. Since aggregation is a lossy operation, it is crucial to select the most appropriate aggregator in order to minimise information loss. In this paper, we present GenAgg, a generalised aggregation operator, which parametrises a function space that includes all standard aggregators. In our experiments, we show that GenAgg is able to represent the standard aggregators with much higher accuracy than baseline methods. We also show that using GenAgg as a drop-in replacement for an existing aggregator in a GNN often leads to a significant boost in performance across various tasks.
Graph Neural Networks (GNNs) provide a powerful framework for operating over structured data. Taking advantage of relational inductive biases, they use local filters to learn functions that generalise over high-dimensional data. Given different graph structures, GNNs can represent many special cases, including CNNs (on grid graphs) [12], RNNs (on line graphs) [4], and Transformers (on fully connected graphs) [19]. All of these architectures can be subsumed under the Graph Networks framework, parametrised by update and aggregation modules [2]. Although the framework itself is general, the representational capacity is often constrained in practice through design choices, which create a human prior [21]. There are two primary reasons for introducing this human prior. First, there are no standard methods to parametrisse all of the modules—MLPs can be used as universal approximators in the update modules, but it is nontrivial to parametrisse the function space of aggregators. Consequently, most GNNs simply make a design choice for the aggregation functions, selecting mean, sum, or max [21].
Figure 1: A qualitative demonstration of the diversity of functions that can be represented by GenAgg. In these visualisations, GenAgg is plotted as a function of inputs  $x_0$  and  $x_1$  for different parametrisations  $\theta = \langle f, \alpha, \beta \rangle$  (see Equation (1)).
Second, constraints can boost performance in GNNs, either through invariances or a regularisation effect.
In this paper, we focus on the problem of parametrising the space of aggregation functions. The ultimate goal is to create an aggregation function which can represent the set of all desired aggregators while remaining as constrained as possible. In prior work, one approach is to introduce learnable parameters into functions that could parametrisse min, mean, and max, such as the Powermean and a variant of Softmax [8, 13, 20]. However, these approaches can only parametrisse a small set of aggregators, and they can introduce instability in the training process (see Section 4). On the opposite end of the spectrum, methods like Deep Sets [22] and LSTMAgg [9] are capable of universal approximation over set functions, but they are extremely complex, which leads to poor sample efficiency. These methods scale in complexity (i.e. number of parameters) with the dimensionality of the input, and lack some of the useful constraints that are shared among standard aggregators (see Section 4). Consequently, the complexity of these methods counteracts the benefits of simple GNN architectures.
Although existing approaches present some limitations, the theoretical advantages of a learnable aggregation module are evident. It has been shown that the choice of aggregation function not only has a significant impact on performance, but also is problem-specific [21]. Since there is no aggregator that can discriminate between all inputs [5], it is important to select an aggregator that preserves the relevant information. In this paper, we present a method that parametrises the function space, allowing GNNs to learn the most appropriate aggregator for each application.
- We introduce Generalised Aggregation (GenAgg), the first aggregation method based on the generalised  $f$ -mean. GenAgg is a learnable permutation-invariant aggregator which is provably capable (both theoretically and experimentally) of representing all "standard aggregators" (see Appendix C for proofs). The representations learned by GenAgg are explainable—each learnable parameter has an interpretable meaning (Section 6).
- Our experiments provide several insights about the role of aggregation functions in the performance of GNNs. In our regression experiments, we demonstrate that GNNs struggle to "make up for" the lack of representational complexity in their constituent aggregators, even when using state-of-the-art parametrised aggregators. This finding is validated in our GNN benchmark experiments, where we show that a GenAgg-based GNN outperforms all of the baselines, including standard aggregators and other state-of-the-art parametrised aggregators.
- Finally, we show that GenAgg satisfies a generalisation of the distributive property. We derive the solution for a binary operator that satisfies this property for given parametrisations of GenAgg. The generalised distributive property can be leveraged in algorithms using GenAgg to improve space and memory-efficiency.
Consider a multiset  $\mathcal{X} = \{x_1, x_2, \ldots, x_n\}$  of cardinality  $|\mathcal{X}| = n$ , where  $x_i \in \mathbb{R}^d$ . We define an aggregation function as a symmetric function  $\odot : \mathbb{R}^{n \times d} \mapsto \mathbb{R}^{1 \times d}$ . The aggregator must be independent over the feature dimension, so without loss of generality it can be represented over a single dimension  $\odot : \mathbb{R}^n \mapsto \mathbb{R}^1$ . A set of standard aggregators is defined  $\mathcal{A} = \{\text{mean, sum, product, min, max, ...}\}$  (for the full list see Table 1). Our task is to create an aggregator  $\bigoplus_{\theta} : \mathbb{R}^n \mapsto \mathbb{R}^1$  parametrised by  $\theta$  which can represent all standard aggregators:  $\forall \bigodot_i \in \mathcal{A} \exists \theta : \bigoplus_{\theta} = \bigodot_i$ .
In this section we introduce GenAgg, a parametrised aggregation function which is based on the generalised  $f$ -mean [11]. In our formulation, we introduce additional parameters to increase the representational capacity of the  $f$ -mean, producing the augmented  $f$ -mean (AFM). Then, as the implementation is non-trivial, we propose a method to implement it. The novel aspect of GenAgg is not
Aggregation Function	α	β	f	GenAgg	SoftmaxAgg	PowerAgg
mean: 1/n∑xi	0	0	f(x) = x	✓	✓	✓
sum: ∑xi	1	0	f(x) = x	✓	X	X
product: ∏{xi}	1	0	f(x) = log(|x|)	✓	X	X
min (magnitude): min{xi}	0	0	f(x) = limp→∞ |x|−p	✓	X	✓
max (magnitude): max{xi}	0	0	f(x) = limp→∞ |x|p	✓	X	✓
min: minxi	0	0	f(x) = limp→∞ e−px	✓	✓	X
max: maxxi	0	0	f(x) = limp→∞ epx	✓	✓	X
harmonic mean: n/∑1/xi	0	0	f(x) = 1/x	✓	X	✓
geometric mean: √n/∑{xi}	0	0	f(x) = log(|x|)	✓	X	✓
root mean square: √1/n∑xi2	0	0	f(x) = x2	✓	X	✓
euclidean norm: √∑xi2	1	0	f(x) = x2	✓	X	X
standard deviation: √1/n∑(xi−μ)2	0	1	f(x) = x2	✓	X	X
log-sum-exp: log{∑exi}	1	0	f(x) = ex	✓	X	X
Table 1: A table of all of the most common aggregators. For each special case, we specify the values of  $\alpha$ ,  $\beta$ , and  $f$  for which the augmented  $f$ -mean is equivalent (see Appendix C). We also report whether or not SoftmaxAgg and PowermeanAgg can represent each aggregator.
only the augmented  $f$ -mean formula, but also the implementation, which allows the mathematical concept of a generalised mean to be utilised in a machine learning context.
3.1 Generalised  $f$ -Mean
The generalised  $f$ -mean [11] is given by:  $f^{-1}(\frac{1}{n}\sum_{i}f(x_{i}))$ . While it is difficult to define aggregation functions, the generalised  $f$ -mean provides a powerful intuition: most aggregators can be represented by a single invertible scalar-valued function  $f:\mathbb{R}^1\mapsto \mathbb{R}^1$ . This is a useful insight, because it allows comparisons to be drawn between aggregators by analysing their underlying functions  $f$ . Furthermore, it provides a framework for discovering new aggregation functions. While classic functions like  $e^{x},\log (x),x^{p}$  all map to aggregators in  $\mathcal{A}$ , new aggregators can be created by defining new functions  $f$ .
3.2 Augmented  $f$ -Mean
The standard generalised  $f$ -mean imposes strict constraints, such as symmetry (permutation-invariance), idempotency  $(\bigoplus (\{x,\ldots ,x\}) = x)$ , and monotonicity  $(\forall i\in [1..n],\frac{\partial\oplus(\{x_1,\ldots,x_n\})}{\partial x_i}\geq 0)$ . However, this definition is too restrictive to parametrise many special cases of aggregation functions. For example, sum violates idempotency  $(\sum_{i\in [1..n]}x_i = nx)$ , and standard deviation violates monotonicity  $(\frac{\partial\sigma(\{x_1,1\})}{\partial x_1} |_{x_1 = 0} < 0)$ . Consequently, we deem these constraints to be counterproductive. In our method, we introduce learnable parameters  $\alpha$  and  $\beta$  to impose a relaxation on the idetempotency and monotonicity constraints, while maintaining symmetry. We call this relaxed
formulation the augmented  $f$ -mean (AFM), given by:
$$
\bigoplus_ {i \in [ 1.. n ]} x _ {i} = f ^ {- 1} \left(n ^ {\alpha - 1} \sum_ {i \in [ 1.. n ]} f \left(x _ {i} - \beta \mu\right)\right). \tag {1}
$$
The  $\alpha$  parameter allows AFM to control its level of dependence on the cardinality of the input  $\mathcal{X}$ . For example, given  $f(x) = \log(|x|)$ , if  $\alpha = 0$ , then AFM represents the geometric mean:  $\bigoplus_{\langle f, \alpha, \beta \rangle} = \bigoplus_{\langle \log(|x|), 0, 0 \rangle} = \sqrt[n]{\prod |x_i|}$ . However, if  $\alpha = 1$ , then the  $n$ -th root disappears, and AFM represents a product:  $\bigoplus_{\langle \log(|x|), 1, 0 \rangle} = \prod |x_i|$ .
The  $\beta$  parameter enables AFM to calculate centralised moments, which are quantitative measures of the distribution of the input  $\mathcal{X}$  [17]. The first raw moment of  $\mathcal{X}$  is the mean  $\mu = \frac{1}{n}\sum x_{i}$ , and the  $k$ -th central moment is given by  $\mu_{k} = \sum (x_{i} - \mu)^{k}$ . With the addition of  $\beta$ , it becomes possible for AFM to represent  $\sqrt[k]{\mu_k}$ , the  $k$ -th root of the  $k$ -th central moment. For  $k = 2$ , this quantity is the standard deviation, which is in our set of standard aggregators  $\mathcal{A}$ . If the output is scaled to the  $k$ -th power, then it can also represent metrics such as variance, unnormalised skewness, and unnormalised kurtosis. It is clear that these metrics about the distribution of data are useful—they can have real-world meaning (e.g., moments of inertia), and they have been used as aggregators in GNNs in prior work [5]. Consequently,  $\beta$  provides AFM with an important extra dimension of representational complexity. In addition to representing the centralised moments when  $\beta = 1$  and  $f(x) = x^p$ ,  $\beta$  allows any aggregator to be calculated in a centralised fashion. While the centralised moments are the only well-known aggregators that arise from nonzero  $\beta$ , there are several aggregators with qualitatively unique behaviour that can only be represented with nonzero  $\beta$  (see Fig. 1).
With this parametrisation, AFM can represent any standard aggregator in  $\mathcal{A}$  (Table 1). Furthermore, by selecting new parametrisations  $\theta = \langle f,\alpha ,\beta \rangle$  , it is possible to compose new aggregators (Fig. 1).
In Equation (1), the manner in which  $f^{-1}$  is implemented is an important design choice. One option is to learn the coefficients for an analytical function (e.g. a truncated Taylor Series) and analytically invert it. However, it can be difficult to compute the analytical inverse of a function, and without carefully selected constraints, there is no guarantee that  $f$  will be invertible.
Another possible option is an invertible neural network (e.g. a parametrised invertible mapping from normalising flows [10]). We have tested the invertible networks from normalising flows literature as implementations for  $f$ . While they work well on smaller tasks, these methods present speed and memory issues in larger datasets.
In practice, we find that the most effective approach is to use two separate MLPs for  $f$  and  $f^{-1}$ . We enforce the constraint  $x = f^{-1}(f(x))$  by minimizing the following optimisation objective:
$$
\mathcal {L} _ {\mathrm {i n v}} \left(\theta_ {1}, \theta_ {2}\right) = \mathbb {E} \left[ \left(\left| f _ {\theta_ {2}} ^ {- 1} \left(f _ {\theta_ {1}} (x)\right) \right| - | x |\right) ^ {2} \right]. \tag {2}
$$
The absolute value operations apply a relaxation to the constraint, allowing  $f^{-1}(f(x))$  to reconstruct either  $x$  or  $|x|$ . This is useful because several of the ground truth functions from Table 1 include an absolute value, making them non-invertible. With this relaxation, it becomes possible to represent those cases. This optimisation objective ensures that  $f$  is both monotonic and invertible over the domains  $\mathbb{R}^+$  and  $\mathbb{R}^-$ , independently. In our implementation, this extra optimisation objective is hidden behind the GenAgg interface and gets applied automatically with a forward hook, so it is not necessary for the user to apply an extra loss term.
While using a scalar-valued  $f: \mathbb{R}^1 \mapsto \mathbb{R}^1$  is the most human-interpretable formulation, it is not necessary. A valid implementation of GenAgg can also be achieved with  $f: \mathbb{R}^1 \mapsto \mathbb{R}^d$  and  $f^{-1}: \mathbb{R}^d \mapsto \mathbb{R}^1$ . In our experiments, we found that mapping to a higher intermediate dimension can sometimes improve performance over a scalar-valued  $f$  (see training details in Appendix E).
3.4 Generalised Distributive Property
Given that GenAgg presents a method of parameterising the function space of aggregators, it can also be used as a tool for mathematical analysis. To demonstrate this, we use the aug-
Aggregation Function	Distributive Operations ψ(a,b)
mean: 1/n∑xi	a+b, a·b
sum: ∑xi	a·b
product: ∏{xi}	|a|log |b|
min (magnitude): min |xi|	min(|a|, |b|)
max (magnitude): max |xi|	max(|a|, |b|)
min: min xi	min(a, b)
max: max xi	max(a, b)
harmonic mean: n/∑1/xi	a·b/a+b, a·b
geometric mean: √n/Π{xi}	|a|·|b|, |a|log |b|
root mean square: √1/n∑xi2	√a2+b2, |a|·|b|
euclidean norm: √∑xi2	|a|·|b|
standard deviation: √1/n∑(xi-μ)2	|a|·|b|
log-sum-exp: log{∑exi}	a+b
Table 2: A table of the distributive operations  $\psi$  that satisfy each aggregation function, computed using Equation 3. All aggregation functions have at least one solution, and some special cases have multiple solutions.
mented  $f$ -mean to analyse a generalised form of the distributive property, which is satisfied if  $\psi(c, \odot_{x_i \in \mathcal{X}} x_i) = \odot_{x_i \in \mathcal{X}} \psi(c, x_i)$  for binary operator  $\psi$  and aggregator  $\odot$ . For a given aggregation function parametrised by  $f$  (assuming  $\beta$  is 0), we derive a closed-form solution for a corresponding binary operator which will satisfy the generalised distributive property (for further explanation and proofs, see Appendix A).
Theorem 3.1. For GenAgg parametrised by  $\theta = \langle f, \alpha, \beta \rangle = \langle f, \alpha, 0 \rangle$ , the binary operator  $\psi$  which will satisfy the Generalised Distributive Property for  $\bigoplus_{\theta}$  is given by:
$$
\psi (a, b) = f ^ {- 1} (f (a) \cdot f (b)) \tag {3}
$$
Furthermore, for the special case  $\theta = \langle f,\alpha ,\beta \rangle = \langle f,0,0\rangle$  there  $\psi (a,b) = f^{-1}(f(a) + f(b))$  is an additional solution.
For example, for the euclidean norm where  $f(x) = x^2$  and  $\alpha = 1$ , the binary operator is  $\psi(a, b) = (a^2 \cdot b^2)^{\frac{1}{2}} = a \cdot b$ , which implies that a constant multiplicative term can be moved outside of the euclidean norm. This is a useful finding, as the distributive property can used to improve algorithmic time and space complexity (e.g. the FFT) [1]. With our derivation of  $\psi$  as a function of  $f$ , it is possible to implement similar efficient algorithms with GenAgg.
Several existing works propose methods to parametrise the space of aggregation functions. These methods can broadly be divided into two categories. Mathematical approaches derive an explicit equation in terms of the inputs and one or more learnable parameters. Usually, these approaches represent a smooth interpolation through function space from min, through mean, to max. Alternatively, Deep Learning approaches seek to use the universal approximation properties of neural networks to maximise representational complexity.
4.1 Mathematical Approaches
SoftmaxAgg SoftmaxAgg computes the weighted sum of the set, where the weighting is derived from the softmax over the elements with some learnable temperature term  $s$  [13, 20]. This formu
lation allows SoftmaxAgg to represent mean, min, and max (see Table 1). Unfortunately, it fails to generalise across the majority of the standard aggregators.
PowerAgg Based on the  $p$ -norm, PowerAgg is a special case of GenAgg where  $\alpha = 0$ ,  $\beta = 0$ , and  $f(x) = x^p$ . There are some methods which use the powermean directly [13, 20, 8], and others which build on top of it [18]. Theoretically, PowerAgg can represent a significant subset of the standard aggregators: min magnitude, max magnitude, mean, root mean square, harmonic mean, and geometric mean (although the geometric mean requires  $\lim_{p\to 0}$ , so it is not practically realisable) (see Table 1). Unfortunately, there is a caveat to this approach: for negative inputs  $x_i < 0$  and non-integer values  $p$ , it is only defined in the complex domain. Furthermore, for negative inputs, the gradient  $\frac{\partial x^p}{\partial p}$  with respect to trainable parameter  $p$  is complex and oscillatory (and therefore is prone to getting stuck in local optima). In order to fix this problem, the inputs must be constrained to be positive. In prior work, this has been achieved by clamping  $x_i' = \max(x_i, 0)$  [13], subtracting the minimum element  $x_i' = x_i - \min(\mathcal{X})$  [20], or taking the absolute value  $x_i' = |x_i|$  [8]. However, this removes important information, making it impossible to reconstruct most standard aggregators.
4.2 Deep Learning Approaches
PNA While Principle Neighbourhood Aggregation [5] is introduced as a GNN architecture, its novelty stems from its method of aggregation. In PNA, input signal is processed by a set of aggregation functions, which is produced by the cartesian product of standard aggregators  $\{\mathrm{mean},\mathrm{min},\mathrm{max},\mathrm{std}\}$  and scaling factors  $\{\frac{1}{n},1,n\}$ . The output of every aggregator is concatenated, and passed through a dense network. While this increases the representational complexity of the aggregator, it also scales the dimensionality of the input by the number of aggregators multiplied by the number of scaling factors, which can decrease sample efficiency (Figure 3). Furthermore, the representational complexity of the method is limited by the choice of standard aggregators—it cannot be used to represent many of the special cases of parametrised general aggregators.
LSTMAgg In LSTMAgg, the input set is treated as a sequence (applying some random permutation), and is encoded with a recurrent neural network [9]. While this method is theoretically capable of universal approximation, in practice its non-permutation-invariance can cause its performance to suffer (as the factorial complexity of possible orderings leads to sample-inefficiency). SortAgg addresses this issue by sorting the inputs with computed features, and passing the first  $k$  sorted inputs through convolutional and dense networks [23]. While this method solves the issue of non-permutation-invariance, it loses the capability of universal approximation by truncating to  $k$  inputs. While universal approximation is not a requirement for an effective aggregation function, we note that it cannot represent many of the standard aggregators.
Deep Sets Deep Sets is a universal set function approximator [22]. However, because it operates over the feature dimension in addition to the "set" dimension, it is not regarded as an aggregation function. Instead, it usually serves as a full GNN layer or graph pooling architecture [14, 15]. One may note that the formulation for Deep Sets  $\phi (\sum_{i\in [1..n]}f(x_i))$  bears some resemblance to our method. However, there are two important differences. First, our method adds the constraint  $\phi = f^{-1}$ , limiting possible parametrisations to the subspace where all of the standard aggregators lie. Second, while the learnable functions  $\phi$  and  $f$  in Deep Sets are fully connected over the feature dimension, the  $f$  and  $f^{-1}$  modules in our architecture are scalar-valued functions which are applied elementwise. To summarise, Deep Sets is useful as a set function approximator, but it lacks constraints that would make it viable as an aggregation function.
In this paper, we run three experiments. First, we show that GenAgg can perform regression to recover any standard aggregation function. Then, we evaluate GenAgg and several baselines inside of a GNN. The resulting GNN architectures are given the same task of regressing upon graph-structured data generated with a standard aggregator. This tests if it is possible for a GNN with a given aggregator to represent data which was generated by different underlying aggregators. Finally, we provide practical results by running experiments on public GNN benchmark datasets: CLUSTER, PATTERN, CIFAR10, and MNIST [6].
Aggregation	GenAgg	P-Agg	S-Agg	mean
mean	1.000	0.817	1.000	1.000
sum	1.000	0.761	0.887	0.888
product (mag)	0.985	0.407	0.172	0.022
min (mag)	0.962	0.450	0.024	0.027
max (mag)	0.990	0.586	0.423	0.024
min	0.995	0.734	1.000	0.805
max	0.990	0.920	1.000	0.805
harm. mean (abs)	0.986	0.453	0.088	0.027
geom. mean (abs)	0.994	0.481	0.152	0.031
root mean square	0.996	0.532	0.308	0.028
euclidean norm	0.964	0.585	0.464	0.019
standard dev.	0.999	0.442	0.558	0.013
log-sum-exp	0.999	0.823	0.947	0.747
(a) Aggregator Regression.
Aggregation	GenAgg	P-Agg	S-Agg	mean
mean	0.977	0.999	1.000	0.972
sum	0.971	0.906	0.887	0.903
product (mag)	0.966	0.644	0.726	0.434
min (mag)	0.952	0.876	0.810	0.731
max (mag)	0.986	0.734	0.784	0.747
min	0.995	0.986	0.999	0.806
max	0.989	0.976	0.999	0.845
harm. mean (abs)	0.931	0.797	0.842	0.697
geom. mean (abs)	0.963	0.629	0.836	0.626
root mean square	0.975	0.775	0.808	0.899
euclidean norm	0.985	0.742	0.680	0.756
standard dev.	0.966	0.739	0.805	0.624
log-sum-exp	0.983	0.919	0.952	0.841
(b) GNN Regression
Figure 2: Results for the Aggregator Regression and GNN Regression experiments, indicating the ability of GenAgg, PowerAgg (P-Agg), SoftmaxAgg (S-Agg), and mean to parametrisse each standard aggregator in  $\mathcal{A}$ . We report the correlation coefficient between the ground truth and predicted outputs. The highest-performing methods (and those within 0.01 correlation) are shown in bold.
For all baselines, we use the implementations provided in PyTorch Geometric [7]. The only exception is PNA, which is a GNN architecture by nature, not an aggregation method. For our experiments, we adapt PNA into an aggregation method, staying as true to the original formulation as possible:  $\mathrm{PNA}(\mathcal{X}) = f([1,n,\frac{1}{n} ]\otimes [\mathrm{mean}(\mathcal{X}),\mathrm{std}(\mathcal{X}),\min (\mathcal{X}),\max (\mathcal{X})])$  , where  $f$  is a linear layer mapping from  $\mathbb{R}^{12d}$  back to  $\mathbb{R}^d$
For more training details, see Appendix E. Our code can be found at: https://github.com/Acciorocketships/generalised-aggregation.
5.1 Aggregator Regression