RemoveIsolatedNodes
¶
Bases: BaseTransform
Removes the isolated nodes of a graph.
A node is isolated if it has no edge to another node, as in
GraphData.has_isolated_nodes(): a node whose only edges are
self-loops is isolated, and is removed together with its self-loops. The
remaining nodes are relabeled to [0, num_remaining_nodes) in their
original order, and every per-node attribute (e.g. node_features,
node_labels, train_mask) and per-edge attribute is sliced
accordingly.
Example:
graph = GraphData(
edge_index=mx.array([[0, 3], [3, 0]]),
node_features=mx.array([[0.0], [1.0], [2.0], [3.0]]),
)
graph = RemoveIsolatedNodes()(graph)
graph.edge_index
# mx.array([[0, 1], [1, 0]])
graph.node_features
# mx.array([[0.0], [3.0]])
Methods:
| Name | Description |
|---|---|
process |
Removes the isolated nodes of |
process
¶
Removes the isolated nodes of data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
The graph to transform. |
required |
Returns:
| Type | Description |
|---|---|
GraphData
|
The graph without isolated nodes. |
Source code in mlx_graphs/transforms/structure.py
from mlx_graphs.transforms import RemoveIsolatedNodes · mlx_graphs/transforms/structure.py