AddSelfLoops
¶
AddSelfLoops(fill_value: float = 1.0)
Bases: BaseTransform
Adds a self-loop to every node of a graph.
A self-loop is appended for every node, including the nodes that already
have one (use RemoveSelfLoops first to avoid duplicates). Every
per-edge attribute (e.g. edge_features, edge_weights) is extended
with fill_value for the new edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fill_value
|
float
|
Value of the per-edge attributes of the added self-loops.
Default: |
1.0
|
Example:
graph = GraphData(edge_index=mx.array([[0, 1], [1, 2]]))
graph = AddSelfLoops()(graph)
graph.edge_index
# mx.array([[0, 1, 0, 1, 2], [1, 2, 0, 1, 2]])
Methods:
| Name | Description |
|---|---|
process |
Adds the self-loops to |
Source code in mlx_graphs/transforms/structure.py
process
¶
Adds the self-loops to data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
The graph to transform. |
required |
Returns:
| Type | Description |
|---|---|
GraphData
|
The graph with self-loops. |
Source code in mlx_graphs/transforms/structure.py
from mlx_graphs.transforms import AddSelfLoops · mlx_graphs/transforms/structure.py