BatchGIN(in_features, hidden_size, out_features)

Bases: Module

Batch Graph Isomorphism Network layer implementation.

Parameters:
  • in_features (int) –

    Number of input features.

  • hidden_size (int) –

    Size of hidden layer.

  • out_features (int) –

    Number of output features.

forward(x, adj)

Forward pass of GIN layer.

Parameters:
  • x (Tensor) –

    Node feature matrix, shape (batch_size, num_nodes, in_features).

  • adj (Tensor) –

    Batch of adjacency matrices, shape (batch_size, num_nodes, num_nodes).

Returns:
  • Tensor

    Updated node features, shape (batch_size, num_nodes, out_features).

Notes

Process:

  1. Neighborhood aggregation with self-loop
  2. Two-layer MLP transformation
  3. Dropout regularization
BatchGraphConvolution(in_features, out_features, bias=True)

Bases: Module

Batch-wise graph convolution layer.

Parameters:
  • in_features (int) –

    Number of input features.

  • out_features (int) –

    Number of output features.

  • bias (bool, default: True ) –

    Whether to include bias. Default: True.

__repr__()

String representation of the module.

Returns:
  • str

    String describing the layer's dimensions.

Notes

Format: "BatchGraphConvolution(in_features -> out_features)" Used for model printing and debugging.

forward(x, adj)

Forward pass of the graph convolution layer.

Parameters:
  • x (Tensor) –

    Node feature matrix, shape (num_nodes, in_features).

  • adj (Tensor) –

    Adjacency matrix, shape (num_nodes, num_nodes).

Returns:
  • Tensor

    Convolved node features, shape (num_nodes, out_features).

BatchMultiHeadGraphAttention(n_head, in_features, out_features, attn_dropout)

Bases: Module

Multi-head graph attention layer with batch processing.

Parameters:
  • n_head (int) –

    Number of attention heads.

  • in_features (int) –

    Number of input features.

  • out_features (int) –

    Number of output features per head.

  • attn_dropout (float) –

    Dropout rate for attention weights.

__repr__()

String representation of the module.

Returns:
  • str

    String describing the layer's dimensions.

Notes

Format: "BatchMultiHeadGraphAttention(in_features -> out_features)" Used for model printing and debugging.

forward(x, adj)

Forward pass of multi-head attention layer.

Parameters:
  • x (Tensor) –

    Input features, shape (batch_size, num_nodes, in_features).

  • adj (Tensor) –

    Adjacency matrices, shape (batch_size, num_nodes, num_nodes).

Returns:
  • Tensor

    Attended node features, shape (batch_size, num_nodes, n_head * out_features).

Notes

Process:

  1. Linear projection to n_head spaces
  2. Compute attention scores
  3. Apply masked softmax
  4. Compute output
ClassClassifier(hs, n_class, droprate)

Bases: Module

Node classification network.

Parameters:
  • hs (int) –

    Hidden state dimension.

  • n_class (int) –

    Number of output classes.

  • droprate (float) –

    Dropout rate for regularization.

Notes

Two-layer MLP with dropout and ReLU activation.

forward(x)

Forward pass of classifier.

Parameters:
  • x (Tensor) –

    Input features, shape (n_nodes, hs).

Returns:
  • Tensor

    Classification logits, shape (n_nodes, n_class).

Notes

Process:

  1. Hidden layer with dropout and ReLU
  2. Output layer for class logits
DGDABase(in_dim, num_class, enc_hs, dec_hs, dim_d, dim_y, dim_m, droprate, backbone, source_pretrained_emb, source_vertex_feats, target_pretrained_emb, target_vertex_feats)

Bases: Module

Base class for DGDA.

Parameters:
  • in_dim (int) –

    Input feature dimension.

  • num_class (int) –

    Number of classes.

  • enc_hs (int) –

    Encoder hidden size.

  • dec_hs (int) –

    Decoder hidden size.

  • dim_d (int) –

    Domain space dimension.

  • dim_y (int) –

    Label space dimension.

  • dim_m (int) –

    Manipulation space dimension.

  • droprate (float) –

    Dropout rate.

  • backbone (str) –

    GNN backbone type.

  • source_pretrained_emb (Tensor) –

    Pretrained embeddings for source domain.

  • source_vertex_feats (Tensor) –

    Vertex features for source domain.

  • target_pretrained_emb (Tensor) –

    Pretrained embeddings for target domain.

  • target_vertex_feats (Tensor) –

    Vertex features for target domain.

Notes

Implements graph disentanglement with:

  1. Feature augmentation with pretrained embeddings
  2. Multi-space encoding (domain, label, manipulation)
  3. Graph reconstruction and noise modeling
  4. Domain adversarial training
forward(x, vts, adj, domain, recon=True, alpha=1.0)

Forward pass of DGDA model.

Parameters:
  • x (Tensor) –

    Input features.

  • vts (Tensor) –

    Vertex indices.

  • adj (Tensor) –

    Adjacency matrix.

  • domain (int) –

    Domain indicator (0: source, 1: target).

  • recon (bool, default: True ) –

    Whether to compute reconstruction. Default: True.

  • alpha (float, default: 1.0 ) –

    Gradient reversal scaling. Default: 1.0.

Returns:
  • dict

    Contains: - 'd', 'y', 'm': Latent representations - 'a_recons': Graph reconstruction - 'm_recons': Noise reconstruction - 'dom_output': Domain predictions - 'cls_output': Class predictions

Notes

Process flow:

  1. Feature augmentation
  2. Graph encoding
  3. Reconstruction (optional)
  4. Domain and class prediction
DomainClassifier(dim_d)

Bases: Module

Binary domain classifier for adversarial training.

Parameters:
  • dim_d (int) –

    Dimension of domain space features.

Notes

Single linear layer for binary domain classification. Typically used with gradient reversal for domain adaptation.

forward(x)

Forward pass of domain classifier.

Parameters:
  • x (Tensor) –

    Input features from domain space, shape (n_nodes, dim_d).

Returns:
  • Tensor

    Domain classification logits, shape (n_nodes, 1).

Notes

Simple linear projection for binary domain classification. Used in conjunction with gradient reversal layer during training.

GNN_VGAE_Encoder(in_dim, hs, dim_d, dim_y, dim_m, droprate, backbone='gcn')

Bases: Module

Variational Graph Auto-Encoder with multiple latent spaces.

Parameters:
  • in_dim (int) –

    Input feature dimension.

  • hs (int) –

    Hidden state dimension.

  • dim_d (int) –

    Domain space dimension.

  • dim_y (int) –

    Label space dimension.

  • dim_m (int) –

    Manipulation space dimension.

  • droprate (float) –

    Dropout rate.

  • backbone (str, default: 'gcn' ) –

    GNN backbone type ('gcn', 'gat', 'gin').

Notes

Encodes graph into three separate latent spaces:

  • Domain space (d)
  • Label space (y)
  • Manipulation space (m)
forward(x, adj)

Forward pass of the VGAE encoder.

Parameters:
  • x (Tensor) –

    Input features, shape (batch_size, num_nodes, in_dim).

  • adj (Tensor) –

    Adjacency matrices, shape (batch_size, num_nodes, num_nodes).

Returns:
  • tuple
    • dict: Contains latent representations and their parameters:
      • 'd', 'y', 'm': Sampled latent vectors
      • 'dmu', 'dlv': Domain space parameters
      • 'ymu', 'ylv': Label space parameters
      • 'mmu', 'mlv': Manipulation space parameters
    • torch.Tensor: Final hidden representations
Notes

Process:

  1. Graph normalization (for GCN backbone)
  2. Two-layer message passing
  3. Parallel encoding into three spaces
  4. Reparameterization for each space
repara(mu, lv)

Reparameterization trick for VAE.

Parameters:
  • mu (Tensor) –

    Mean vectors.

  • lv (Tensor) –

    Log variance vectors.

Returns:
  • Tensor

    Sampled vectors from the distribution.

vectorized_sym_norm(adjs)

Compute symmetric normalization of adjacency matrices.

Parameters:
  • adjs (Tensor) –

    Batch of adjacency matrices, shape (batch_size, num_nodes, num_nodes).

Returns:
  • Tensor

    Normalized adjacency matrices.

GraphDecoder(dec_hs, dim_d, dim_y, dim_m, droprate)

Bases: Module

Multi-space graph decoder for structure reconstruction.

Parameters:
  • dec_hs (int) –

    Decoder hidden state dimension.

  • dim_d (int) –

    Domain space dimension.

  • dim_y (int) –

    Label space dimension.

  • dim_m (int) –

    Manipulation space dimension.

  • droprate (float) –

    Dropout rate for regularization.

Notes

Reconstructs graph structure from three disentangled spaces:

  • Domain space (d)
  • Label space (y)
  • Manipulation space (m)
forward(d, y, m)

Forward pass of graph decoder.

Parameters:
  • d (Tensor) –

    Domain space features, shape (n_nodes, dim_d).

  • y (Tensor) –

    Label space features, shape (n_nodes, dim_y).

  • m (Tensor) –

    Manipulation space features, shape (n_nodes, dim_m).

Returns:
  • Tensor

    Reconstructed adjacency matrix, shape (n_nodes, n_nodes).

Notes

Process:

  1. Independent transformation of each space
  2. Concatenation of transformed features
  3. Final projection to common space
  4. Symmetric matrix construction via outer product
GraphDiscriminator(in_dim, hs, droprate)

Bases: Module

Graph-level discriminator for adversarial training.

Parameters:
  • in_dim (int) –

    Input feature dimension.

  • hs (int) –

    Hidden state dimension.

  • droprate (float) –

    Dropout rate for regularization.

Notes

Implements a graph-level discriminator with:

  1. Feature transformation
  2. Mean pooling
  3. Binary classification
forward(x)

Forward pass of graph discriminator.

Parameters:
  • x (Tensor) –

    Input node features, shape (n_nodes, in_dim).

Returns:
  • Tensor

    Graph-level discrimination logits, shape (1,).

Notes

Process:

  1. Node feature transformation with dropout
  2. Mean pooling across nodes
  3. Final classification layer
NoiseDecoder(dim_m, droprate)

Bases: Module

Decoder network for reconstructing noise patterns in graph structure.

Parameters:
  • dim_m (int) –

    Dimension of manipulation space features.

  • droprate (float) –

    Dropout rate for regularization.

forward(x)

Forward pass of noise decoder.

Parameters:
  • x (Tensor) –

    Input features from manipulation space, shape (n_nodes, dim_m).

Returns:
  • Tensor

    Reconstructed noise matrix, shape (n_nodes, n_nodes).

Notes

Process:

  1. Two-layer MLP transformation
  2. Symmetric matrix construction via outer product