dropout_node
¶
dropout_node(
edge_index: array,
p: float = 0.5,
num_nodes: Optional[int] = None,
training: bool = True,
) -> tuple[array, array, array]
Randomly drops nodes with probability p, together with all the edges
connected to them. The kept edges are not relabeled.
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 node. Default: |
0.5
|
num_nodes
|
Optional[int]
|
Number of nodes in the graph. Inferred from |
None
|
training
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
array
|
A tuple |
array
|
boolean mask of shape |
array
|
a boolean mask of shape |
Example:
edge_index = mx.array([[0, 1, 1, 2, 2, 3], [1, 0, 2, 1, 3, 2]])
edge_index, edge_mask, node_mask = dropout_node(edge_index, p=0.5)
# edge_index: e.g. mx.array([[0, 1], [1, 0]])
# edge_mask: e.g. mx.array([True, True, False, False, False, False])
# node_mask: e.g. mx.array([True, True, False, False])
Source code in mlx_graphs/utils/dropout.py
from mlx_graphs.utils import dropout_node · mlx_graphs/utils/dropout.py