Skip to content

avg_pool

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

Pools and coarsens a graph given by a clustering, averaging the node features and the positions of each cluster (as PyG's avg_pool).

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.

Source code in mlx_graphs/nn/pooling/cluster_pooling.py
def avg_pool(
    cluster: mx.array, data: GraphData, transform: Optional[Callable] = None
) -> GraphData:
    r"""Pools and coarsens a graph given by a clustering, averaging the node
    features and the positions of each cluster (as PyG's ``avg_pool``).

    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.
    """
    return _pool(cluster, data, "mean", transform)

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