estimation

Responsibility

  • Choose which coalitions to evaluate (Estimator) and turn coalition payoffs into per-player attributions (Estimand aggregators).

  • Rescale attributions for presentation (normalisers) and make Shapley values efficient (additive_efficiency).

Public surface

  • ExactEstimator (exact): all 2^n masks in bitmask order; requires the full table.

  • MonteCarloEstimator (mc): the grand and empty coalitions, singletons and (n-1)-sets, then a uniformly drawn size and a uniform unseen coalition of it. Stratified SVARM ( paper, decision).

  • ComplementaryEstimator (complementary): (N, ∅), singleton pairs, block pairs per size 2..n/2 that put every player on both sides, then random pairs. m_counts exposes the count matrix. A warning names sizes that stay empty (decision).

  • NeymanEstimator (neyman_cc, default): phase one yields (N, ∅), singleton pairs, then complete passes (one draw per player) size by size, ending between passes. begin_allocation(masks, payoffs) water-fills the remaining pairs over sizes >= n/2 with weight sqrt(sum sigma^2[:, j]/j + sum sigma^2[:, n-j]/(n-j)) (the middle column once, divided by n); sample_allocation_masks() yields phase two.

  • LeverageEstimator (leverage, Shapley): complementary pairs allocated uniformly over sizes, enumerating covered size classes; leverage_values solves the sum-constrained regression with weight (n-1)/(s(n-s) count_s), so values are efficient at every budget.

  • KernelBanzhafEstimator (kernel_banzhaf, Banzhaf): distinct uniform complementary pairs; least squares of payoffs on presence minus one half plus an intercept.

  • ProxyEstimator (proxy, both estimands, extra proxy): leverage-sampled masks and boosted trees (100, depth 3, seed 0) with exact per-leaf values (tree_values). The aggregator’s values of the residual are added when n < 30 or masks >= 16n. scikit-learn is imported at construction.

  • PermutationEstimator (permutation, option antithetic, default true): the grand and empty coalitions, then unseen prefixes of random orderings and their reverses, up to the mc budget; any estimand.

  • LimeEstimator (lime, options kernel_width 25, alpha 1): distinct random subsets; lime_values is the kernel-weighted ridge of payoffs on presence. Ignores the estimand, like loo.

  • standard_errors (mc, exact; config explanation.stderr): marginal_standard_errors sums squared stratum variances with a finite-population correction, using pooled variance for one-observation sides; an unobserved player gets inf. Undefined for permutation (correlated prefixes).

  • plan_budget(n, value_range, target_error, confidence): Hoeffding orderings and evaluations, capped at 2^n; the plan command.

  • check_stop (budget.stop): ends mc/permutation sampling on interval width or a stable top-k set; the orchestrator evaluates in chunks.

  • pairwise_interactions (extra interactions): shapiq order-2 index of a full table.

  • LeaveOneOutEstimator (loo): N and each N - {i}; ignores budget and estimand (decision).

  • Every estimator: estimate_attributions(masks, payoffs, aggregator). leverage and kernel_banzhaf reject the other estimand; complementary and neyman_cc accept Shapley only.

  • ShapleyAggregator, BanzhafAggregator: a complete Shapley table goes through aggregate_shapley_exact. Other tables use aggregate_from_marginals: per player and size stratum l the mean payoff of sampled coalitions with i of size l+1 minus the mean of those without i of size l, combined with stratum probabilities renormalised over strata having both means. A player with none gets 0 and one warning.

  • Normalisers: IdentityNormalizer, AbsSumNormalizer, PowerShiftNormalizer, MinMaxNormalizer; additive_efficiency(values, grand, base) shifts all values equally (explanation.efficiency: additive).

  • _shared.py: budget_fraction(n, fraction, evaluations) turns an absolute count (BudgetConfig.evaluations_for resolves per_player to ceil(alpha n)) into evaluations / 2^n; compute_mc_num_samples (floor 2, or n + 2) and compute_complementary_num_splits (even, floor min(2n + 2, 2^n)); random_present.

Data flow

  • In: PlayerSet, the budget fraction, include_minimal_masks, seed from the pipeline config; later the collected masks and payoffs (both phases for Neyman).

  • Out: an iterator of CoalitionMask and a list[float] of attributions.

  • Imports domain, protocols, plugins (context type only), numpy; proxy also scikit-learn.

Invariants

  • On the full table every estimator is efficient for the Shapley estimand (Full coalition table); leverage is efficient at every budget.

  • Every sampler yields the grand and empty coalitions first; they count toward the budget.

  • Complementary aggregation does not depend on mask order; at the floor the game v(S) = |S| gives 1 per player (C14).

  • mc is exact on the full table and nearly unbiased from about 32n masks; kernel_banzhaf and proxy with correction are exact on the full table.

  • additive_efficiency never increases the L2 error: it projects onto the hyperplane holding the exact values.

Known issues

  • Fixed: M01, M02, M03, C01, C03, C04, C05, C10, C12, C13, C14 (Fixed issues).

Tests