Skip to content

Commit 052a62e

Browse files
authored
Merge pull request #1 from automl/dev
Initial version of HyperSHAP in a usable state
2 parents ac2ac11 + 6d431a0 commit 052a62e

27 files changed

Lines changed: 4452 additions & 155 deletions

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
runs-on: ubuntu-latest
3030
strategy:
3131
matrix:
32-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
32+
python-version: ["3.11", "3.12", "3.13"]
3333
fail-fast: false
3434
defaults:
3535
run:
@@ -47,7 +47,7 @@ jobs:
4747
run: uv run python -m pytest tests --cov --cov-config=pyproject.toml --cov-report=xml
4848

4949
- name: Check typing
50-
run: uv run mypy
50+
run: uv run pyright
5151

5252

5353
- name: Upload coverage reports to Codecov with GitHub Action on Python 3.11

.github/workflows/on-release-main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,3 @@ jobs:
6464

6565
- name: Deploy documentation
6666
run: uv run mkdocs gh-deploy --force
67-

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,6 @@ cython_debug/
209209
marimo/_static/
210210
marimo/_lsp/
211211
__marimo__/
212+
213+
# IDE project files
214+
.idea

CONTRIBUTING.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing to `hypershap`
1+
# Contributing to `HyperSHAP`
22

33
Contributions are welcome, and they are greatly appreciated!
44
Every little bit helps, and credit will always be given.
@@ -9,7 +9,7 @@ You can contribute in many ways:
99

1010
## Report Bugs
1111

12-
Report bugs at https://github.com/mwever/hypershap/issues
12+
Report bugs at https://github.com/automl/HyperSHAP/issues
1313

1414
If you are reporting a bug, please include:
1515

@@ -29,11 +29,11 @@ Anything tagged with "enhancement" and "help wanted" is open to whoever wants to
2929

3030
## Write Documentation
3131

32-
hypershap could always use more documentation, whether as part of the official docs, in docstrings, or even on the web in blog posts, articles, and such.
32+
HyperSHAP could always use more documentation, whether as part of the official docs, in docstrings, or even on the web in blog posts, articles, and such.
3333

3434
## Submit Feedback
3535

36-
The best way to send feedback is to file an issue at https://github.com/mwever/hypershap/issues.
36+
The best way to send feedback is to file an issue at https://github.com/automl/HyperSHAP/issues.
3737

3838
If you are proposing a new feature:
3939

@@ -44,22 +44,22 @@ If you are proposing a new feature:
4444

4545
# Get Started!
4646

47-
Ready to contribute? Here's how to set up `hypershap` for local development.
47+
Ready to contribute? Here's how to set up `HyperSHAP` for local development.
4848
Please note this documentation assumes you already have `uv` and `Git` installed and ready to go.
4949

50-
1. Fork the `hypershap` repo on GitHub.
50+
1. Fork the `HyperSHAP` repo on GitHub.
5151

5252
2. Clone your fork locally:
5353

5454
```bash
5555
cd <directory_in_which_repo_should_be_created>
56-
git clone git@github.com:YOUR_NAME/hypershap.git
56+
git clone git@github.com:YOUR_NAME/HyperSHAP.git
5757
```
5858

5959
3. Now we need to install the environment. Navigate into the directory
6060

6161
```bash
62-
cd hypershap
62+
cd HyperSHAP
6363
```
6464

6565
Then, install and activate the environment with:

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ check: ## Run code quality tools.
1010
@uv lock --locked
1111
@echo "🚀 Linting code: Running pre-commit"
1212
@uv run pre-commit run -a
13-
@echo "🚀 Static type checking: Running mypy"
14-
@uv run mypy
13+
@echo "🚀 Static type checking: Running pyright"
14+
@uv run pyright
1515
@echo "🚀 Checking for obsolete dependencies: Running deptry"
1616
@uv run deptry src
1717

README.md

Lines changed: 109 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,143 @@
1-
# hypershap
1+
# HyperSHAP
22

33
[![Release](https://img.shields.io/github/v/release/mwever/hypershap)](https://img.shields.io/github/v/release/mwever/hypershap)
44
[![Build status](https://img.shields.io/github/actions/workflow/status/mwever/hypershap/main.yml?branch=main)](https://github.com/mwever/hypershap/actions/workflows/main.yml?query=branch%3Amain)
55
[![codecov](https://codecov.io/gh/mwever/hypershap/branch/main/graph/badge.svg)](https://codecov.io/gh/mwever/hypershap)
66
[![Commit activity](https://img.shields.io/github/commit-activity/m/mwever/hypershap)](https://img.shields.io/github/commit-activity/m/mwever/hypershap)
77
[![License](https://img.shields.io/github/license/mwever/hypershap)](https://img.shields.io/github/license/mwever/hypershap)
88

9-
HyperSHAP is a post-hoc explanation method for hyperparameter optimization.
9+
HyperSHAP a game‑theoretic Python library for explaining Hyperparameter Optimization (HPO). It uses Shapley values and interaction indices to provide both local and global insights into how individual hyper‑parameters (and their interactions) affect a model’s performance.
1010

11-
- **Github repository**: <https://github.com/mwever/hypershap/>
12-
- **Documentation** <https://mwever.github.io/hypershap/>
11+
- **Github repository**: <https://github.com/automl/hypershap/>
12+
- **Documentation** <https://automl.github.io/hypershap/>
1313

14-
## Getting started with your project
1514

16-
### 1. Create a New Repository
15+
## Table of Contents
16+
- [Features](#features)
17+
- [Installation](#installation)
18+
- [Getting Started](#getting-started)
19+
- [API Overview](#api-overview)
20+
- [Example Notebook](#example-notebook)
21+
- [Citation](#citation)
22+
- [Contributing](#contributing)
23+
- [License](#license)
1724

18-
First, create a repository on GitHub with the same name as this project, and then run the following commands:
25+
---
1926

20-
```bash
21-
git init -b main
22-
git add .
23-
git commit -m "init commit"
24-
git remote add origin git@github.com:mwever/hypershap.git
25-
git push -u origin main
26-
```
27+
## Features
28+
- **Additive Shapley decomposition** of any performance metric across hyper‑parameters.
29+
- **Interaction analysis** via the Faithful Shapley Interaction Index (FSII).
30+
- Ready‑made explanation tasks for **Ablation**, **Tunability**, and **Optimizer Bias** studies.
31+
- Integrated **visualisation** (SI‑graph) for interaction effects.
32+
- Works with any surrogate model that follows the `ExplanationTask` interface.
2733

28-
### 2. Set Up Your Development Environment
34+
---
2935

30-
Then, install the environment and the pre-commit hooks with
36+
## Installation
3137

32-
```bash
33-
make install
38+
```sh
39+
$ make install
3440
```
3541

36-
This will also generate your `uv.lock` file
42+
## Getting Started
43+
Given an existing setup with a ConfigurationSpace from the [ConfigSpace package](https://github.com/automl/ConfigSpace) and black-box function as follows:
44+
```Python
45+
from ConfigSpace import ConfigurationSpace, Configuration
3746

38-
### 3. Run the pre-commit hooks
47+
# ConfigurationSpace describing the hyperparameter space
48+
cs = ConfigurationSpace()
49+
...
3950

40-
Initially, the CI/CD pipeline might be failing due to formatting issues. To resolve those run:
51+
# A black-box function, evaluating ConfigSpace.Configuration objects
52+
def blackbox_function(cfg: Configuration) -> float:
53+
...
54+
```
55+
56+
You can use HyperSHAP as follows:
57+
```Python
58+
from hypershap import ExplanationTask, HyperSHAP
4159

42-
```bash
43-
uv run pre-commit run -a
60+
# Instantiate HyperSHAP
61+
hypershap = HyperSHAP(ExplanationTask.from_function(config_space=cs,function=blackbox_function))
62+
# Conduct tunability analysis
63+
hypershap.tunability(baseline_config=cs.get_default_configuration())
64+
# Plot results as a Shapley Interaction graph
65+
hypershap.plot_si_graph()
4466
```
4567

46-
### 4. Commit the changes
68+
The example demonstrates how to:
69+
1. Wrap a black-box function in an explanation task.
70+
2. Use `HyperSHAP` to obtain interaction values for the **tunability** game.
71+
3. Plot the corresponding SI-graph.
4772

48-
Lastly, commit the changes made by the two steps above to your repository.
73+
---
74+
75+
## API Overview
76+
77+
| Method | Purpose | Key Arguments |
78+
|--------|---------|---------------|
79+
| `HyperSHAP(explanation_task)` | Initialise the explainer with a generic `ExplanationTask`. |
80+
| `ablation(config_of_interest, baseline_config, index="FSII", order=2)` | Explain the contribution of each hyperparameter value (and interactions) when moving from a baseline to a specific configuration. |
81+
| `tunability(baseline_config=None, index="FSII", order=2, n_samples=10_000)` | Quantify how much performance can be gained by tuning subsets of hyper‑parameters. |
82+
| `optimizer_bias(optimizer_of_interest, optimizer_ensemble, index="FSII", order=2)` | Attribute performance differences to a particular optimizer vs. an ensemble of optimizers. |
83+
| `plot_si_graph(interaction_values=None, save_path=None)` | Plot the Shapley Interaction (SI) graph; uses the most recent interaction values if none are supplied. |
84+
| `ExplanationTask.get_hyperparameter_names()` | Helper to retrieve ordered hyper‑parameter names (used for visualisation). |
85+
86+
All methods return an `InteractionValues` object (from **shapiq**) that can be inspected, saved, or passed to the visualisation routine.
87+
88+
---
4989

50-
```bash
51-
git add .
52-
git commit -m 'Fix formatting issues'
53-
git push origin main
90+
## Example Notebooks
91+
Full Jupyter notebooks illustrating all three explanation tasks (ablation, tunability, optimizer bias) are included in the repository under `examples/`. The notebookts walk through:
92+
93+
- Building a mockup environment
94+
- Creating the corresponding explanation task
95+
- Loading explanation tasks from different setups: data, black-box function, and existing surrogate model.
96+
- Computing interaction values with HyperSHAP
97+
- Visualizing results with `plot_si_graph`
98+
99+
---
100+
101+
## Citation
102+
If you use HyperSHAP in your research, please cite the original paper:
103+
104+
```bibtex
105+
@article{wever-arxiv25,
106+
author = {Marcel Wever and
107+
Maximilian Muschalik and
108+
Fabian Fumagalli and
109+
Marius Lindauer},
110+
title = {HyperSHAP: Shapley Values and Interactions for Hyperparameter Importance},
111+
journal = {CoRR},
112+
volume = {abs/2502.01276},
113+
year = {2025},
114+
doi = {10.48550/ARXIV.2502.01276},
115+
}
54116
```
55117

56-
You are now ready to start development on your project!
57-
The CI/CD pipeline will be triggered when you open a pull request, merge to main, or when you create a new release.
118+
The paper introduces the underlying game-theoretic framework and demonstrates its usefulness for HPO explainability.
119+
120+
## Contributing
58121

59-
To finalize the set-up for publishing to PyPI, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/publishing/#set-up-for-pypi).
60-
For activating the automatic documentation with MkDocs, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/mkdocs/#enabling-the-documentation-on-github).
61-
To enable the code coverage reports, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/codecov/).
122+
Contributions are welcome! Please follow these steps:
62123

63-
## Releasing a new version
124+
Fork the repo and create a feature branch (git checkout -b feat/your-feature).
125+
Write tests (the project uses pytest).
126+
Ensure all tests pass (pytest).
127+
Update documentation if you add new functionality.
128+
Submit a Pull Request with a clear description of the changes.
64129

65-
- Create an API Token on [PyPI](https://pypi.org/).
66-
- Add the API Token to your projects secrets with the name `PYPI_TOKEN` by visiting [this page](https://github.com/mwever/hypershap/settings/secrets/actions/new).
67-
- Create a [new release](https://github.com/mwever/hypershap/releases/new) on Github.
68-
- Create a new tag in the form `*.*.*`.
69130

70-
For more details, see [here](https://fpgmaas.github.io/cookiecutter-uv/features/cicd/#how-to-trigger-a-release).
131+
See CONTRIBUTING.md for detailed guidelines.
71132

72133
---
73134

135+
## License
136+
HyperSHAP is released under the BSD 3-Clause License. See the `LICENSE` file for full terms.
137+
138+
---
139+
140+
**Enjoy exploring your HPO pipelines with HyperSHAP!** 🎉
141+
142+
---
74143
Repository initiated with [fpgmaas/cookiecutter-uv](https://github.com/fpgmaas/cookiecutter-uv).

docs/modules.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
::: hypershap.foo
1+
# API Reference
2+
3+
## HyperSHAP
4+
::: hypershap.hypershap
5+
6+
## Explanation Task
7+
::: hypershap.task
8+
9+
## Surrogate Model
10+
::: hypershap.surrogate_model
11+
12+
## Games
13+
::: hypershap.games
14+
15+
## Utils
16+
::: hypershap.utils

0 commit comments

Comments
 (0)