SOGA(in_dim, hid_dim, num_classes, num_layers=3, dropout=0.0, act=F.relu, num_negative_samples=5, num_positive_samples=2, struct_lambda=1.0, neigh_lambda=1.0, weight_decay=0.0, lr=0.004, epoch=200, gnn='gcn', device='cuda:0', batch_size=0, num_neigh=-1, verbose=2, **kwargs)

Bases: BaseGDA

Source Free Graph Unsupervised Domain Adaptation (WSDM-24).

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

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

    GNN backbone. Default: gcn.

  • num_negative_samples (int, default: 5 ) –

    The number of negative samples in NCE loss. Default: 5.

  • num_positive_samples (int, default: 2 ) –

    The number of positive samples in NCE loss. Default: 2.

  • struct_lambda (float, default: 1.0 ) –

    Structure NCE loss weight. Default: 1.0.

  • neigh_lambda (float, default: 1.0 ) –

    Neighborhood NCE loss weight. Default: 1.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.

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

NCE_loss(outputs, center_nodes, positive_samples, negative_samples)

Compute Noise Contrastive Estimation loss.

Parameters:
  • outputs (Tensor) –

    Model output probabilities.

  • center_nodes (Tensor) –

    Indices of center nodes.

  • positive_samples (Tensor) –

    Indices of positive samples.

  • negative_samples (Tensor) –

    Indices of negative samples.

Returns:
  • Tensor

    NCE loss value.

Notes
  • Implements InfoNCE-style contrastive loss
  • Handles both structural and neighborhood contrasts
  • Uses temperature-scaled dot product similarity
div(softmax_output)

Calculate diversity loss.

Parameters:
  • softmax_output (Tensor) –

    Softmax probabilities.

Returns:
  • Tensor

    Diversity loss value.

Notes
  • Computes negative entropy of mean predictions
  • Encourages uniform class distribution
ent(softmax_output)

Calculate mean entropy across samples.

Parameters:
  • softmax_output (Tensor) –

    Softmax probabilities.

Returns:
  • Tensor

    Mean entropy loss.

entropy(x)

Calculate entropy of probability distribution.

Parameters:
  • x (Tensor) –

    Input probability distribution.

Returns:
  • Tensor

    Computed entropy values.

Notes
  • Handles numerical stability with epsilon
  • Computes per-sample entropy
fit(source_data, target_data)

Train the SOGA model on source and target domains.

Parameters:
  • source_data (Data) –

    Source domain graph data.

  • target_data (Data) –

    Target domain graph data.

Notes

Training process:

Source Pretraining

  • Supervised training on source domain
  • Classification loss optimization

Target Adaptation

  • Unsupervised adaptation
  • NCE loss for structure and neighborhood
  • Information maximization
forward_model(data, **kwargs)

Forward pass placeholder for SOGA model.

Parameters:
  • data (Data) –

    Input graph data.

  • **kwargs

    Additional arguments.

Notes

Placeholder method as SOGA implements custom forward logic through:

  • Source domain training in train_source()
  • Target domain adaptation in train_target()
  • Prediction using adapted model in predict()
  • NCE-based contrastive learning
init_model(**kwargs)

Initialize the SOGA base model.

Parameters:
  • **kwargs

    Additional parameters for model initialization.

Returns:
  • SOGABase

    Initialized model with specified parameters.

Notes

Configures model with:

  • GNN backbone architecture
  • NCE loss parameters
  • Sampling configurations
  • Model dimensions and dropout
predict(data)

Make predictions on target domain data.

Parameters:
  • data (Data) –

    Input graph data.

Returns:
  • tuple

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

Notes
  • Evaluates model in inference mode
  • Handles batch processing
  • Concatenates predictions for full graph
process_graph(data)

Process input graph data.

Parameters:
  • data (Data) –

    Input graph to be processed.

Notes

Placeholder method as graph processing is handled through:

  • Positive/negative sample generation
  • Neighborhood structure analysis
  • Information maximization computations
  • Batch-wise data handling in training methods
train_source(optimizer)

Train the model on source domain data.

Parameters:
  • optimizer (Optimizer) –

    Optimizer for model parameters.

Notes
  • Performs supervised training on source domain
  • Uses cross-entropy loss for classification
  • Tracks training metrics and loss
  • Handles batch processing if specified
train_target(target_data, optimizer)

Adapt the model to target domain.

Parameters:
  • target_data (Data) –

    Target domain graph data.

  • optimizer (Optimizer) –

    Optimizer for model parameters.

Notes

Implementation includes:

  • Initialization of target domain samples
  • NCE loss computation for structure and neighborhood
  • Information maximization loss
  • Combined optimization objective