DMoNPooling
¶
Bases: Module
The spectral modularity pooling operator from the "Graph Clustering with Graph Neural Networks" paper.
where the assignments \(\mathbf{S}\) are computed by an MLP from the node features. Also returns the spectral (modularity) loss
where \(\mathbf{B}\) is the modularity matrix, the orthogonality loss
(see dense_mincut_pool()) and the cluster loss
The output features go through a SELU activation, and the output
adjacency is normalized as in dense_mincut_pool(). As in PyG (2.8),
the cluster loss of a batch is the mean of the cluster norms times the
mean of the inverse graph sizes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_features_dim
|
Union[int, List[int]]
|
Size of the input node features, or a list of
sizes |
required |
k
|
int
|
Number of clusters. |
required |
dropout
|
float
|
Dropout probability of the assignment logits.
Default: |
0.0
|
Example:
import mlx.core as mx
from mlx_graphs.nn import DMoNPooling
pool = DMoNPooling(16, k=4)
adj = (mx.random.uniform(shape=(2, 10, 10)) > 0.7).astype(mx.float32)
x = mx.random.normal((2, 10, 16))
s, x, adj, spectral_loss, ortho_loss, cluster_loss = pool(adj, x)
>>> x.shape
(2, 4, 16)
Methods:
| Name | Description |
|---|---|
__call__ |
Pools the graphs. |
Source code in mlx_graphs/nn/pooling/dense_pool.py
__call__
¶
__call__(
adj: array, node_features: array, mask: Optional[array] = None
) -> Tuple[array, array, array, array, array, array]
Pools the graphs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adj
|
array
|
Adjacency matrices of shape |
required |
node_features
|
array
|
Node features of shape |
required |
mask
|
Optional[array]
|
Optional boolean mask of shape |
None
|
Returns:
| Type | Description |
|---|---|
array
|
A tuple `(s, node_features, adj, spectral_loss, ortho_loss, |
array
|
cluster_loss) |
array
|
|
Source code in mlx_graphs/nn/pooling/dense_pool.py
from mlx_graphs.nn import DMoNPooling · mlx_graphs/nn/pooling/dense_pool.py