torch_geometric.nn.models.LabelPropagation

class LabelPropagation(num_layers: int, alpha: float)[source]

Bases: MessagePassing

The label propagation operator, firstly introduced in the “Learning from Labeled and Unlabeled Data with Label Propagation” paper.

\[\mathbf{Y}^{\prime} = \alpha \cdot \mathbf{D}^{-1/2} \mathbf{A} \mathbf{D}^{-1/2} \mathbf{Y} + (1 - \alpha) \mathbf{Y},\]

where unlabeled data is inferred by labeled data via propagation. This concrete implementation here is derived from the “Combining Label Propagation And Simple Models Out-performs Graph Neural Networks” paper.

Note

For an example of using the LabelPropagation, see examples/label_prop.py.

Parameters:
  • num_layers (int) – The number of propagations.

  • alpha (float) – The \(\alpha\) coefficient.

forward(y: Tensor, edge_index: Union[Tensor, SparseTensor], mask: Optional[Tensor] = None, edge_weight: Optional[Tensor] = None, post_step: Optional[Callable[[Tensor], Tensor]] = None) Tensor[source]

Forward pass.

Parameters:
  • y (torch.Tensor) – The ground-truth label information \(\mathbf{Y}\).

  • edge_index (torch.Tensor or SparseTensor) – The edge connectivity.

  • mask (torch.Tensor, optional) – A mask or index tensor denoting which nodes are used for label propagation. (default: None)

  • edge_weight (torch.Tensor, optional) – The edge weights. (default: None)

  • post_step (callable, optional) – A post step function specified to apply after label propagation. If no post step function is specified, the output will be clamped between 0 and 1. (default: None)

reset_parameters() None

Resets all learnable parameters of the module.