SpecReg(in_dim, hid_dim, num_classes, num_layers=3, dropout=0.0, act=F.relu, ppmi=True, adv_dim=40, reg_mode=True, gamma_adv=0.1, thr_smooth=-1, gamma_smooth=0.01, thr_mfr=-1, gamma_mfr=0.01, weight_decay=0.003, lr=0.004, epoch=100, device='cuda:0', batch_size=0, num_neigh=-1, verbose=2, **kwargs)

Bases: BaseGDA

Graph Domain Adaptation via Theory-Grounded Spectral Regularization (ICLR-23).

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.003 ) –

    Weight decay (L2 penalty). Default: 0.003.

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

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

  • ppmi (bool, default: True ) –

    Use PPMI matrix or not. Default: True.

  • adv_dim (int, default: 40 ) –

    Hidden dimension of adversarial module. Default: 40.

  • reg_mode (bool, default: True ) –

    Use reg mode or adv mode. Default: True.

  • gamma_adv (float, default: 0.1 ) –

    Trade off parameter for adv. Default: 0.1.

  • thr_smooth (float, default: -1 ) –

    Spectral smoothness threshold. Default: -1.

  • gamma_smooth (float, default: 0.01 ) –

    Trade off parameter for spectral smoothness. Default: 0.01.

  • thr_mfr (float, default: -1 ) –

    Maximum Frequency Response threshold. Default: -1.

  • gamma_mfr (float, default: 0.01 ) –

    Trade off parameter for Maximum Frequency Response. Default: 0.01.

  • lr (float, default: 0.004 ) –

    Learning rate. Default: 0.001.

  • epoch (int, default: 100 ) –

    Maximum number of training epoch. Default: 100.

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

calculate_gradient_penalty(x_src, x_tgt)

Calculate gradient penalty for Wasserstein GAN training.

Parameters:
  • x_src (Tensor) –

    Source domain features.

  • x_tgt (Tensor) –

    Target domain features.

Returns:
  • Tensor

    Computed gradient penalty value.

Notes

Implements Wasserstein GAN gradient penalty by:

  • Interpolating between source and target features
  • Computing gradients of critic output
  • Penalizing gradients that deviate from norm 1
fit(source_data, target_data)

Train the SpecReg model.

Parameters:
  • source_data (Data) –

    Source domain graph data.

  • target_data (Data) –

    Target domain graph data.

Notes

Training process includes:

  • Setting up data loaders
  • Initializing model, critic, and optimizers
  • Alternating training between:
    • Critic optimization (Wasserstein distance)
    • Model optimization with spectral regularization
  • Computing and logging training metrics
forward_model(source_data, target_data, alpha, epoch)

Forward pass of the model.

Parameters:
  • source_data (Data) –

    Source domain graph data.

  • target_data (Data) –

    Target domain graph data.

  • alpha (float) –

    Gradient reversal scaling parameter.

  • epoch (int) –

    Current training epoch.

Returns:
  • tuple

    Contains: - loss : torch.Tensor Combined loss from multiple components. - source_logits : torch.Tensor Model predictions for source domain. - target_logits : torch.Tensor Model predictions for target domain.

Notes

Computes multiple loss terms:

  • Classification loss on source domain
  • Wasserstein distance with gradient penalty
  • Spectral smoothness regularization (if reg_mode)
  • Maximum Frequency Response regularization (if reg_mode)
  • Entropy minimization on target domain
init_model(**kwargs)

Initialize the SpecReg model.

Parameters:
  • **kwargs

    Other parameters for the UDAGCNBase model.

Returns:
  • UDAGCNBase

    Initialized UDAGCN model on the specified device.

predict(data, source=False)

Make predictions on given data.

Parameters:
  • data (Data) –

    Input graph data.

  • source (bool, default: False ) –

    Whether the input is from source domain. Default: False.

Returns:
  • tuple

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

Notes

Uses appropriate encoder based on domain (source/target).

process_graph(data)

Process the input graph data.

Parameters:
  • data (Data) –

    Input graph data to be processed.

Notes

Placeholder method for graph preprocessing.