rllm.nn.conv.graph_conv.LGCConv¶
- class rllm.nn.conv.graph_conv.LGCConv(beta: float = 0.5, *, with_param: bool = False, in_dim: int | None = None, out_dim: int | None = None, bias: bool = False)[source]¶
Bases:
MessagePassingThe LGC (Lazy Graph Convolution) implementation with message passing, based on the “From Cluster Assumption to Graph Convolution: Graph-based Semi-Supervised Learning Revisited” paper.
This model use hyperparameter \(\beta\) to control the message attribution of both neighbor nodes and the node itself:
- If \(\beta = 1\), the model is equivalent to the graph convolution form of GCN model.
(if with_param is True, the model is equivalent to the GCN model)
If \(\beta = 0\), the model only focus on the node itself.
\[ \begin{align}\begin{aligned}\mathbf{\hat{A}} = \mathbf{\tilde{D}^{-\frac{1}{2}} \tilde{A} \tilde{D}^{-\frac{1}{2}}}\\\mathbf{X}^{(k+1)} = \left[\beta\mathbf{\hat{A}} + (1-\beta)\mathbf{I}\right] \mathbf{X}^{(k)}\end{aligned}\end{align} \]- Parameters:
beta (float) – The hyperparameter \(\beta\) to control the message attribution.
with_param (bool) – If set to True, the model will learn a linear transformation for node features.
in_dim (int) – Size of each input sample.
out_dim (int) – Size of each output sample.
bias (bool) – If set to False, no bias terms are added into the final output. Only available when with_param is True.
Shapes:
input:
node features \((|\mathcal{V}|, F_{in})\)
edge_index is sparse adjacency matrix \((|\mathcal{V}|, |\mathcal{V}|)\) or edge list \((2, |\mathcal{E}|)\)
output:
node features \((|\mathcal{V}|, F_{out})\)
- forward(x: Tensor, edge_index: Tensor, edge_weight: Tensor | None = None) Tensor[source]¶
Run lazy graph convolution with optional linear projection.
- Parameters:
x (Tensor) – Input node features.
edge_index (Union[Tensor, SparseTensor]) – Graph connectivity in edge-list or sparse adjacency format.
edge_weight (Optional[Tensor]) – Optional per-edge weights.
- Returns:
Output node features after lazy propagation.
- Return type:
Tensor
Example
>>> import torch >>> from rllm.nn.conv.graph_conv import LGCConv >>> conv = LGCConv(beta=0.5) >>> x = torch.randn(4, 8) >>> edge_index = torch.tensor([[0, 1, 2], [1, 2, 3]]) >>> out = conv(x, edge_index) >>> out.shape torch.Size([4, 8])