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

Flowchart. At most 10 players or 2 to the n generations affordable: exact. Otherwise, Banzhaf index: kernel_banzhaf. Otherwise, values must add up: leverage. Otherwise, scikit-learn and a longer prompt: proxy. Otherwise mc. A side box lists the baselines permutation, lime and loo.

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)

Log-scale line plot of coalitions requested against players n from 4 to 14. exact grows as 2 to the n; mc stays at a tenth of it; the paired estimators follow mc above their 2n + 2 floor; neyman_cc phase one grows more slowly.

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_width wide (mc only), or

  • the top_k_stable largest 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

  1. Count players: len(TokenPartitioner().partition(snapshot).player_ids).

  2. If \(2^n\) generations are affordable, use exact.

  3. Else start with proxy or leverage (kernel_banzhaf for Banzhaf) at per_player: 8 with two seeds.

  4. Raise the budget while the top players change between seeds.

  5. Report estimator and budget; the run manifest records both (How a run works).

Situation

estimator

budget.fraction

Why

Up to about 10 players, or a reference to validate other runs

exact

1.0 (required)

Exact values; efficiency holds; \(2^n\) generations

You report the Banzhaf index

kernel_banzhaf

per_player: 8 or more

Regression on paired uniform samples; lowest Banzhaf error from \(4n\) coalitions; mc is the sampler alternative

Shapley on a longer prompt, scikit-learn available

proxy

per_player: 8 or more

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)\)

leverage

per_player: 4 or more

Efficient at every budget by construction; second-lowest error from \(8n\); Shapley only

Shapley, no extra dependency, payoffs cheap

mc

per_player: 8 or more

Every sample updates every player; no extra dependency

Shapley, generous budget, payoff variance differs by coalition size

neyman_cc

per_player: 16 or more

Spends phase two where variance is high; better than complementary from \(16n\)

Shapley and you want every coalition paired with its complement

complementary

per_player: 16 or more

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

permutation

per_player: 8 or more

Random orderings and their reverses, every prefix evaluated; plugin_options: {permutation: {antithetic: false}} draws plain orderings

The surrogate baseline of faithfulness comparisons

lime

per_player: 8 or more

Weighted ridge on random subsets with the reference kernel; coefficients, not Shapley values; ignores the estimand and needs efficiency: none; options kernel_width (25) and alpha (ridge, 1)

A baseline any attribution method must beat

loo

budget.evaluations: n + 2 past max_players

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)

mc

smallest that is stable

Re-run with two seeds; if the top players change, raise the budget