GRADE(in_dim, hid_dim, num_classes, mode='node', num_layers=2, dropout=0.0, act=F.relu, disc='JS', weight=0.01, weight_decay=0.01, lr=0.001, epoch=200, device='cuda:0', batch_size=0, num_neigh=-1, verbose=2, **kwargs)

Bases: BaseGDA

Non-IID Transfer Learning on Graphs (AAAI-23).

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

    Weight decay (L2 penalty). Default: 0.01.

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

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

  • disc (str, default: 'JS' ) –

    Discriminator. Default: JS.

  • weight (int, default: 0.01 ) –

    Loss trade-off parameter. Default: 0.01.

  • lr (float, default: 0.001 ) –

    Learning rate. Default: 0.001.

  • epoch (int, default: 200 ) –

    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 GRADE model.

Parameters:
  • source_data (Data) –

    Source domain graph data.

  • target_data (Data) –

    Target domain graph data.

Notes

Training process includes:

  • Setting up appropriate data loaders based on mode (node/graph)
  • Initializing model and optimizer
  • Training with dynamic gradient reversal parameter
  • Supporting both node-level and graph-level tasks
  • Computing and logging training metrics
forward_model(source_data, target_data, alpha)

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.

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

Computes multiple loss terms:

  • Cross entropy loss for source domain
  • Domain adaptation loss (JS-divergence, MMD, or Conditional)
  • Weighted combination of both losses
init_model(**kwargs)

Initialize the GRADE model.

Parameters:
  • **kwargs

    Other parameters for the GRADEBase model.

Returns:
  • GRADEBase

    Initialized GRADE 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 data loader based on domain (source/target)
  • Returns both logits and ground truth labels
  • Handles batched predictions for large graphs
process_graph(data)

Process the input graph data.

Parameters:
  • data (Data) –

    Input graph data to be processed.

Notes

Placeholder method for graph preprocessing.