PageRank(k=5, alpha=0.9, **kwargs)
Bases: MessagePassing
Implementation of PageRank algorithm as a message passing layer.
This class implements a personalized PageRank algorithm that can be used as a message passing layer in graph neural networks. It performs k iterations of random walk with restart to compute node importance scores.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
Notes
The PageRank computation follows these steps:
-
Normalize edge weights using GCN normalization
-
For k iterations:
-
Propagate messages along edges
-
Combine with restart probability
-
-
Return final node importance scores
The message passing follows the formula: x = (1 - alpha) * propagate(x) + alpha * hidden, where hidden is the initial node features.
forward(x, edge_index, edge_weight=None)
Forward pass of the PageRank layer.
| Parameters: |
|
|---|
| Returns: |
|
|---|
message(x_j, norm)
Compute messages for each edge.
| Parameters: |
|
|---|
| Returns: |
|
|---|
SEPA(in_dim, hid_dim, num_classes, num_layers=2, dropout=0.0, gnn='gcn', lamda_im=0.2, lamda_pp=0.1, lamda_sep=1.0, tau=1.5, act=F.relu, weight_decay=0.01, lr=0.001, epoch=200, device='cuda:0', batch_size=0, num_neigh=-1, verbose=2, **kwargs)
Bases: BaseGDA
Structure Enhanced Prototypical Alignment for Unsupervised Cross-Domain Node Classification (NN-24).
| Parameters: |
|
|---|
cls_im(prob)
Compute information maximization loss for domain adaptation.
This function calculates the information maximization loss which consists of two components:
- Diversity loss: Encourages the model to make diverse predictions across classes
- Entropy loss: Minimizes the uncertainty of predictions
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
The loss is computed as:
- Diversity loss: -sum(mean_prob * log(mean_prob))
- Entropy loss: mean(-sum(prob * log(prob)))
where mean_prob is the average probability distribution across samples
fit(source_data, target_data)
Train the SEPA model.
| Parameters: |
|
|---|
Notes
The training process includes:
- Creating data loaders for both domains
- Initializing the GNN model and optimizer
- Training for specified number of epochs
- Logging training progress (loss and micro-F1 score)
forward_model(source_data, target_data)
Forward pass of the SEPA model for domain adaptation.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
This function requires batch training (batch_size > 0) as specified in the model initialization. The implementation should handle batched data from both source and target domains.
init_model(**kwargs)
Initialize the SEPA model.
| Parameters: |
|
|---|
| Returns: |
|
|---|
obtain_source_prototype(feat, label)
Compute class prototypes for source domain features.
This function calculates the mean feature vector (prototype) for each class in the source domain by averaging the features of samples belonging to the same class.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
The prototype for each class is computed as: center = sum(features * onehot) / sum(onehot), where onehot is the one-hot encoding of class labels
predict(data)
Make predictions using the trained model.
| Parameters: |
|
|---|
| Returns: |
|
|---|
process_graph(data)
Process the input graph data.
| Parameters: |
|
|---|
Notes
This is a placeholder method that should be implemented by subclasses if graph preprocessing is needed.
proto_alignment(target_proto, source_proto)
Compute prototype alignment loss between source and target domains.
This function calculates a loss that aligns class prototypes between source and target domains using InfoNCE loss. It encourages similar classes to have similar prototypes across domains while maintaining discriminability between different classes.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
The alignment loss is computed using InfoNCE loss with three components:
- Target-Source similarity: Measures alignment between corresponding classes
- Target-Target similarity: Ensures target prototypes are discriminable
- Source-Source similarity: Ensures source prototypes are discriminable
The loss is computed as:
-
Normalize prototypes to unit length
-
Compute cosine similarity matrices between:
- Target and source prototypes (ts)
- Target and target prototypes (tt)
- Source and source prototypes (ss)
-
Apply temperature scaling (tau)
-
Calculate InfoNCE loss using positive pairs (same class) and negative pairs (different classes)
The loss encourages:
- High similarity between corresponding class prototypes across domains
- Low similarity between different class prototypes within each domain
seperate_center(center, feat, label)
Compute separation loss between class prototypes to enhance class discriminability.
This function calculates a loss that encourages class prototypes to be well-separated in the feature space by maximizing the distance between different class prototypes while minimizing the distance between samples of the same class.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
The separation loss is computed using InfoNCE loss:
- Normalize prototypes to unit length
- Compute cosine similarity matrix between prototypes
- Apply temperature scaling (tau) to the similarity scores
- Calculate InfoNCE loss by comparing positive pairs (same class) against negative pairs (different classes)
The loss encourages:
- High similarity between samples of the same class
- Low similarity between samples of different classes