spamosaic.architectures.hg_lgcn
- class spamosaic.architectures.hg_lgcn.HG_LGCN(*args: Any, **kwargs: Any)[source]
Bases:
ModuleFull Heterogeneous Graph LightGCN network with encoder-decoder architecture.
This module uses HG_LGCN_vanilla for graph feature encoding and a customizable decoder for reconstruction.
- Parameters:
input_size (int) – Dimensionality of input node features.
output_size (int) – Dimension of the latent embedding.
K (int, default=8) – Number of LightGCN layers.
dec_l (int, default=1) – Number of layers in the decoder (1 = linear decoder).
hidden_size (int, default=512) – Size of hidden layer in the MLP head.
dropout (float, default=0.2) – Dropout rate used in MLP head.
- forward(feature, edge_index, edge_weight, edge_type)[source]
Returns: - Latent embedding (L2-normalized). - Reconstructed feature from decoder.
- forward(feature, edge_index, edge_weight, edge_type)[source]
Forward pass for HG_LGCN model.
- Parameters:
feature (torch.Tensor) – Input node features.
edge_index (torch.LongTensor) – COO edge list.
edge_weight (torch.Tensor) – Edge weights.
edge_type (torch.Tensor) – Edge type indicators.
- Returns:
Normalized latent representation (embedding).
Reconstructed feature tensor.
- Return type:
Tuple[torch.Tensor, torch.Tensor]
- class spamosaic.architectures.hg_lgcn.HG_LGCN_Conv(*args: Any, **kwargs: Any)[source]
Bases:
MessagePassingHeterogeneous Graph LightGCN convolution layer.
This layer handles intra-group and inter-group message passing separately, applying degree-normalized edge weights and combining both feature streams.
- Inherits from:
torch_geometric.nn.conv.MessagePassing
- forward(x, edge_index, edge_weight, edge_type)[source]
Executes the forward pass using intra- and inter-group edge types.
- forward(x, edge_index, edge_weight, edge_type)[source]
Forward pass for heterogeneous LightGCN convolution.
- Parameters:
x (torch.Tensor) – Input node features, shape (N, F).
edge_index (torch.LongTensor) – Edge list in COO format, shape (2, E).
edge_weight (torch.Tensor) – Edge weights, shape (E,).
edge_type (torch.Tensor) – Edge type indicator: 1 for intra-group, 0 for inter-group.
- Returns:
Concatenated features from intra-group and inter-group aggregations.
- Return type:
torch.Tensor
- class spamosaic.architectures.hg_lgcn.HG_LGCN_vanilla(*args: Any, **kwargs: Any)[source]
Bases:
ModuleStacked HG_LGCN_Conv layers with layer-wise feature concatenation.
- Parameters:
num_layers (int) – Number of HG_LGCN_Conv layers to stack.
- forward(x, edge_index, edge_weight, edge_type)[source]
Executes stacked HG_LGCN_Conv layers and concatenates intermediate features.
- forward(x, edge_index, edge_weight, edge_type)[source]
Forward pass of stacked HG_LGCN layers.
- Parameters:
x (torch.Tensor) – Input node features.
edge_index (torch.LongTensor) – Edge list in COO format.
edge_weight (torch.Tensor) – Weights for each edge.
edge_type (torch.Tensor) – Indicator for intra/inter group edges.
- Returns:
Concatenated node features from all layers.
- Return type:
torch.Tensor
Classes
Full Heterogeneous Graph LightGCN network with encoder-decoder architecture. |
|
Heterogeneous Graph LightGCN convolution layer. |
|
Stacked HG_LGCN_Conv layers with layer-wise feature concatenation. |