dense_diff_pool
¶
dense_diff_pool(
adj: array,
node_features: array,
s: array,
mask: Optional[array] = None,
normalize: bool = True,
) -> Tuple[array, array, array, array]
The differentiable pooling operator from the "Hierarchical Graph Representation Learning with Differentiable Pooling" paper.
based on the dense learned assignments \(\mathbf{S} \in \mathbb{R}^{B \times N \times C}\). Also returns the auxiliary link prediction loss
divided by the number of entries of \(\mathbf{A}\) if normalize,
and the entropy regularization
\(\mathcal{L}_E = \frac{1}{B N} \sum_{b, n} H(\mathbf{S}_{b, n})\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adj
|
array
|
Adjacency matrices of shape |
required |
node_features
|
array
|
Node features of shape |
required |
s
|
array
|
Assignment logits of shape |
required |
mask
|
Optional[array]
|
Optional boolean mask of shape |
None
|
normalize
|
bool
|
Whether to divide the link loss by the number of entries of
|
True
|
Returns:
| Type | Description |
|---|---|
array
|
A tuple |
array
|
pooled features |
array
|
adjacency |
Example:
import mlx.core as mx
from mlx_graphs.nn import dense_diff_pool
adj = (mx.random.uniform(shape=(2, 10, 10)) > 0.7).astype(mx.float32)
x = mx.random.normal((2, 10, 16))
s = mx.random.normal((2, 10, 3))
x, adj, link_loss, ent_loss = dense_diff_pool(adj, x, s)
>>> x.shape, adj.shape
((2, 3, 16), (2, 3, 3))
Source code in mlx_graphs/nn/pooling/dense_pool.py
from mlx_graphs.nn import dense_diff_pool · mlx_graphs/nn/pooling/dense_pool.py