ClusterData
¶
ClusterData(
data: GraphData,
num_parts: int,
partition: Optional[Union[array, ndarray]] = None,
method: Literal["auto", "metis", "balanced"] = "auto",
num_iters: int = 10,
)
Partitions a graph into num_parts clusters, for Cluster-GCN
training ("Cluster-GCN: An Efficient Algorithm for Training Deep and Large Graph Convolutional Networks"),
following PyG's ClusterData. Use it with ClusterLoader.
PyG partitions with METIS. Here, METIS (through the optional pymetis
package) is used only if it is installed or method="metis" is set;
otherwise a dependency-free balanced partitioner is used (see
balanced_partition()): partitions are balanced but differ from
METIS', with a usually larger edge cut. Any custom partition can also be
given with partition.
cluster_data[i] is the subgraph induced by the nodes of cluster i
(edges between clusters are dropped), with n_id and e_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
The graph to partition. |
required |
num_parts
|
int
|
Number of clusters. Ignored if |
required |
partition
|
Optional[Union[array, ndarray]]
|
Optional cluster id of every node, |
None
|
method
|
Literal['auto', 'metis', 'balanced']
|
|
'auto'
|
num_iters
|
int
|
Refinement rounds of the |
10
|
Attributes:
| Name | Type | Description |
|---|---|---|
cluster |
Cluster id of every node (numpy array). |
|
node_perm |
Node ids sorted by cluster (numpy array). |
|
partptr |
Start of every cluster in |
Example:
from mlx_graphs.loaders import ClusterData, ClusterLoader
cluster_data = ClusterData(data, num_parts=100)
loader = ClusterLoader(cluster_data, batch_size=10, shuffle=True)
for batch in loader:
out = model(batch.node_features, batch.edge_index)
Methods:
| Name | Description |
|---|---|
nodes_of |
Global ids of the nodes of the given cluster(s), cluster by cluster. |
subgraph |
Subgraph induced by the union of the given clusters. |
Source code in mlx_graphs/loaders/cluster.py
nodes_of
¶
Global ids of the nodes of the given cluster(s), cluster by cluster.
Source code in mlx_graphs/loaders/cluster.py
subgraph
¶
Subgraph induced by the union of the given clusters.
Source code in mlx_graphs/loaders/cluster.py
from mlx_graphs.loaders import ClusterData · mlx_graphs/loaders/cluster.py