GTrans(in_dim, hid_dim, num_classes, num_layers=3, dropout=0.0, act=F.relu, loop_adj=1, loop_feat=4, ratio=0.1, margin=-1, make_undirected=True, strategy='dropedge', weight_decay=0.0, lr=0.0001, epoch=500, gnn='gcn', device='cuda:0', batch_size=0, num_neigh=-1, verbose=2, **kwargs)
Bases: BaseGDA
Empowering Graph Representation Learning with Test-Time Graph Transformation (ICLR-23).
| Parameters: |
|
|---|
augment(feat, edge_index=None, edge_weight=None, p=0.5, strategy='dropedge')
Apply graph augmentation for contrastive learning.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Supports two strategies:
- dropedge: Randomly drops edges
- shuffle: Randomly shuffles node features
fit(source_data, target_data)
Train the GTrans model with test-time graph transformation.
| Parameters: |
|
|---|
Notes
Implementation steps:
Source Training
- Pretrains model on source domain
- Freezes model parameters after source training
Target Adaptation
- Initializes feature and structure perturbations
- Alternates between feature and structure optimization
- Uses test-time loss for adaptation
- Maintains perturbation budget constraints
Edge Sampling
- Samples final edge structure
- Ensures connectivity constraints
- Maintains undirected property if specified
forward_model(data, **kwargs)
Forward pass placeholder for GTrans model.
| Parameters: |
|
|---|
Notes
Placeholder method as GTrans implements custom forward logic through:
- Source domain training in train_source()
- Test-time adaptation in fit()
- Prediction using transformed graphs in predict()
init_model(**kwargs)
Initialize the GTrans base model.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Configures base GNN model with:
- Specified backbone architecture (GCN by default)
- Layer dimensions and dropout
- Activation functions
predict(data)
Make predictions using transformed graph.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
- Uses optimized feature and structure
- Applies final graph transformation
- Returns predictions and ground truth
process_graph(data)
Process input graph data.
| Parameters: |
|
|---|
Notes
Placeholder method as graph processing is handled through:
- Feature perturbation optimization
- Structure modification via edge sampling
- Graph augmentation strategies in augment()
- Test-time transformation procedures
sample_final_edges(n_perturbations, perturbed_edge_weight, data, modified_edge_index, n)
Sample final edge structure based on learned weights.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
- Uses iterative sampling strategy
- Maintains best performing structure
- Ensures perturbation budget constraints
- Handles undirected graph requirements
test_time_loss(feat, edge_index, edge_weight=None)
Compute test-time adaptation loss.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
- Implements contrastive learning objective
- Uses different augmentation strategies
- Supports margin-based loss variant
- Compares different graph views
train_source(optimizer)
Train the model on source domain data.
| Parameters: |
|
|---|
Notes
- Performs standard supervised training on source domain
- Computes cross-entropy loss on labeled data
- Tracks and logs training metrics
- Uses full batch training only
update_edge_weights(gradient, optimizer_adj, perturbed_edge_weight)
Update edge weights using gradient information.
| Parameters: |
|
|---|
Notes
- Applies gradient updates to edge weights
- Maintains minimum weight threshold
- Uses Adam optimizer for updates