CorrectAndSmooth
¶
CorrectAndSmooth(
num_correction_layers: int,
correction_alpha: float,
num_smoothing_layers: int,
smoothing_alpha: float,
autoscale: bool = True,
scale: float = 1.0,
)
Bases: Module
The correct and smooth (C&S) post-processing model from the "Combining Label Propagation And Simple Models Out-performs Graph Neural Networks" paper.
The soft predictions \(\mathbf{Z}\) of a base predictor are first
corrected by propagating their residual error on the training nodes
(correct()), then smoothed by propagating the corrected predictions,
with the ground truth on the training nodes (smooth()). Both steps
use LabelPropagation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_correction_layers
|
int
|
The number of propagations \(L_1\). |
required |
correction_alpha
|
float
|
The \(\alpha_1\) coefficient. |
required |
num_smoothing_layers
|
int
|
The number of propagations \(L_2\). |
required |
smoothing_alpha
|
float
|
The \(\alpha_2\) coefficient. |
required |
autoscale
|
bool
|
If |
True
|
scale
|
float
|
The scaling factor \(\gamma\), used when
|
1.0
|
Example:
import mlx.core as mx
from mlx_graphs.nn import CorrectAndSmooth
post = CorrectAndSmooth(
num_correction_layers=50,
correction_alpha=1.0,
num_smoothing_layers=50,
smoothing_alpha=0.8,
autoscale=False,
scale=20.0,
)
y_soft = mx.softmax(logits, axis=-1)
y_soft = post.correct(edge_index, y_soft, y[train_idx], train_idx)
y_soft = post.smooth(edge_index, y_soft, y[train_idx], train_idx)
References
[1] Huang et al. Combining Label Propagation And Simple Models Out-performs Graph Neural Networks
Methods:
| Name | Description |
|---|---|
__call__ |
Applies |
correct |
Corrects the soft predictions with the propagated residual error. |
smooth |
Smooths the (corrected) predictions by propagating them, with the |
Source code in mlx_graphs/nn/models/correct_and_smooth.py
__call__
¶
__call__(
edge_index: array,
y_soft: array,
y_true: array,
mask: array,
edge_weights: Optional[array] = None,
) -> array
Applies correct() then smooth().
Source code in mlx_graphs/nn/models/correct_and_smooth.py
correct
¶
correct(
edge_index: array,
y_soft: array,
y_true: array,
mask: array,
edge_weights: Optional[array] = None,
) -> array
Corrects the soft predictions with the propagated residual error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Input edge index of shape |
required |
y_soft
|
array
|
The soft predictions \(\mathbf{Z}\) of a base
predictor, shape |
required |
y_true
|
array
|
The ground truth of the training nodes: integer labels of
shape |
required |
mask
|
array
|
Boolean mask or index array of the training nodes |
required |
edge_weights
|
Optional[array]
|
Optional weight of each edge. Default: |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The corrected predictions, shape |
Source code in mlx_graphs/nn/models/correct_and_smooth.py
smooth
¶
smooth(
edge_index: array,
y_soft: array,
y_true: array,
mask: array,
edge_weights: Optional[array] = None,
) -> array
Smooths the (corrected) predictions by propagating them, with the ground truth on the training nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
Input edge index of shape |
required |
y_soft
|
array
|
The corrected predictions from |
required |
y_true
|
array
|
The ground truth of the training nodes: integer labels of
shape |
required |
mask
|
array
|
Boolean mask or index array of the training nodes |
required |
edge_weights
|
Optional[array]
|
Optional weight of each edge. Default: |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The final predictions, shape |
Source code in mlx_graphs/nn/models/correct_and_smooth.py
from mlx_graphs.nn import CorrectAndSmooth · mlx_graphs/nn/models/correct_and_smooth.py