dropout_edge
¶
dropout_edge(
edge_index: array,
p: float = 0.5,
force_undirected: bool = False,
training: bool = True,
) -> tuple[array, array]
Randomly drops edges of edge_index with probability p.
Randomness comes from mx.random.uniform, so results are reproducible
with mx.random.seed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
a [2, num_edges] array representing the source and target nodes of each edge |
required |
p
|
float
|
Probability of dropping each edge. Default: |
0.5
|
force_undirected
|
bool
|
If |
False
|
training
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
array
|
A tuple |
array
|
mask of shape |
tuple[array, array]
|
When |
tuple[array, array]
|
second element is instead, as in PyG, an array with the position in |
tuple[array, array]
|
the input |
features
|
an edge and its added reverse share the same position. |
Example:
edge_index = mx.array([[0, 1, 1, 2, 2, 3], [1, 0, 2, 1, 3, 2]])
edge_index, edge_mask = dropout_edge(edge_index, p=0.5)
# edge_index: e.g. mx.array([[0, 1, 2, 2], [1, 2, 1, 3]])
# edge_mask: e.g. mx.array([True, False, True, True, True, False])
edge_index, edge_id = dropout_edge(edge_index, force_undirected=True)
# edge_index: e.g. mx.array([[0, 1], [1, 0]])
# edge_id: e.g. mx.array([0, 0])
Source code in mlx_graphs/utils/dropout.py
from mlx_graphs.utils import dropout_edge · mlx_graphs/utils/dropout.py