DGDA(in_dim, hid_dim, num_classes, num_layers=3, dropout=0.0, act=F.relu, dec_dim=64, d_dim=64, y_dim=256, m_dim=128, recons_w=1.0, beta=0.5, ent_w=1.0, d_w=1.0, y_w=1.0, m_w=0.1, edge_drop_rate=0.1, edge_add_rate=0.1, weight_decay=0.0005, lr=0.001, epoch=400, device='cuda:0', batch_size=0, num_neigh=-1, verbose=2, **kwargs)

Bases: BaseGDA

Graph Domain Adaptation: A Generative View (TKDD-24).

Parameters:
  • in_dim (int) –

    Input feature dimension.

  • hid_dim (int) –

    Hidden dimension of model.

  • num_classes (int) –

    Total number of classes.

  • num_layers (int, default: 3 ) –

    Total number of layers in model. Default: 3.

  • dropout (float, default: 0.0 ) –

    Dropout rate. Default: 0..

  • weight_decay (float, default: 0.0005 ) –

    Weight decay (L2 penalty). Default: 0.0005.

  • act (callable activation function or None, default: relu ) –

    Activation function if not None. Default: torch.nn.functional.relu.

  • dec_dim (int, default: 64 ) –

    Dimension of the graph decoder hidden layer. Default: 64.

  • d_dim (int, default: 64 ) –

    Dimension of the domain latent variables. Default: 64.

  • y_dim (int, default: 256 ) –

    Dimension of the semantic latent variables. Default: 256.

  • m_dim (int, default: 128 ) –

    Dimension of the random latent variables. Default: 128.

  • recons_w (float, default: 1.0 ) –

    Trade-off weight for reconstruction loss. Default: 1.0.

  • beta (float, default: 0.5 ) –

    Trade-off weight for kl loss. Default: 0.5.

  • ent_w (float, default: 1.0 ) –

    Trade-off weight for entropy loss. Default: 1.0.

  • d_w (float, default: 1.0 ) –

    Trade-off weight for domain loss. Default: 1.0.

  • y_w (float, default: 1.0 ) –

    Trade-off weight for cross entropy loss. Defalut: 1.0.

  • m_w (float, default: 0.1 ) –

    Trade-off weight for manipulating reconstruction loss. Defalut: 0.1.

  • lr (float, default: 0.001 ) –

    Learning rate. Default: 0.001.

  • epoch (int, default: 400 ) –

    Maximum number of training epoch. Default: 400.

  • device (str, default: 'cuda:0' ) –

    GPU or CPU. Default: cuda:0.

  • batch_size (int, default: 0 ) –

    Minibatch size, 0 for full batch training. Default: 0.

  • num_neigh (int, default: -1 ) –

    Number of neighbors in sampling, -1 for all neighbors. Default: -1.

  • verbose (int, default: 2 ) –

    Verbosity mode. Range in [0, 3]. Larger value for printing out more log information. Default: 2.

  • **kwargs

    Other parameters for the model.

DGDA_loss(res, labels, adj, domain, manipulate=False, dadj=None)

Compute the combined loss for DGDA training.

Parameters:
  • res (dict) –

    Model outputs including reconstructions and latent variables.

  • labels (Tensor) –

    Ground truth labels.

  • adj (Tensor) –

    Adjacency matrix.

  • domain (int) –

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

  • manipulate (bool, default: False ) –

    Whether using manipulated graphs. Default: False.

  • dadj (Tensor, default: None ) –

    Difference adjacency matrix for manipulation.

Returns:
  • Tensor

    Combined loss value.

Notes

Combines multiple loss terms:

  • Graph reconstruction loss
  • KL divergence for three latent spaces
  • Classification loss (source only)
  • Domain adversarial loss
  • Maximum entropy regularization
drop_edges(adj, drop_rate=0.0, add_rate=0.0)

Perform edge manipulation for data augmentation.

Parameters:
  • adj (Tensor) –

    Original adjacency matrix.

  • drop_rate (float, default: 0.0 ) –

    Probability of edge dropping. Default: 0.0.

  • add_rate (float, default: 0.0 ) –

    Rate of edge addition. Default: 0.0.

Returns:
  • tuple

    Contains: - nadj : torch.Tensor New adjacency matrix after manipulation. - dadj : torch.Tensor Difference matrix showing changes.

Notes
  • Maintains graph symmetry
  • Preserves self-loops
  • Controls sparsity level
fit(source_data, target_data)

Train the DGDA model on source and target domain data.

Parameters:
  • source_data (Data) –

    Source domain graph data.

  • target_data (Data) –

    Target domain graph data.

Notes

Training process consists of multiple stages:

Pretraining Stage

  • DeepWalk pretraining for source domain
  • DeepWalk pretraining for target domain
  • Embedding initialization

Main Training Loop

  • Processes original graphs
  • Computes multiple losses:

    • Reconstruction loss
    • KL divergence for latent spaces
    • Classification loss
    • Domain adversarial loss
    • Entropy maximization

Manipulation Training

  • Edge dropping and addition
  • Additional reconstruction objectives
  • Structure preservation
forward_model(source_data, target_data)

Forward pass of the DGDA model.

Parameters:
  • source_data (Data) –

    Source domain graph data.

  • target_data (Data) –

    Target domain graph data.

Notes

Placeholder method as the main forward logic is implemented in the fit method, which handles:

  • Multiple latent space encoding
  • Graph reconstruction
  • Domain discrimination
  • Classification
  • Edge manipulation

The complex nature of DGDA's generative approach requires integrated processing of both domains with access to the full training context, hence implementation in fit method.

init_model(**kwargs)

Initialize the DGDA base model.

Parameters:
  • **kwargs

    Additional parameters for model initialization.

Returns:
  • DGDABase

    Initialized model with specified architecture parameters.

Notes

Configures model with:

  • Encoder-decoder architecture
  • Multiple latent spaces (domain, semantic, random)
  • Pretrained embeddings for both domains
  • GCN backbone for feature extraction
kl_loss(mu, lv)

Compute KL divergence loss for variational inference.

Parameters:
  • mu (Tensor) –

    Mean of the latent distribution.

  • lv (Tensor) –

    Log variance of the latent distribution.

Returns:
  • Tensor

    KL divergence loss normalized by number of nodes.

max_entropy(x)

Compute maximum entropy regularization.

Parameters:
  • x (Tensor) –

    Input logits.

Returns:
  • Tensor

    Entropy loss term.

Notes

Encourages uniform distribution in latent spaces.

predict(data)

Make predictions on target domain data.

Parameters:
  • data (Data) –

    Input graph data.

Returns:
  • tuple

    Contains: - logits : torch.Tensor Model predictions. - labels : torch.Tensor True labels.

Notes

Uses stored graph structure and features for consistent prediction.

process_graph(data)

Process the input graph data.

Parameters:
  • data (Data) –

    Input graph data to be processed.

Notes

Placeholder method for potential preprocessing steps:

  • Graph structure normalization
  • Feature preprocessing
  • Edge weight computation
  • Adjacency matrix preparation

Currently not implemented as preprocessing is handled in the fit method through DeepWalk pretraining and edge manipulation procedures.

recons_loss(recons, adjs)

Compute weighted binary cross-entropy loss for graph reconstruction.

Parameters:
  • recons (Tensor) –

    Reconstructed adjacency matrix.

  • adjs (Tensor) –

    Original adjacency matrix.

Returns:
  • Tensor

    Weighted reconstruction loss.

Notes
  • Handles class imbalance with positive edge weighting
  • Normalizes based on graph size
  • Ensures non-negative loss values