Choosing an estimator¶
Each requested coalition costs one generation; cache hits are free. Pick the estimator, then its budget; the closing table is the reference. Code: Using approximate estimators; formulas: Approximate estimation, Regression estimators and hierarchical players.
Picking an estimator¶
Illustrative, condensed from the decision table.¶
base_value and grand_value are always exact. With identity normalization the
values sum to grand_value - base_value under leverage, on the full table and with
efficiency: additive;
elsewhere the gap shrinks as the budget grows. Error against budget:
Estimator benchmark; for your prompts: Choosing a budget.
What a budget costs¶
budget.fraction scales the \(2^n\) coalitions of the full table. What each
estimator requests at 10 %:
Code for this figure
import matplotlib.pyplot as plt
from mllm_shap import (
ComplementaryEstimator,
ExactEstimator,
MonteCarloEstimator,
NeymanEstimator,
PlayerSet,
)
sizes = range(4, 15)
estimators = { # label: (estimator, budget.fraction, marker)
"exact (full table)": (ExactEstimator(), 1.0, "o"),
"complementary, leverage, kernel_banzhaf, proxy": (ComplementaryEstimator(), 0.1, "s"),
"mc": (MonteCarloEstimator(), 0.1, "."),
"neyman_cc, phase one": (NeymanEstimator(), 0.1, "^"),
}
figure, axis = plt.subplots(figsize=(6.5, 3.5), layout="constrained")
for label, (estimator, fraction, marker) in estimators.items():
counts = [
sum(1 for _ in estimator.sample_masks(
PlayerSet(player_ids=tuple(f"p{i}" for i in range(n))), fraction, False, 0
))
for n in sizes
]
axis.plot(sizes, counts, marker=marker, label=label)
axis.set(yscale="log", xlabel="players n", ylabel="coalitions requested")
axis.legend(fontsize="small")
Coalitions requested at budget.fraction 0.1 (seed 0)
Up to \(n = 7\) the paired estimators sit on their \(2n + 2\) floor (every
singleton pair) and round odd counts down to whole pairs; mc’s floor is 2. neyman_cc
shows phase one; the runner adds phase two up to the same budget.
output.metrics.executed counts backend calls left after deduplication and the base
generation.
Past about 25 players any fraction of \(2^n\) is too many. Set a count instead (one budget key per run):
budget.evaluations: 2000: 2000 coalitions, empty and grand included.budget.per_player: 4: \(\lceil 4n \rceil\) coalitions.
Floors and the \(2^n\) ceiling still apply; exact takes only fraction: 1.0.
explanation:
estimator: leverage
budget:
per_player: 4
A run planning more than \(2^{\text{max\_players}}\) coalitions
(explanation.max_players, default 24), such as a full table on more players, raises
ConfigError before any model call. Lower the budget, coarsen the
players or raise the limit.
Standard errors¶
explanation.stderr: true adds a standard error per value (stderr in the JSON);
value ± 1.96 * stderr is a 95% interval. Only mc and exact (zero) have one; inf marks a player mc never observed. On
the reference games mc intervals covered the exact value in 92 to 97% of seeds at 10
to 25% budget. Needs efficiency: none and the identity normalizer; reanalyze
recomputes it. Formula and why permutation has none: Standard errors.
Stopping early¶
budget.stop ends sampling early; the budget stays the cap. Every check_every
coalitions (default 16), after min_evaluations (default \(2(n + 1)\)), it stops when
every 95% interval is at most
max_ci_widthwide (mconly), orthe
top_k_stablelargest players match the previous check (mc,permutation).
It saves few evaluations; use it to reach a target width (Permutation, LIME, standard errors and budgets). Semivalues, new estimators and honest uncertainty runs it, standard errors and the budget planner on a toy game.
explanation:
estimator: mc
budget: {fraction: 0.5, stop: {max_ci_width: 0.2, check_every: 16}}
Pairwise interactions¶
explain_interactions() (extra interactions) returns the order-2
k-SII matrix via shapiq; a positive entry means two players are worth more together
than apart. It scores all \(2^n\) coalitions: keep inputs short; an archive or the
replay backend serves repeats. index picks others such as
FSII (Faith-SHAP). The result has player ids, their words in labels and top(k)
for the largest pairs.
Which to choose¶
Count players:
len(TokenPartitioner().partition(snapshot).player_ids).If \(2^n\) generations are affordable, use
exact.Else start with
proxyorleverage(kernel_banzhaffor Banzhaf) atper_player: 8with two seeds.Raise the budget while the top players change between seeds.
Report estimator and budget; the run manifest records both (How a run works).
Situation |
|
|
Why |
|---|---|---|---|
Up to about 10 players, or a reference to validate other runs |
|
|
Exact values; efficiency holds; \(2^n\) generations |
You report the Banzhaf index |
|
|
Regression on paired uniform samples; lowest Banzhaf error from
\(4n\) coalitions; |
Shapley on a longer prompt, scikit-learn available |
|
|
Lowest Shapley error from \(8n\) coalitions on the benchmark games; also computes Banzhaf; fits trees on every aggregation |
Shapley, values must add up to \(v(N) - v(\emptyset)\) |
|
|
Efficient at every budget by construction; second-lowest error from \(8n\); Shapley only |
Shapley, no extra dependency, payoffs cheap |
|
|
Every sample updates every player; no extra dependency |
Shapley, generous budget, payoff variance differs by coalition size |
|
|
Spends phase two where variance is high; better than |
Shapley and you want every coalition paired with its complement |
|
|
Each pair \((S, N \setminus S)\) informs every player; pairs that cover every size cost about \(n \ln n\) pairs |
The classic baseline of attribution papers, any estimand |
|
|
Random orderings and their reverses, every prefix evaluated;
|
The surrogate baseline of faithfulness comparisons |
|
|
Weighted ridge on random subsets with the reference kernel; coefficients, not
Shapley values; ignores the estimand and needs |
A baseline any attribution method must beat |
|
|
Leave-one-out, \(v(N) - v(N \setminus \{i\})\); \(n + 2\) generations; not Shapley, so values need not add up |
Expensive backend (paid API, large model) |
|
smallest that is stable |
Re-run with two seeds; if the top players change, raise the budget |