Skip to content

ClusterLoader

ClusterLoader(
    cluster_data: ClusterData, batch_size: int = 1, shuffle: bool = False
)

Merges batch_size clusters of a ClusterData per mini-batch and yields the subgraph they induce, including the edges between the merged clusters (Cluster-GCN's stochastic multiple partitions), following PyG's ClusterLoader.

Each batch is a GraphData with node- and edge-level attributes sliced to the subgraph, plus n_id and e_id.

Parameters:

Name Type Description Default
cluster_data ClusterData

The partitioned graph.

required
batch_size int

Number of clusters per mini-batch. Defaults to 1

1
shuffle bool

Whether to shuffle the clusters at each epoch. Defaults to False

False

Example:

cluster_data = ClusterData(data, num_parts=1500)
loader = ClusterLoader(cluster_data, batch_size=20, shuffle=True)
Source code in mlx_graphs/loaders/cluster.py
def __init__(
    self, cluster_data: ClusterData, batch_size: int = 1, shuffle: bool = False
):
    if batch_size < 1:
        raise ValueError(f"`batch_size` must be positive (got {batch_size})")
    self.cluster_data = cluster_data
    self.batch_size = batch_size
    self.shuffle = shuffle
    self._indices = np.arange(len(cluster_data))
    self._current_index = 0

from mlx_graphs.loaders import ClusterLoader · mlx_graphs/loaders/cluster.py