PairAlign(in_dim, hid_dim, num_classes, num_layers=2, cls_dim=128, cls_layers=2, dropout=0.0, backbone='GS', pooling='mean', ew_type='pseudobeta', rw_lmda=1.0, ls_lambda=1.0, lw_lambda=0.005, label_rw=False, edge_rw=False, ew_start=0, ew_freq=10, lw_start=0, lw_freq=10, gamma_reg=0.0001, weight_CE_src=False, bn=False, 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
Pairwise Alignment Improves Graph Domain Adaptation (ICML-24).
| Parameters: |
|
|---|
CE_loss(pred, label)
Standard cross-entropy loss computation.
| Parameters: |
|
|---|
| Returns: |
|
|---|
CE_loss_weight(pred, label, label_weight, weight_src)
Weighted cross-entropy loss with label-specific weights.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
- Combines class weights and label weights
- Supports optional source domain weighting
- Normalizes by number of classes
- Handles both balanced and imbalanced scenarios
CE_srcweight_loss(pred, label)
Weighted cross-entropy loss for source domain.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
- Computes inverse frequency weights for classes
- Applies class-specific weights to loss
- Handles class imbalance in source domain
LS_optimization(cov, muhat_tgt, mu_src, lambda_reg)
Perform least squares optimization for weight computation.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
-
Solves constrained optimization problem:
- Minimizes L2 distance between transformed source and target
- Includes regularization towards uniform weights
- Maintains probability constraints
-
Prints covariance matrix rank for debugging
- Uses CVXPY with SCS solver
cal_edge_prob_sep(src_graph, tgt_graph)
Calculate separate edge probabilities for source and target domains.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Implementation steps:
- Converts sparse adjacency to dense format
- Creates one-hot label encodings using sparse matrices
- Computes class-conditional edge probabilities
- Normalizes by node counts per class
calc_edge_rw_pseudo(src_graph, tgt_graph, yhat_src, yhat_tgt)
Calculate edge reweighting using pseudo-labels.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Implementation steps:
Edge Feature Computation
- Constructs sparse edge features for both domains
- Uses einsum for efficient tensor operations
- Handles class-conditional edge probabilities
Distribution Alignment
- Computes covariance and mean statistics
- Performs least squares optimization
- Applies ratio-based weight calculation
Weight Processing
- Handles numerical edge cases (inf, nan)
- Updates graph edge weights
- Computes alignment metrics
calc_label_rw(y_src, y_hat_tgt, cov, lambda_reg)
Calculate label reweighting coefficients using constrained optimization.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
-
Solves a quadratic program with:
- L2 loss between transformed and target distributions
- L2 regularization towards uniform weights
- Sum-to-one and non-negativity constraints
-
Uses CVXPY with SCS solver for optimization
calc_ratio_weight(src_graph, kmm_weight, gamma_reg)
Calculate edge ratio weights using kernel mean matching.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
- Computes class-conditional edge probabilities
- Applies regularization for stability
- Handles edge probability ratios between domains
- Maintains probability constraints
calc_true_beta(src_graph, tgt_graph)
Calculate true beta values for edge distribution alignment.
| Parameters: |
|
|---|
Notes
- Creates edge class matrices for both domains
- Computes edge class probabilities
- Calculates ratio between target and source probabilities
- Handles numerical edge cases (inf, nan)
- Stores results in source graph for reference
- Maintains class-pair relationships in edge classification
calc_true_ew(src_graph, tgt_graph)
Calculate true edge weights between source and target domains.
| Parameters: |
|
|---|
Notes
- Computes edge probability ratios
- Handles numerical stability with gamma regularization
- Stores true edge weights for reference
calc_true_lw(src_graph, tgt_graph)
Calculate true label weights between domains.
| Parameters: |
|
|---|
Notes
- Computes class distribution in both domains
- Calculates ratio of target to source distributions
- Stores true weights and initializes current weights
- Uses one-hot encoding for label processing
fit(source_data, target_data)
Train the PairAlign model on source and target domain data.
| Parameters: |
|
|---|
Notes
Training process includes:
Initial Setup
- Edge weight initialization
- Data loader configuration
- True weight calculations (edge, label, beta)
Training Loop
- Forward pass with reweighting
- Loss computation and optimization
- Periodic weight updates
- Performance monitoring
forward_model(source_data, target_data, epoch)
Forward pass of the PairAlign model.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
- Updates edge weights periodically if edge_rw is enabled
- Updates label weights periodically if label_rw is enabled
- Handles both weighted and unweighted classification losses
init_model(**kwargs)
Initialize the PairAlign base model.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Configures model with:
- GNN backbone with specified dimensions
- Classification layers
- Reweighting mechanisms for edges and labels
predict(data)
Make predictions on input data.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
- Evaluates model in inference mode
- Returns both predictions and ground truth
process_graph(data)
Process input graph data.
| Parameters: |
|
|---|
Notes
Placeholder method as preprocessing is handled by:
- Edge weight calculation
- Label weight computation
- Beta value estimation
update_ew(src_data, tgt_data, pred_src, pred_tgt)
Update edge weights based on domain alignment.
| Parameters: |
|
|---|
Notes
-
Supports multiple edge weight calculation methods:
- pseudobeta: Dynamic weight calculation
- truth: Uses true edge weights
- other: Ratio-based weight calculation
-
Updates edge weights in source graph
update_lw(src_data, tgt_data, pred_src, pred_tgt)
Update label weights for domain alignment.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
- Computes label distribution alignment
- Uses least squares optimization with regularization
- Maintains probability constraints