examples.complementarity.py¶
Complementarity Analysis for Graph Datasets using RINGS Framework
This script demonstrates how to: 1. Load a graph dataset from PyTorch Geometric 2. Apply various RINGS perturbations to the graph data 3. Compute complementarity metrics
- Usage (from root directory):
python -m examples.complementarity –dataset MUTAG –perturbation original
- For more options:
python -m examples.complementarity –help
- examples.complementarity.get_available_perturbations()[source]¶
Return a list of available perturbation names with descriptions.
- Returns:
Mapping from perturbation name to description
- Return type:
dict
- examples.complementarity.create_perturbation(name, seed=42)[source]¶
Create a perturbation transform based on the given name and seed.
- Parameters:
name (str) – Name of the perturbation
seed (int) – Random seed for reproducible perturbations
- Returns:
A transform that can be applied to graph data
- Return type:
BaseTransform
- examples.complementarity.apply_perturbation(dataset, perturbation)[source]¶
Apply a perturbation to all graphs in a dataset.
- Parameters:
dataset – PyTorch Geometric dataset
perturbation – Transform to apply
- Returns:
List of transformed graph data objects
- Return type:
list
- examples.complementarity.create_complementarity_functor(n_jobs=1)[source]¶
Create a ComplementarityFunctor with standard parameters.
The ComplementarityFunctor measures the difference between: 1. The metric space of node features (using euclidean distance) 2. The metric space of graph structure (using shortest path distance)
- Parameters:
n_jobs (int) – Number of parallel jobs (-1 for all cores)
- Returns:
Configured functor
- Return type:
- examples.complementarity.compute_complementarity(dataloader, functor)[source]¶
Compute complementarity scores for all graphs in the dataloader.
- Parameters:
dataloader – PyTorch Geometric dataloader containing graphs
functor – ComplementarityFunctor to compute scores
- Returns:
Array of complementarity scores
- Return type:
numpy.ndarray
- examples.complementarity.main()[source]¶
Main function to run the complementarity analysis.
- User inputs are handled via command line arguments:
–perturbation: “Perturbation to apply to the dataset (default: original)” –dataset: “Name of the TU dataset to use (default: MUTAG)” –seed: “Random seed for reproducibility (default: 42)” –batch-size: “Batch size for dataloader (default: 32)” –n-jobs: “Number of parallel jobs (-1 for all cores, default: 1)”