Skip to content

spatialfusion.models.gcn

spatialfusion.models.gcn

GCN-based autoencoder model for node feature reconstruction and optional classification.

This module provides: - GCNAutoencoder: Graph convolutional autoencoder with masked node input and optional classification head.

GCNAutoencoder

Bases: Module

Graph Convolutional Network (GCN) autoencoder with optional classification head.

The model performs masked node feature reconstruction using stacked GCN layers. During training, a fraction of node features is replaced by a learnable mask token and corrupted with noise. The latent node embeddings can optionally be passed through a classification head.

Parameters:

Name Type Description Default
in_dim int

Input feature dimension.

required
hidden_dim int

Hidden layer dimensionality.

required
out_dim int

Output feature dimension for reconstruction.

required
node_mask_ratio float

Fraction of nodes to mask during training.

0.1
num_layers int

Number of GCN layers in the encoder.

1
dropout float

Dropout probability applied during training.

0.2
noise_std float

Standard deviation of Gaussian noise added to masked inputs.

0.1
n_classes int

Number of classes for node classification. If 0, no classification head is used.

0

__init__(in_dim, hidden_dim, out_dim, node_mask_ratio=0.1, num_layers=1, dropout=0.2, noise_std=0.1, n_classes=0)

Initialize the GCN autoencoder.

Parameters:

Name Type Description Default
in_dim int

Input node feature dimension.

required
hidden_dim int

Hidden layer size for GCN encoder.

required
out_dim int

Output feature dimension for reconstruction.

required
node_mask_ratio float

Fraction of nodes to mask during training.

0.1
num_layers int

Number of GCN layers.

1
dropout float

Dropout probability.

0.2
noise_std float

Standard deviation of Gaussian noise applied to inputs.

0.1
n_classes int

Number of output classes for classification. If greater than zero, a classification head is created.

0

encode(g, feat)

Encode node features using stacked GCN layers.

Parameters:

Name Type Description Default
g DGLGraph

Input DGL graph.

required
feat Tensor

Input node feature tensor of shape (num_nodes, in_dim).

required

Returns:

Type Description
Tensor

Tensor of shape (num_nodes, hidden_dim) containing latent node embeddings.

forward(g)

Forward pass of the GCN autoencoder.

The forward pass performs: 1. Random node masking 2. Noise injection and dropout 3. GCN encoding 4. Feature reconstruction 5. Optional node classification

Parameters:

Name Type Description Default
g DGLGraph

Input DGL graph with node features stored in g.ndata["feat"].

required

Returns:

Type Description

A tuple (x_recon, x_original, node_mask, z, logits) where: - x_recon: Reconstructed node features. - x_original: Original input node features. - node_mask: Boolean mask indicating masked nodes. - z: Latent node embeddings. - logits: Classification logits if n_classes > 0, otherwise None.