DGSDA(in_dim, hid_dim, num_classes, mode='node', num_layers=2, dropout=0.0, act=F.relu, K=8, alpha=0.05, beta=0.5, gamma=0.05, weight_decay=0.0, lr=0.004, epoch=200, device='cuda:0', batch_size=0, num_neigh=-1, verbose=2, **kwargs)

Bases: BaseGDA

Disentangled Graph Spectral Domain Adaptation (ICML-25).

Parameters:
  • in_dim (int) –

    Input feature dimension.

  • hid_dim (int) –

    Hidden dimension of model.

  • num_classes (int) –

    Total number of classes.

  • mode (str, default: 'node' ) –

    Mode for node or graph level tasks. Default: node.

  • num_layers (int, default: 2 ) –

    Total number of layers in model. Default: 2.

  • dropout (float, default: 0.0 ) –

    Dropout rate. Default: 0..

  • weight_decay (float, default: 0.0 ) –

    Weight decay (L2 penalty). Default: 0..

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

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

  • K (int, default: 8 ) –

    Order of the polynomial filter. Default: 8.

  • alpha (float, default: 0.05 ) –

    Theta loss trade-off parameter. Default: 0.05.

  • beta (float, default: 0.5 ) –

    MMD loss trade-off parameter. Default: 0.5.

  • gamma (float, default: 0.05 ) –

    Entropy loss trade-off parameter. Default: 0.05.

  • lr (float, default: 0.004 ) –

    Learning rate. Default: 0.004.

  • epoch (int, default: 200 ) –

    Maximum number of training epoch. Default: 200.

  • 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.

Examples:

>>> from pygda.models import DGSDA
>>> model = DGSDA(in_dim=128, hid_dim=64, num_classes=7)
>>> model.fit(source_data, target_data)
>>> logits, labels = model.predict(test_data)
entropy_minimization_loss(output)

Compute entropy minimization loss for target domain regularization.

Parameters:
  • output (Tensor) –

    Model predictions of shape [num_nodes, num_classes].

Returns:
  • Tensor

    Entropy minimization loss value.

Notes

The entropy minimization loss is computed as:

  • Compute softmax probabilities from logits
  • Calculate class-wise prediction frequencies
  • Compute weighted entropy loss that penalizes uncertain predictions more heavily for classes with higher prediction frequencies
fit(source_data, target_data)

Train the DGSDA model on source and target domain data.

Parameters:
  • source_data (Data) –

    Source domain graph data.

  • target_data (Data) –

    Target domain graph data.

Notes

The training process includes:

  1. Data Loader Setup: Creates appropriate data loaders based on the task mode (node/graph) and batch size settings.

  2. Model Initialization: Initializes the DGSDA model with specified architecture parameters.

  3. Optimization: Uses Adam optimizer with specified learning rate and weight decay for parameter updates.

  4. Training Loop: For each epoch:

    • Processes batches of source and target data

    • Computes multi-component loss

    • Updates model parameters

    • Logs training metrics (loss, accuracy, time)

  5. Evaluation: Computes micro-F1 score on source domain for monitoring training progress.

The method supports both node-level and graph-level tasks, though currently only node-level tasks are fully implemented.

forward_model(source_data, target_data)

Forward pass of the DGSDA model.

Parameters:
  • source_data (Data) –

    Source domain graph data containing node features, edge indices, and labels.

  • target_data (Data) –

    Target domain graph data containing node features, edge indices, and labels.

Returns:
  • tuple

    Contains:

    • loss : torch.Tensor Total training loss combining multiple loss components.

    • source_logits : torch.Tensor Source domain predictions.

Notes

The forward pass computes multiple loss components:

  • Source domain cross-entropy loss for supervised learning
  • Temperature parameter L1 loss between source and target domains
  • Maximum Mean Discrepancy (MMD) loss for domain alignment
  • Entropy minimization loss for target domain regularization
init_model(**kwargs)

Initialize the DGSDA base model.

Parameters:
  • **kwargs

    Additional parameters for model initialization.

Returns:
  • DGSDABase

    Initialized model with specified architecture parameters.

predict(data, source=False)

Make predictions on input data.

Parameters:
  • data (Data) –

    Input graph data.

  • source (bool, default: False ) –

    Whether predicting on source domain. Default: False.

Returns:
  • tuple

    Contains:

    • logits : torch.Tensor Model predictions.

    • labels : torch.Tensor True labels.

Notes

The prediction process:

  1. Model Evaluation: Sets the model to evaluation mode to disable dropout and batch normalization updates.

  2. Data Processing: Uses the appropriate data loader (source or target) based on the source parameter.

  3. Inference: Performs forward pass without gradient computation for efficient inference.

  4. Result Aggregation: Concatenates predictions from multiple batches if the data is processed in batches.

The method automatically handles both source and target domain prediction modes, with different processing pipelines for each.

process_graph(data)

Process the input graph data.

Parameters:
  • data (Data) –

    Input graph data to be processed.

Notes

This method is currently a placeholder as preprocessing is handled through the NeighborLoader and DataLoader classes during training and prediction phases.