AdaGCN(in_dim, hid_dim, num_classes, mode='node', num_layers=3, dropout=0.0, act=F.relu, gnn_type='gcn', adv_dim=40, gp_weight=5, domain_weight=1, weight_decay=0.0, lr=0.004, epoch=100, device='cuda:0', batch_size=0, num_neigh=-1, verbose=2, **kwargs)

Bases: BaseGDA

Graph Transfer Learning via Adversarial Domain Adaptation with Graph Convolution (TKDE-22).

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: 3 ) –

    Total number of layers in model. Default: 3.

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

  • gnn_type (string, default: 'gcn' ) –

    Use GCN or PPMIConv. Default: gcn.

  • adv_dim (int, default: 40 ) –

    Hidden dimension of adversarial module. Default: 40.

  • gp_weight (float, default: 5 ) –

    Trade off parameter for gradient penalty. Default: 5.

  • domain_weight (float, default: 1 ) –

    Trade off parameter for domain loss. Default: 1.

  • lr (float, default: 0.004 ) –

    Learning rate. Default: 0.004.

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

fit(source_data, target_data)

Train the AdaGCN model.

Parameters:
  • source_data (Data) –

    Source domain graph data.

  • target_data (Data) –

    Target domain graph data.

Notes

Training process includes:

  • Setting up data loaders for both domains
  • Initializing GNN and discriminator
  • Training with adversarial learning
  • Supporting both node and graph level tasks
forward_model(source_data, target_data)

Forward pass of the model.

Parameters:
  • source_data (Data) –

    Source domain graph data.

  • target_data (Data) –

    Target domain graph data.

Returns:
  • tuple

    Contains: - loss : torch.Tensor Combined loss from classification and domain adaptation. - source_logits : torch.Tensor Model predictions for source domain. - target_logits : torch.Tensor Model predictions for target domain.

Notes

Performs adversarial training with:

  • Discriminator optimization
  • Gradient penalty computation
  • Classification loss
  • Domain adaptation loss
gradient_penalty(encoded_source, encoded_target)

Compute gradient penalty for Wasserstein GAN training.

Parameters:
  • encoded_source (Tensor) –

    Encoded features from source domain.

  • encoded_target (Tensor) –

    Encoded features from target domain.

Returns:
  • Tensor

    Computed gradient penalty value.

Notes

Implements Wasserstein GAN gradient penalty by:

  • Interpolating between source and target features
  • Computing gradients w.r.t. discriminator outputs
  • Penalizing gradients that deviate from norm 1
  • Handling different batch sizes between domains
init_model(**kwargs)

Initialize the AdaGCN model.

Parameters:
  • **kwargs

    Other parameters for the AdaGCNBase model.

Returns:
  • AdaGCNBase

    Initialized AdaGCN 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

Handles predictions for both source and target domains using appropriate data loaders.

process_graph(data)

Process the input graph data.

Parameters:
  • data (Data) –

    Input graph data to be processed.

Notes

Placeholder method for graph preprocessing.