PANPooling
¶
PANPooling(
node_features_dim: int,
ratio: Union[float, int] = 0.5,
min_score: Optional[float] = None,
multiplier: float = 1.0,
nonlinearity: Union[str, Callable] = "tanh",
)
Bases: Module
The path integral based pooling operator from the "Path Integral Based Convolution and Pooling for Graph Neural Networks" paper.
PAN pooling performs top-\(k\) pooling where global node importance is measured based on node features and the MET matrix:
where \({\rm deg}(\mathbf{M})_j\) sums the column \(j\) of
\(\mathbf{M}\). The kept nodes are scaled by their (normalized)
score, and the pooled graph keeps the entries of \(\mathbf{M}\)
between them, as edges j -> i weighted by \(\mathbf{M}_{i,j}\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
int
|
Size of the input node features. |
required |
ratio
|
Union[float, int]
|
The graph pooling ratio, used to compute
\(k = \lceil \mathrm{ratio} \cdot N \rceil\) for a float, or
\(k\) itself for an integer. Ignored if |
0.5
|
min_score
|
Optional[float]
|
Minimal node score of the kept nodes. When given,
|
None
|
multiplier
|
float
|
Coefficient by which the features are multiplied after
pooling. Default: |
1.0
|
nonlinearity
|
Union[str, Callable]
|
The non-linearity of the scores, as a callable or the
name of a function of |
'tanh'
|
Example:
import mlx.core as mx
from mlx_graphs.nn import PANConv, PANPooling
conv = PANConv(16, 32, filter_size=2)
pool = PANPooling(32, ratio=0.5)
edge_index = mx.array([[0, 1, 1, 2, 3, 4], [1, 0, 2, 1, 4, 3]])
batch_indices = mx.array([0, 0, 0, 1, 1])
x, (m_index, m_weights) = conv(edge_index, mx.random.normal((5, 16)))
x, edge_index, edge_weights, batch_indices, perm, score = pool(
m_index, x, m_weights, batch_indices
)
>>> x.shape
(3, 32)
Methods:
| Name | Description |
|---|---|
__call__ |
Pools the graphs. |
Source code in mlx_graphs/nn/pooling/pan_pool.py
__call__
¶
__call__(
m_index: array,
node_features: array,
m_weights: array,
batch_indices: Optional[array] = None,
) -> Tuple[array, array, array, array, array, array]
Pools the graphs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m_index
|
array
|
|
required |
node_features
|
array
|
Node features of shape |
required |
m_weights
|
array
|
The |
required |
batch_indices
|
Optional[array]
|
Graph of each node, of shape |
None
|
Returns:
| Type | Description |
|---|---|
array
|
A tuple `(node_features, edge_index, edge_weights, |
array
|
batch_indices, perm, score)` with the pooled graph, the indices |
array
|
|
Source code in mlx_graphs/nn/pooling/pan_pool.py
from mlx_graphs.nn import PANPooling · mlx_graphs/nn/pooling/pan_pool.py