LargestConnectedComponents
¶
LargestConnectedComponents(
num_components: int = 1, connection: Literal["weak", "strong"] = "weak"
)
Bases: BaseTransform
Keeps only the largest connected components of a graph.
The nodes are relabeled to [0, num_remaining_nodes) in their original
order, and every per-node and per-edge attribute is sliced accordingly.
Requires scipy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_components
|
int
|
Number of largest components to keep. Default: |
1
|
connection
|
Literal['weak', 'strong']
|
|
'weak'
|
Example:
graph = GraphData(edge_index=mx.array([[0, 1, 3], [1, 2, 4]]))
graph = LargestConnectedComponents()(graph)
graph.edge_index
# mx.array([[0, 1], [1, 2]])
Methods:
| Name | Description |
|---|---|
process |
Restricts |
Source code in mlx_graphs/transforms/structure.py
process
¶
Restricts data to its largest connected components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
The graph to transform. |
required |
Returns:
| Type | Description |
|---|---|
GraphData
|
The graph restricted to its largest components. |
Source code in mlx_graphs/transforms/structure.py
from mlx_graphs.transforms import LargestConnectedComponents · mlx_graphs/transforms/structure.py