StruRW(in_dim, hid_dim, num_classes, num_layers=2, cls_dim=128, cls_layers=2, dropout=0.0, gnn='GS', pooling='mean', reweight=True, pseudo=True, ew_start=100, ew_freq=20, lamb=0.8, mode='erm', act=F.relu, bn=False, weight_decay=0.0001, lr=0.05, epoch=100, device='cuda:0', batch_size=0, num_neigh=-1, verbose=2, **kwargs)
Bases: BaseGDA
Structural Re-weighting Improves Graph Domain Adaptation (ICML-23).
| Parameters: |
|
|---|
cal_edge_prob_sep(src_graph, tgt_graph, tgt_pred)
Calculate edge probabilities for source and target graphs.
| Parameters: |
|
|---|
| Returns: |
|
|---|
cal_reweight(source_data, target_data, target_pred)
Calculate edge weights for source graph based on structural alignment.
| Parameters: |
|
|---|
Notes
Updates source_data.edge_weight based on the ratio of edge probabilities between source and target domains.
cal_str_dif_rel(pred_mtx, true_mtx)
Calculate absolute and relative structural differences.
| Parameters: |
|
|---|
| Returns: |
|
|---|
cal_str_diff_ratio(pred_mtx, true_mtx)
Calculate structural difference ratio.
| Parameters: |
|
|---|
| Returns: |
|
|---|
calculate_str_diff(src_edge_prob, tgt_edge_prob, tgt_true_edge_prob)
Calculate multiple structural difference metrics between source and target graphs.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Computes four types of structural differences:
- Target prediction vs. true target (absolute and relative)
- Target prediction vs. source (absolute and relative)
- Ratio-based structural difference
- Log-based structural difference
fit(source_data, target_data)
Train the StruRW model on source and target domain data.
| Parameters: |
|
|---|
Notes
Training process includes:
Edge weight initialization:
- Sets default edge weights to 1 if not provided
- Handles both source and target graphs
Batch processing setup:
- Full batch (batch_size=0): Uses entire graph
- Mini-batch: Creates neighbor loaders with specified size
Model initialization:
- Sets up main model (GNN)
- For 'adv' mode: Initializes domain discriminator
- Configures optimizer based on training mode
Training loop:
- Updates edge weights periodically if reweighting is enabled
- Computes losses based on selected mode (erm/mixup/mmd/adv)
- Tracks and logs training metrics
The method adapts its behavior based on the selected training mode and handles both full-batch and mini-batch training scenarios.
forward_model(source_data, target_data, alpha, epoch)
Forward pass of the model for non-mixup modes.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Implements different training modes:
- 'erm': Standard cross-entropy loss
- 'adv': Adversarial training with domain discriminator
- 'mmd': Maximum Mean Discrepancy loss
forward_model_mixup(source_data, target_data, epoch)
Forward pass of the model for mixup mode.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Implements mixup training with beta distribution sampling and edge reweighting if enabled.
id_node(data, id_new_value_old)
Update graph structure based on new node indices.
| Parameters: |
|
|---|
| Returns: |
|
|---|
init_model(**kwargs)
Initialize the StruRW model.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Initializes different model architectures based on mode:
- 'mixup': Returns MixupBase model
- others: Returns ReweightGNN model with specified backbone
predict(data)
Make predictions on given data.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Handles both mixup and standard prediction modes.
process_graph(data)
Process the input graph data.
| Parameters: |
|
|---|
Notes
Placeholder method for graph preprocessing.
shuffle_data(data)
Shuffle node indices in the graph.
| Parameters: |
|
|---|
| Returns: |
|
|---|