global_sort_pool
¶
global_sort_pool(
node_features: array,
batch_indices: Optional[array],
k: int,
num_graphs: Optional[int] = None,
) -> array
The global pooling operator from the "An End-to-End Deep Learning Architecture for Graph Classification" paper.
The nodes of each graph are sorted in descending order of their last
feature, and the features of the first k nodes are concatenated. Graphs
with fewer than k nodes are padded with zeros. This is PyG's
SortAggregation (formerly global_sort_pool).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features
|
array
|
Node features array of shape |
required |
batch_indices
|
Optional[array]
|
Batch array of shape (node_features.shape[0]),
indicating for each node its batch index. |
required |
k
|
int
|
The number of nodes kept for each graph. |
required |
num_graphs
|
Optional[int]
|
Number of graphs in the batch, i.e. number of rows of the
output. By default, inferred as |
None
|
Returns:
| Type | Description |
|---|---|
array
|
An array of shape |
Example:
import mlx.core as mx
from mlx_graphs.nn import global_sort_pool
node_features = mx.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
batch_indices = mx.array([0, 0, 1])
>>> global_sort_pool(node_features, batch_indices, k=2)
array([[3, 4, 1, 2],
[5, 6, 0, 0]], dtype=float32)
Source code in mlx_graphs/nn/pooling/global_pooling.py
from mlx_graphs.nn import global_sort_pool · mlx_graphs/nn/pooling/global_pooling.py