Skip to content

max_pool

max_pool(
    cluster: array, data: GraphData, transform: Optional[Callable] = None
) -> GraphData

Pools and coarsens a graph given by a clustering, taking the feature-wise maximum of the nodes of each cluster (as PyG's max_pool). The positions are averaged.

Edges are mapped onto the clusters of their nodes; self-loops are removed and duplicate edges merged (their edge_features are summed).

Parameters:

Name Type Description Default
cluster array

Cluster of each node, of shape [N].

required
data GraphData

The graph (or GraphDataBatch) to coarsen.

required
transform Optional[Callable]

A function/transform applied to the coarsened graph. Default: None

None

Returns:

Type Description
GraphData

The coarsened graph, with one node per cluster (in increasing order of

GraphData

cluster id), the average pos and, for a batch, the

GraphData

batch_indices of each cluster.

Example:

from mlx_graphs.nn import max_pool
from mlx_graphs.utils import voxel_grid

cluster = voxel_grid(batch.pos, size=0.2, batch=batch.batch_indices)
coarse = max_pool(cluster, batch)
Source code in mlx_graphs/nn/pooling/cluster_pooling.py
def max_pool(
    cluster: mx.array, data: GraphData, transform: Optional[Callable] = None
) -> GraphData:
    r"""Pools and coarsens a graph given by a clustering, taking the
    feature-wise maximum of the nodes of each cluster (as PyG's ``max_pool``).
    The positions are averaged.

    Edges are mapped onto the clusters of their nodes; self-loops are removed
    and duplicate edges merged (their ``edge_features`` are summed).

    Args:
        cluster: Cluster of each node, of shape ``[N]``.
        data: The graph (or ``GraphDataBatch``) to coarsen.
        transform: A function/transform applied to the coarsened graph.
            Default: ``None``

    Returns:
        The coarsened graph, with one node per cluster (in increasing order of
        cluster id), the average ``pos`` and, for a batch, the
        ``batch_indices`` of each cluster.

    Example:

    .. code-block:: python

        from mlx_graphs.nn import max_pool
        from mlx_graphs.utils import voxel_grid

        cluster = voxel_grid(batch.pos, size=0.2, batch=batch.batch_indices)
        coarse = max_pool(cluster, batch)
    """
    return _pool(cluster, data, "max", transform)

from mlx_graphs.nn import max_pool · mlx_graphs/nn/pooling/cluster_pooling.py