Using estimand aggregators

Estimand aggregators (mllm_shap.estimation.estimands) turn coalition masks and payoffs \(v(S)\) into attributions. Each run records the estimand, so Banzhaf output is never reported as Shapley. Getting started shows Shapley and Banzhaf disagreeing on a majority game.

Coalition weights

Weight of a marginal contribution \(v(S \cup \{i\}) - v(S)\) with \(|S| = k\):

from mllm_shap import BanzhafAggregator, ShapleyAggregator

shapley = ShapleyAggregator()
banzhaf = BanzhafAggregator()

n = 4
for k in range(n):
    print(
        f"k={k}",
        round(shapley.coalition_weight(k, n), 6),
        round(banzhaf.coalition_weight(k, n), 6),
    )

Output

k=0 0.25 0.125
k=1 0.083333 0.125
k=2 0.083333 0.125
k=3 0.25 0.125

Shapley weights sum to one over each player’s coalitions, so values add up. Banzhaf weights are uniform, \(1/2^{n-1}\).

Choosing the estimand of a run

explanation.estimand picks the aggregator for the same coalitions and payoffs. Result and manifest carry the label:

from mllm_shap import (
    ConversationSnapshot,
    ExplainConfig,
    ExplainRunner,
    Message,
    Role,
    Turn,
)

snapshot = ConversationSnapshot.from_turns((
    Turn(messages=(Message(role=Role.USER, text="Cancel my old phone plan today"),)),
))
for estimand in ("shapley", "banzhaf"):
    config = ExplainConfig.model_validate({
        "backend": {"kind": "mock", "model_id": "stub"},
        "explanation": {
            "estimator": "exact",
            "estimand": estimand,
            "absence_policy": "pad",
            "archive": {"path": ""},
        },
    })
    output = ExplainRunner(config).explain_sync(snapshot)
    print(
        output.result.estimand.value,
        output.manifest.estimand.value,
        tuple(round(value, 4) for value in output.result.values),
    )

Output

shapley shapley (0.1667, 0.1667, 0.1667, 0.1667, 0.1667, 0.1667)
banzhaf banzhaf (0.0312, 0.0312, 0.0312, 0.0312, 0.0312, 0.0312)

JSON manifests use EstimandWire: "shapley", "banzhaf", "beta_shapley" or "weighted_banzhaf".

Below the full table both are estimated per coalition size: What the aggregator computes from partial samples.

Semivalues

beta_shapley and weighted_banzhaf change only the weight per coalition size (Estimands: Shapley vs Banzhaf). They run with mc, exact, permutation, lime or loo; options go under plugin_options:

explanation:
  estimand: beta_shapley
  estimator: mc
  plugin_options:
    beta_shapley: {alpha: 4.0, beta: 1.0}     # alpha = beta = 1 is Shapley

weighted_banzhaf takes p (default 0.3; 0.5 is Banzhaf). Both read the coalitions Shapley reads, so an archived run can be reanalyzed or replayed for another estimand with the same estimator.

Notebooks: Shapley vs Banzhaf on toy cooperative games (majority and additive games) and Semivalues, new estimators and honest uncertainty. Theory: Shapley values and axioms, Estimands: Shapley vs Banzhaf, Cooperative games. API: Estimation.