RadiusGraph
¶
RadiusGraph(
r: float,
loop: bool = False,
max_num_neighbors: Optional[int] = 32,
flow: Literal["source_to_target", "target_to_source"] = "source_to_target",
)
Bases: BaseTransform
Creates the graph connecting the nodes whose positions pos are
within a given distance.
The previous edges of the graph are replaced, and its edge_features and
edge_weights are dropped. For a GraphDataBatch, only the nodes of
the same graph are connected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
The distance. |
required |
loop
|
bool
|
If |
False
|
max_num_neighbors
|
Optional[int]
|
The maximum number of neighbors of each node; the
closest ones are kept. |
32
|
flow
|
Literal['source_to_target', 'target_to_source']
|
Direction of the edges, for use with message passing. With
|
'source_to_target'
|
Example:
import mlx.core as mx
from mlx_graphs.data import GraphData
from mlx_graphs.transforms import RadiusGraph
pos = mx.array([[0.0, 0.0], [1.0, 0.0], [3.0, 0.0]])
graph = GraphData(edge_index=mx.zeros((2, 0), dtype=mx.int32), pos=pos)
graph = RadiusGraph(r=1.5)(graph)
>>> graph.edge_index
array([[1, 0],
[0, 1]], dtype=int32)
Methods:
| Name | Description |
|---|---|
process |
Replaces the edges of |
Source code in mlx_graphs/transforms/spatial.py
process
¶
Replaces the edges of data by its radius graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
GraphData
|
The graph to transform. It must have a |
required |
Returns:
| Type | Description |
|---|---|
GraphData
|
The graph with the radius edges. |
Source code in mlx_graphs/transforms/spatial.py
from mlx_graphs.transforms import RadiusGraph · mlx_graphs/transforms/spatial.py