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): all2^nmasks 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 size2..n/2that put every player on both sides, then random pairs.m_countsexposes 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/2with weightsqrt(sum sigma^2[:, j]/j + sum sigma^2[:, n-j]/(n-j))(the middle column once, divided byn);sample_allocation_masks()yields phase two.LeverageEstimator(leverage, Shapley): complementary pairs allocated uniformly over sizes, enumerating covered size classes;leverage_valuessolves 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, extraproxy): 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 whenn < 30or masks>= 16n.scikit-learnis imported at construction.PermutationEstimator(permutation, optionantithetic, default true): the grand and empty coalitions, then unseen prefixes of random orderings and their reverses, up to themcbudget; any estimand.LimeEstimator(lime, optionskernel_width25,alpha1): distinct random subsets;lime_valuesis the kernel-weighted ridge of payoffs on presence. Ignores the estimand, likeloo.standard_errors(mc,exact; configexplanation.stderr):marginal_standard_errorssums squared stratum variances with a finite-population correction, using pooled variance for one-observation sides; an unobserved player getsinf. Undefined forpermutation(correlated prefixes).plan_budget(n, value_range, target_error, confidence): Hoeffding orderings and evaluations, capped at2^n; theplancommand.check_stop(budget.stop): endsmc/permutationsampling on interval width or a stable top-kset; the orchestrator evaluates in chunks.pairwise_interactions(extrainteractions):shapiqorder-2 index of a full table.LeaveOneOutEstimator(loo):Nand eachN - {i}; ignores budget and estimand (decision).Every estimator:
estimate_attributions(masks, payoffs, aggregator).leverageandkernel_banzhafreject the other estimand;complementaryandneyman_ccaccept Shapley only.ShapleyAggregator,BanzhafAggregator: a complete Shapley table goes throughaggregate_shapley_exact. Other tables useaggregate_from_marginals: per player and size stratumlthe mean payoff of sampled coalitions withiof sizel+1minus the mean of those withoutiof sizel, 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_forresolvesper_playertoceil(alpha n)) intoevaluations / 2^n;compute_mc_num_samples(floor 2, orn + 2) andcompute_complementary_num_splits(even, floormin(2n + 2, 2^n));random_present.
Data flow¶
In:
PlayerSet, the budget fraction,include_minimal_masks,seedfrom the pipeline config; later the collected masks and payoffs (both phases for Neyman).Out: an iterator of
CoalitionMaskand alist[float]of attributions.Imports domain, protocols, plugins (context type only), numpy;
proxyalso scikit-learn.
Invariants¶
On the full table every estimator is efficient for the Shapley estimand (Full coalition table);
leverageis 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).mcis exact on the full table and nearly unbiased from about32nmasks;kernel_banzhafandproxywith correction are exact on the full table.additive_efficiencynever 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¶
test_axioms, test_games (reference games in
_games.py)