CWGCN(in_dim, hid_dim, num_classes, mode='node', num_layers=2, dropout=0.0, gnn='gcn', act=F.relu, weight_decay=0.0001, lr=0.001, epoch=200, device='cuda:0', batch_size=0, num_neigh=-1, verbose=2, **kwargs)

Bases: BaseGDA

Correntropy-Induced Wasserstein GCN: Learning Graph Embedding via Domain Adaptation (TIP-2023).

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

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

    GNN backbone. Default: gcn.

  • weight_decay (float, default: 0.0001 ) –

    Weight decay (L2 penalty). Default: 0.0001.

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

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

  • lr (float, default: 0.001 ) –

    Learning rate. Default: 0.001.

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

fit(source_data, target_data)

Train the CWGCN model in two steps.

Parameters:
  • source_data (Data) –

    Source domain graph data.

  • target_data (Data) –

    Target domain graph data.

Notes

Training process consists of two main steps:

Step 1: Source Domain Training

  • Initializes data loaders based on mode (node/graph)
  • Trains model with correntropy-induced loss
  • Updates all model parameters
  • Monitors source domain performance

Step 2: Target Domain Adaptation

  • Freezes classification layer parameters
  • Computes source domain statistics
  • Aligns feature distributions
  • Minimizes mean and variance discrepancy
  • Tracks target domain performance

Implementation Details:

  • Supports both node and graph-level tasks
  • Handles full-batch and mini-batch processing
  • Uses Adam optimizer with weight decay
  • Implements comprehensive logging
forward_model(source_data)

Forward pass of the CWGCN model.

Parameters:
  • source_data (Data) –

    Source domain graph data.

Returns:
  • tuple

    Contains: - loss : torch.Tensor Correntropy-induced loss. - source_logits : torch.Tensor Model predictions. - weight : torch.Tensor Sample weights from correntropy. - x_list : list List of intermediate representations.

Notes

Handles both node and graph-level tasks with appropriate batch processing.

get_src_mean_std(embedding, weight)

Calculate weighted mean and standard deviation of source embeddings.

Parameters:
  • embedding (Tensor) –

    Source domain embeddings.

  • weight (Tensor) –

    Sample weights from correntropy.

Returns:
  • tuple

    Contains: - mean_e : torch.Tensor Weighted mean of embeddings. - var_e : torch.Tensor Bias-corrected standard deviation.

Notes

Implements:

  • Weighted mean computation
  • Bias-corrected variance estimation
  • Proper normalization with sample weights
init_model(**kwargs)

Initialize the CWGCN base model.

Parameters:
  • **kwargs

    Additional parameters for model initialization.

Returns:
  • CWGCNBase

    Initialized model with specified architecture parameters.

Notes

Configures model with:

  • Selected GNN backbone (gcn, sage, gat, or gin)
  • Two-layer architecture
  • Mode-specific settings (node/graph)
  • Dropout and activation functions
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
  • Handles both node and graph-level predictions
  • Processes data in batches if specified
  • Concatenates results for full predictions
process_graph(data)

Process the input graph data.

Parameters:
  • data (Data) –

    Input graph data to be processed.

Notes

Placeholder method for potential graph preprocessing. Current implementation focuses on direct feature usage.