DegreeScalerAggregation
¶
DegreeScalerAggregation(
aggr: Union[str, List[Union[str, Aggregation]], Aggregation],
scaler: Union[Scalers, List[Scalers]],
deg: Union[array, ndarray, Sequence[int]],
train_norm: bool = False,
aggr_kwargs: Optional[Union[Dict[str, Any], List[Dict[str, Any]]]] = None,
)
Bases: Aggregation
Combines one or more aggregations and rescales their output with one or more degree-based scalers, from "Principal Neighbourhood Aggregation for Graph Nets" paper.
With \(d\) the number of elements of a set (the in-degree of a node in message passing), and \(\delta\) the average of \(\log(d + 1)\) (or of \(d\), for the linear scalers) over the training graphs, the scalers multiply the aggregated features by:
"identity": \(1\)"amplification": \(\log(d + 1) / \delta\)"attenuation": \(\delta / \log(\max(d, 1) + 1)\)"linear": \(d / \delta_{lin}\)"inverse_linear": \(\delta_{lin} / \max(d, 1)\)
The outputs of all the scalers are concatenated along the last axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggr
|
Union[str, List[Union[str, Aggregation]], Aggregation]
|
The aggregation(s): a name, a list of names/aggregations
(combined with |
required |
scaler
|
Union[Scalers, List[Scalers]]
|
A scaler name or a list of scaler names. |
required |
deg
|
Union[array, ndarray, Sequence[int]]
|
Histogram of the in-degrees of the training nodes:
|
required |
train_norm
|
bool
|
If |
False
|
aggr_kwargs
|
Optional[Union[Dict[str, Any], List[Dict[str, Any]]]]
|
Arguments used to build the aggregation(s) given by name
(a dict, or a list of dicts for a list of aggregations).
Default: |
None
|
Example:
import mlx.core as mx
from mlx_graphs.nn.aggr import DegreeScalerAggregation
deg = mx.array([0, 2, 3, 1]) # 2 nodes of degree 1, 3 of degree 2, ...
aggr = DegreeScalerAggregation(
["mean", "max"], ["identity", "amplification"], deg
)
x = mx.random.normal((6, 16))
index = mx.array([0, 0, 1, 1, 1, 2])
>>> aggr(x, index).shape
(3, 64)
Methods:
| Name | Description |
|---|---|
reset_parameters |
Resets the normalization constants to their values from |
Source code in mlx_graphs/nn/aggr/scaler.py
reset_parameters
¶
Resets the normalization constants to their values from deg.
Source code in mlx_graphs/nn/aggr/scaler.py
from mlx_graphs.nn.aggr import DegreeScalerAggregation · mlx_graphs/nn/aggr/scaler.py