Skip to content

avg_pool_x

avg_pool_x(
    cluster: array,
    x: array,
    batch: array,
    batch_size: Optional[int] = None,
    size: Optional[int] = None,
) -> Tuple[array, Optional[array]]

Averages the features of the nodes of each cluster.

Parameters:

Name Type Description Default
cluster array

Cluster of each node, of shape [N] (e.g. from voxel_grid() or graclus()).

required
x array

Node features, of shape [N, F].

required
batch array

Graph of each node, of shape [N].

required
batch_size Optional[int]

The number of graphs (only used with size). Default: None (inferred from batch).

None
size Optional[int]

If given, the maximum number of clusters per graph: the output then has batch_size * size rows indexed by cluster directly (empty clusters are zeros), and no batch vector is returned. Default: None

None

Returns:

Type Description
A tuple `(x, batch)`

the features of each cluster, in increasing

Optional[array]

order of cluster id, and the graph of each cluster (None when

Tuple[array, Optional[array]]

size is given).

Source code in mlx_graphs/nn/pooling/cluster_pooling.py
def avg_pool_x(
    cluster: mx.array,
    x: mx.array,
    batch: mx.array,
    batch_size: Optional[int] = None,
    size: Optional[int] = None,
) -> Tuple[mx.array, Optional[mx.array]]:
    r"""Averages the features of the nodes of each cluster.

    Args:
        cluster: Cluster of each node, of shape ``[N]`` (e.g. from
            :func:`~mlx_graphs.utils.voxel_grid` or
            :func:`~mlx_graphs.utils.graclus`).
        x: Node features, of shape ``[N, F]``.
        batch: Graph of each node, of shape ``[N]``.
        batch_size: The number of graphs (only used with ``size``). Default:
            ``None`` (inferred from ``batch``).
        size: If given, the maximum number of clusters per graph: the output
            then has ``batch_size * size`` rows indexed by ``cluster`` directly
            (empty clusters are zeros), and no batch vector is returned.
            Default: ``None``

    Returns:
        A tuple ``(x, batch)``: the features of each cluster, in increasing
        order of cluster id, and the graph of each cluster (``None`` when
        ``size`` is given).
    """
    return _pool_x(cluster, x, batch, "mean", batch_size, size)

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