GraphRoute
GraphRoute is a graph-based dynamic ensemble selection framework. Given a pool of candidate models, a GNN trained over a sample similarity graph learns which models to trust for individual cases. Because different models have different inductive biases, their reliability varies across the input space. GraphRoute learns sample representations where proximity better reflects shared model competence. This approach is particularly valuable for problems where models optimized for aggregate performance tend to fail on rare edge cases, and where failures on such cases are the most consequential.
GraphRoute operates in three stages:
- Train a pool of diverse models.
- Construct a graph where nodes represent samples and edges encode sample similarity.
- Train a GNN to produce per-classifier competence scores.
- Installation
- Quickstart
- Data and model interface
- Configure Experiments
- Configuration
- Reusing a trained pool
- Development
Installation
pip install graphroute
GraphRoute requires Python 3.10–3.12, PyTorch 2.0 or newer, and PyTorch Geometric 2.4 or newer.
The quickstart and experiment runner are repository-level scripts. To use them, clone the repository and follow the development installation.
Quickstart
python quickstart.py
The quickstart trains a pool of four lightweight models on synthetic data, fits a graph attention network (GAT), and compares the performance of the resulting GNN's dynamic selection with the individual classifiers and fixed ensemble baselines.
Data and model interface
GraphRoute accepts PyTorch Dataset objects whose samples are (inputs, target) pairs. Datasets with
custom sample structures can provide a collate_fn; see the fit_graphroute
function documentation in
graphroute/run.py
for the required interface. Supply the candidate model instances through the
ordered models list.
Configure Experiments
run_experiments.py
reads the experiment configuration from
configs/experiment.yaml
and model factories from
model_registry.py.
Register candidate models in MODEL_REGISTRY, specify their names in
base.models, and run:
python run_experiments.py --config configs/experiment.yaml
The provided YAML defines one experiment. Uncomment its optional sweep
section to run the Cartesian product of the listed values. Each completed
configuration and its metrics are saved as a separate JSON file under
results/<dataset>/. Repeating the command skips completed configurations.
Use --force to rerun completed configurations.
With the default data_dir="data", GraphRoute reads train.pt and test.pt
from data/<dataset>/; each file must contain an (inputs, targets) tuple saved
using torch.save. validation.pt is optional. When it is absent, GraphRoute
derives validation data from the training set using val_ratio.
Configuration
Every available setting and its default is defined in
graphroute/config.py.
The YAML file uses the same field names. The tables below focus on settings
whose options require an understanding of GraphRoute itself.
General
| Argument | Meaning | Available options |
|---|---|---|
loss_target |
Sets the GNN training objective. | "meta_labels": minimizes the loss between predicted competence scores and targets that encode each model’s competence."ensemble": minimizes the loss between the combined prediction and each sample’s ground-truth class label or regression target. |
Model pool training (base)
| Argument | Meaning | Available options |
|---|---|---|
base.models |
Names the ordered model pool using entries in the experiment registry. | Nonempty list of registered model names |
base.split_mode |
Chooses how the pool produces out-of-sample predictions for GNN training. | "oof_stacking", "split_train" |
base.oof_folds |
Sets the number of folds used for OOF pool training. | Integer of at least 2 |
To use all of the training data to train both the base classifiers and the GNN without the optimistic bias caused by evaluating models on their own training samples, base.split_mode="oof_stacking" uses cross-validation to generate out-of-fold predictions for GNN training. The final classifiers used for inference are then trained on the full training set.
split_train is less computationally expensive because each base classifier is trained only once. It divides the training data into two parts: one is used to train the base classifiers, and the other is used to train the GNN.
Graph construction (graph)
| Argument | Meaning | Available options |
|---|---|---|
graph.node_feature_source |
Selects the sample representation supplied to the GNN. |
"decision_space": concatenated pool predictions for the sample."feature_space": original features (flattened if not tabular already)."embedding_mean": averages internal representation each model produces for the sample immediately before its final layer (requires same size embeddings)."embedding_concat": concatenates internal representation each model produces for the sample immediately before its final layer (embedding sizes may differ)."hybrid": decision-space representation and original features concatenated.
|
graph.edge_feature_source |
Selects the representation used to measure similarity when constructing graph edges. | |
graph.k |
Sets the number of neighbors per sample. | Positive integer |
graph.neighbor_mode |
Selects ordinary nearest neighbors or class-balanced neighbors. | "knn", "class_balanced" |
graph.weight_mode |
Determines how sample-to-sample edge weights are calculated. | "softmax", "uniform", "inverse_distance", "cmdw" |
graph.pool_calibrate |
Enables or disables classification-pool calibration. | True, False |
graph.calib_method |
Selects the calibration method. | "ts-mix", "logistic" |
When oof_stacking is combined with embedding-based representations, GraphRoute uses out-of-fold predictions for GNN training, but extracts embeddings from the final base classifiers.
GNN training and dynamic selection (gnn)
| Argument | Meaning | Available options |
|---|---|---|
gnn.arch |
Selects the architecture used to learn the dynamic selection rule. | "gat", "graph_gps", "mlp" |
gnn.loss |
Selects the GNN training loss. | "bce", "focal_bce", "soft_bce", "regression" |
gnn.ens_combination_mode |
Determines how model scores form the final prediction. | "soft_weighted_voting", "hard_weighted_voting", "soft_voting", "hard_voting", "weighted_mean" for regression |
gnn.voting_weight_space |
Selects how GNN scores become voting weights; when omitted, GraphRoute chooses based on loss_target. |
None, "logit", "sig" |
gnn.fallback |
Selects the fallback rule when no model receives a positive selection weight. | "uniform", "wacc", "acc", "bacc" |
Reusing a trained pool
GraphRoute automatically caches the results of the computation-heavy base-model training stage under pool_cache//pool_/. The cache includes the final trained pool models and the model outputs required to construct the graph and train the GNN. The pool-configuration-hash identifies the specified model architectures and configuration for training base classifiers. Changing only the configuration for graph construction or GNN training leaves the hash unchanged, allowing the trained pool to be reused. Because dataset is part of the pool-cache path, use a different dataset name or delete the existing cache when the underlying data or preprocessing changes. Otherwise, GraphRoute may reuse stale models or predictions.
Development
Development installation
git clone https://github.com/briannamueller/GraphRoute.git
cd GraphRoute
pip install -e .
pytest -q
The quickstart and test suite run offline on CPU.
License
MIT -- see LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphroute-0.1.0.tar.gz.
File metadata
- Download URL: graphroute-0.1.0.tar.gz
- Upload date:
- Size: 68.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65b2b9d3d38cf265d015e3b759323eb74787510652abca7a64830c80a63f32df
|
|
| MD5 |
299c6fa08f68cab2378c67fd8b4856dd
|
|
| BLAKE2b-256 |
341346fa36426db7b00ff092f86088a02c189d8c222ec8e9b25e708ee1264388
|
Provenance
The following attestation bundles were made for graphroute-0.1.0.tar.gz:
Publisher:
publish.yml on briannamueller/GraphRoute
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphroute-0.1.0.tar.gz -
Subject digest:
65b2b9d3d38cf265d015e3b759323eb74787510652abca7a64830c80a63f32df - Sigstore transparency entry: 2690014787
- Sigstore integration time:
-
Permalink:
briannamueller/GraphRoute@3b5289667f45675b2c8f047abb176b454e19e8f8 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/briannamueller
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3b5289667f45675b2c8f047abb176b454e19e8f8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file graphroute-0.1.0-py3-none-any.whl.
File metadata
- Download URL: graphroute-0.1.0-py3-none-any.whl
- Upload date:
- Size: 54.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa8122f0cf982bcf4ac9ff9c6de21f7146e2afe130e146b2f51e14b99b921be9
|
|
| MD5 |
380cb53b64afb21797dccb5a0f840a26
|
|
| BLAKE2b-256 |
c1e7b6a48050c9329594ac234cc5c58e2dcc6f5d5df6081035760e622c56ebef
|
Provenance
The following attestation bundles were made for graphroute-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on briannamueller/GraphRoute
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
graphroute-0.1.0-py3-none-any.whl -
Subject digest:
aa8122f0cf982bcf4ac9ff9c6de21f7146e2afe130e146b2f51e14b99b921be9 - Sigstore transparency entry: 2690014897
- Sigstore integration time:
-
Permalink:
briannamueller/GraphRoute@3b5289667f45675b2c8f047abb176b454e19e8f8 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/briannamueller
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3b5289667f45675b2c8f047abb176b454e19e8f8 -
Trigger Event:
release
-
Statement type: