Repository navigation
Commit 9de7fac
Add PolySHAP Approximator (#559)
* PolySHAP file integration
* test: add cross-approximator conformance + convergence test scaffold
Forward-looking spec for the 3 new SV approximators (LeverageSHAP,
PolySHAP, OddSHAP). Approximator classes are looked up dynamically by
name, so the file auto-skips classes that have not yet been registered
in shapiq.approximator. As each implementation lands, the corresponding
parametrizations activate.
- Interface conformance (always required): index='SV', n_players,
max_order/min_order, values shape and dtype, interaction_lookup.
- Numerical convergence vs ExactComputer (xfail strict=False): atol
schedule by budget percentage.
- Determinism: same (n, random_state, budget, game) -> bit-identical
output.
75 tests, all currently SKIP on main. Will activate as classes land.
* test: extend conformance harness to ALL SV approximators
Honors the cross-method testing platform promised to the tutor:
unified harness covering every SV approximator in shapiq (the
existing 11 — KernelSHAP, SVARM, Permutation*, ProxySPEX, ... — and
the 3 new ones from this project) instead of only the new line-up.
Approximator list is sourced dynamically from
shapiq.approximator.SV_APPROXIMATORS (canonical registry) plus the
3 new project names, deduplicated. Future shapiq additions land in
the harness automatically.
Split into two scopes:
* test_interface_conformance — strict shape/dtype/index/lookup
contract from the API spec. Applied ONLY to the 3 new
approximators (the contract is ours; existing methods have
different default output conventions like ProxySPEX defaulting
to FBII and max_order=n).
* test_numerical_convergence_vs_exact + test_determinism — apply
to ALL SV approximators. Cross-method comparison against
ExactComputer ground truth on identical SOUM games. xfail with
strict=False so methods that do converge surface as XPASS;
methods still under development surface as XFAIL.
Two robustness helpers:
* _construct_or_skip — tries (n=, index='SV', max_order=1,
random_state=) first (covers multi-index methods like SPEX,
ProxySPEX, ProxySHAP, MSRBiased, kADDSHAP), then falls back to
minimal signature for SV-only methods (KernelSHAP, OwenSamplingSV).
* _safe_approximate — skips on ValueError raised by approximators
that explicitly refuse a regime (e.g. SPEX 'Insufficient budget
to compute the transform' at low budgets).
Results: 10 passed, 95 skipped, 90 xfailed, 23 xpassed. The 23
xpassed are existing shapiq SV methods that converge cleanly at
full budget on small SOUM — a useful baseline for the upcoming
benchmark report.
* PolySHAPKAdd, PolySHAPPartial, PolySHAPPrior
refactored PolySHAP+ExplanationFrontierGenerator into subclasses requiring no generator; registered all three subclasses; removed unexpected parameters; cleaner variable naming; included unedited efficient_sampling for now
* docstring: removed ref to removed para
* feat(benchmark): cross-method performance harness for SV approximators
Drop-in framework that any teammate can merge into their feature branch
to run head-to-head benchmarks against ExactComputer across every SV
approximator in shapiq, then plot the standard SHAP-literature metric
curves. No source files are modified — adds a top-level benchmark/
package, a single test file, and a small in-place test-helper sys.path
hook. Does not touch pyproject.toml or any other upstream config.
Files added:
* benchmark/__init__.py: makes the runner a proper Python package so
invocation is 'python -m benchmark.performance'.
* benchmark/_discovery.py: single source of truth for SV approximator
discovery + SV-mode construction. Holds:
- PROJECT_APPROXIMATOR_NAMES: LeverageSHAP, PolySHAP,
PolySHAPKAdd / Partial / Prior, OddSHAP.
- _SV_CONSTRUCT_OVERRIDES: per-class kwargs for non-standard
constructors (PolySHAP variants need max_order /
n_explanation_terms / q_prior).
- construct_for_sv(): three-stage construction (override ->
explicit SV signature -> minimal signature), returning
(estimator, exc) so the caller can report the most informative
exception. A ValueError from inside a matched signature wins
over a TypeError from a signature mismatch.
- safe_approximate(): catches ValueError and RuntimeError so
sparse approximators that refuse a budget regime (SPEX,
ProxySPEX, ...) skip the cell cleanly instead of crashing.
* benchmark/performance.py: CLI runner that consumes _discovery,
sweeps (method, game, budget, seed), records every cell in a
long-format CSV, and emits one PNG per (game, metric) plus a
runtime PNG. Seven metrics chosen from the union of LeverageSHAP,
PolySHAP, OddSHAP and shapiq.benchmark.metrics literature:
MSE / MAE / SSE / SAE / Precision@5 / Precision@10 / KendallTau.
Includes a '--check' interface-probe mode that prints a
constructibility table without running a sweep.
* benchmark/README.md: usage doc covering merge workflow, --check,
sweep CLI, output layout, CSV format, metric definitions, plot
conventions, and notes on the multi-index approximators that need
explicit (index='SV', max_order=1).
Files modified:
* tests/shapiq/tests_unit/tests_approximators/test_approximators_vs_exact.py:
now imports the shared helpers from benchmark._discovery via a
tightly-scoped sys.path hook at the top of the file. Picks up the
ValueError-priority construction and the RuntimeError-catch that
the test file previously did not have. Interface conformance is
now applied to the project's six new approximator names
(LeverageSHAP, PolySHAP + 3 variants, OddSHAP), so Matthias's
PolySHAP variants are no longer silently skipped by the contract
check.
Verified locally:
* pytest test_approximators_vs_exact.py: 10 passed, 170 skipped,
87 xfailed, 26 xpassed. No failures.
* python -m benchmark.performance --check: surfaces all 17 method
names (11 existing on main + 6 project additions) correctly.
* Drop-in compatibility verified by temporary merge into all three
feature branches (oddshap_approximator, leverageSHAP, PolySHAP) —
clean merge in each, --check picks up the local approximator.
* feat/gitignore: Add benchmark/results/* to .gitignore
* PolySHAP unit tests
* PolySHAP docstrings; underdefined problem warning
* PolySHAP removed time measurements; fixed docstring
* PolySHAP benchmark discovery
* PolySHAP: removed efficient_sampling.py
Removed for lack of generalization
* PolySHAP seeded unit tests
* PolySHAP paper reproduction notebook
* FIX PolySHAP interaction values
* PolySHAP maxorder showcase notebook
* PolySHAPPrior excluded from benchmarking
* PolySHAP bib-reference and mini-demo
* PolySHAP changelog entry
* PolySHAP lint fixes
* PolySHAP removal of additional benchmark and notebooks
* PolySHAP OddSHAP Fumagalli bib references
* PolySHAP make overrides ty-compatible
* PolySHAP unified class; improved unit tests
* PolySHAP docstring: unbounded max_order
* Adapt PolySHAP to the reworked documentation
- cite the PolySHAP paper as Fumagalli.2026, its key in main's
bibliography (Fumagalli.2026a is now OddSHAP)
- move the example into the Shapley values gallery, cite with :cite:
instead of :footcite:, and add it to EXAMPLE_ORDER
- link the timeline's PolySHAP entry to the class and the example
- export PolySHAP from the top-level package like the other approximators
* Fix PolySHAP's prior_frontier when the empty set is not listed first
The regression assumes that the empty set is the first frontier term.
A prior_frontier without it (e.g. only singletons and pairs) silently
returned wrong Shapley values, and one listing it last raised an
IndexError. The empty set is now always put first, the other terms keep
their order, and duplicate terms are ignored.
* Fix PolySHAP failing for more than ~1,030 players
binom(n, k) overflows float64 from n ~ 1030 on. The regression kernel
weight (~1 / binom) then underflowed to 0 and the sampler's adjustment
weight (~binom) overflowed to inf, so lstsq failed with "SVD did not
converge". The kernel weights are now kept in log space and added to
the sampler's log adjustment weights, as in the other regression
approximators (see #621 for OddSHAP).
* Declare only SV in PolySHAP's valid_indices
PolySHAP inherited all regression indices from Regression, but it only
computes Shapley values. It now declares ("SV",) like KernelSHAP,
LeverageSHAP and OddSHAP.
* Remove unrelated .gitignore entries
Drops the duplicate .claude entry and the repository-wide cache/ rule, which are not related to PolySHAP.
---------
Co-authored-by: Holzner, Matthias <matthias.holzner@campus.lmu.de>
Co-authored-by: YUANLUO WU <yuanluowu@gmail.com>
Co-authored-by: Fabian Kadlez <F.Kadlez@campus.lmu.de>
Co-authored-by: Maximilian <maximilian.muschalik@gmail.com>1 parent 9c583f4 commit 9de7fac
9 files changed
Lines changed: 1088 additions & 0 deletions
File tree
- docs/source
- _data
- examples/approximators/shapley_values
- src/shapiq
- approximator
- regression
- tests/shapiq/tests_unit/tests_approximators
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
5 | 12 | | |
6 | 13 | | |
7 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
686 | 686 | | |
687 | 687 | | |
688 | 688 | | |
| 689 | + | |
| 690 | + | |
689 | 691 | | |
690 | 692 | | |
691 | 693 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
| 122 | + | |
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| 70 | + | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
| |||
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
| 153 | + | |
151 | 154 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
0 commit comments