Skip to content

PowerMeanAggregation

PowerMeanAggregation(
    p: float = 1.0,
    learn: bool = False,
    channels: int = 1,
    clamp_min: Optional[float] = 0.0001,
    clamp_max: Optional[float] = 100.0,
)

Bases: Aggregation

Power mean aggregation with an (optionally learnable) power, from "DeeperGCN: All You Need to Train Deeper GCNs" paper.

\[ \mathrm{powermean}(\mathcal{X}|p) = \left(\frac{1}{|\mathcal{X}|} \sum_{\mathbf{x}_i\in\mathcal{X}}\mathbf{x}_i^{p}\right)^{1/p}. \]

As in PyG, unless \(p = 1\), the inputs and the mean are clamped to [clamp_min, clamp_max] (so the inputs are expected to be positive).

Parameters:

Name Type Description Default
p float

Initial power. Default: 1.0

1.0
learn bool

If True, \(p\) is a learnable parameter. Default: False

False
channels int

Number of learnable powers, one per feature channel when greater than 1. Requires learn=True. Default: 1

1
clamp_min Optional[float]

Lower bound of the clamping, or None. Default: 1e-4

0.0001
clamp_max Optional[float]

Upper bound of the clamping, or None. Default: 100.

100.0

Methods:

Name Description
reset_parameters

Resets the power to its initial value.

Source code in mlx_graphs/nn/aggr/basic.py
def __init__(
    self,
    p: float = 1.0,
    learn: bool = False,
    channels: int = 1,
    clamp_min: Optional[float] = 1e-4,
    clamp_max: Optional[float] = 100.0,
):
    super().__init__()
    if not learn and channels != 1:
        raise ValueError(
            "Cannot set 'channels' greater than 1 in PowerMeanAggregation "
            "when 'p' is not learnable"
        )
    self._init_p = p
    self.learn = learn
    self.channels = channels
    self.clamp_min = clamp_min
    self.clamp_max = clamp_max
    if learn:
        self.p = mx.full((channels,), p)
    else:
        self._p = p
    self.reset_parameters()

reset_parameters

reset_parameters()

Resets the power to its initial value.

Source code in mlx_graphs/nn/aggr/basic.py
def reset_parameters(self):
    """Resets the power to its initial value."""
    if self.learn:
        self.p = mx.full((self.channels,), self._init_p)

from mlx_graphs.nn.aggr import PowerMeanAggregation · mlx_graphs/nn/aggr/basic.py