LabelPropagation
¶
Bases: Module
The label propagation operator from the "Learning from Labeled and Unlabeled Data with Label Propagation" paper, in the form used by "Combining Label Propagation And Simple Models Out-performs Graph Neural Networks".
The layer has no parameters and no gradient flows through it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_layers
|
int
|
The number of propagations. |
required |
alpha
|
float
|
The \(\alpha\) coefficient. |
required |
Example:
import mlx.core as mx
from mlx_graphs.nn import LabelPropagation
edge_index = mx.array([[0, 1, 1, 2, 2, 3], [1, 0, 2, 1, 3, 2]])
labels = mx.array([0, 0, 1, 1])
train_mask = mx.array([True, False, False, True])
model = LabelPropagation(num_layers=3, alpha=0.9)
out = model(edge_index, labels, mask=train_mask)
>>> out.shape
(4, 2)
References
[1] Huang et al. Combining Label Propagation And Simple Models Out-performs Graph Neural Networks
Methods:
| Name | Description |
|---|---|
__call__ |
Propagates the labels. |
Source code in mlx_graphs/nn/models/label_prop.py
__call__
¶
__call__(
edge_index: array,
y: array,
mask: Optional[array] = None,
edge_weights: Optional[array] = None,
post_step: Optional[Callable[[array], array]] = None,
) -> array
Propagates the labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Input edge index of shape |
required |
y
|
array
|
The label information \(\mathbf{Y}\): integer class labels
of shape |
required |
mask
|
Optional[array]
|
Boolean mask or index array of the nodes whose labels are
propagated; the other nodes start from zero. Default: |
None
|
edge_weights
|
Optional[array]
|
Optional weight of each edge. If given, it is used
as is, without the symmetric normalization. Default: |
None
|
post_step
|
Optional[Callable[[array], array]]
|
Function applied after each propagation. Default:
|
None
|
Returns:
| Type | Description |
|---|---|
array
|
The propagated labels, shape |
Source code in mlx_graphs/nn/models/label_prop.py
from mlx_graphs.nn import LabelPropagation · mlx_graphs/nn/models/label_prop.py