SortAggregation
¶
SortAggregation(k: int)
Bases: Aggregation
Sort pooling from "An End-to-End Deep Learning Architecture for Graph Classification" paper (DGCNN).
The elements of each set (e.g. the nodes of each graph) are sorted in
descending order of their last feature, and the first \(k\) are kept
and flattened. Sets with fewer than \(k\) elements are padded with
zeros. Unlike PyG, index does not need to be sorted.
This is also the global_sort_pool of earlier PyG versions, see
global_sort_pool().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of elements kept per set. |
required |
Example:
import mlx.core as mx
from mlx_graphs.nn.aggr import SortAggregation
pool = SortAggregation(k=3)
node_features = mx.random.normal((7, 16))
batch_indices = mx.array([0, 0, 0, 0, 1, 1, 1])
>>> pool(node_features, batch_indices).shape
(2, 48)
Methods:
| Name | Description |
|---|---|
aggregate |
Sort-pools |
Source code in mlx_graphs/nn/aggr/sort.py
aggregate
¶
aggregate(
x: array,
index: array,
dim_size: int,
max_num_elements: Optional[int] = None,
**kwargs,
) -> array
Sort-pools x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array
|
Array of shape |
required |
index
|
array
|
Set (e.g. graph) of each element. |
required |
dim_size
|
int
|
Number of sets. |
required |
max_num_elements
|
Optional[int]
|
Only the first |
None
|
Returns:
| Type | Description |
|---|---|
array
|
An array of shape |
Source code in mlx_graphs/nn/aggr/sort.py
from mlx_graphs.nn.aggr import SortAggregation · mlx_graphs/nn/aggr/sort.py