spamosaic.architectures.wlgcn

Weighted Light graph convolution (WLGCN) layers for SpaMosaic.

Implements a parameter-free propagation layer on pre-normalized sparse adjacencies and an MLP head for embedding + reconstruction.

class spamosaic.architectures.wlgcn.HEAD(*args: Any, **kwargs: Any)[source]

Bases: Module

MLP head that outputs an L2-normalized embedding and reconstructs input features.

Parameters:
  • input_size (int) – Input feature dimension.

  • output_size (int) – Embedding dimension.

  • dec_l (int, default=1) – Number of decoder layers (1 = linear decoder).

  • hidden_size (int, default=512) – Hidden size of the MLP trunk.

  • dropout (float, default=0.2) – Dropout rate.

  • slope (float, default=0.2) – Negative slope for LeakyReLU.

forward(feature)[source]

Forward pass.

Parameters:

feature (torch.Tensor) – Input features of shape [N, input_size].

Returns:

  • z: L2-normalized embedding [N, output_size].

  • r: Reconstructed features [N, input_size] from pre-norm representation.

Return type:

tuple[torch.Tensor, torch.Tensor]

class spamosaic.architectures.wlgcn.WLGCN_vanilla(*args: Any, **kwargs: Any)[source]

Bases: Module

Parameter-free LightGCN-style propagation.

Accepts a precomputed normalized sparse adjacency \(\hat{A} \approx D^{-1/2}(A + I\cdot\text{fill})D^{-1/2}\) as a torch_sparse.SparseTensor.

Parameters:
  • K (int, default=1) – Number of propagation steps (returns K+1 representations including the 0-th order input).

  • agg ({'cat', 'sum', 'mean'}, default='cat') – How to aggregate representations across steps.

forward(x: torch.Tensor, A_hat: torch_sparse.SparseTensor) torch.Tensor[source]

Propagate features via A_hat for K steps and aggregate.

Parameters:
  • x (torch.Tensor) – Node features of shape [N, F].

  • A_hat (torch_sparse.SparseTensor) – Pre-normalized sparse adjacency on the correct device.

Returns:

Aggregated output. Shapes depend on agg: - 'cat'[N, F * (K+1)] - 'sum'[N, F] - 'mean'[N, F]

Return type:

torch.Tensor

Classes

spamosaic.architectures.wlgcn.HEAD

MLP head that outputs an L2-normalized embedding and reconstructs input features.

spamosaic.architectures.wlgcn.WLGCN_vanilla

Parameter-free LightGCN-style propagation.