Estimand aggregators and estimation¶
Exact coalition enumeration estimator.
- class nlp_shap.estimation.exact.ExactEstimator[source]¶
Bases:
objectEnumerate all coalitions and delegate attribution to an estimand plugin.
- static num_coalitions(num_players: int) int[source]¶
Return the number of coalitions evaluated by exact enumeration.
- static iter_mask_ints(num_players: int) Iterator[int][source]¶
Lazily yield coalition bitmasks except the all-present coalition.
- static mask_int_to_present(mask_int: int, num_players: int) tuple[bool, ...][source]¶
Decode a coalition bitmask into presence flags.
- bind_snapshot(snapshot: ConversationSnapshot) None[source]¶
Attach the conversation snapshot under explanation.
- sample_masks(player_set: PlayerSet, budget_fraction: float, include_minimal_masks: bool, seed: int) Iterator[CoalitionMask][source]¶
Yield every coalition mask except the grand coalition.
- static iter_masks(player_set: PlayerSet) Iterator[CoalitionMask][source]¶
Lazily yield coalition masks except the all-present coalition.
- estimate_attributions(masks: Sequence[CoalitionMask], payoffs: Sequence[float], aggregator: EstimandAggregator) list[float][source]¶
Aggregate coalition payoffs with the selected estimand plugin.
Monte Carlo coalition sampling estimator.
- class nlp_shap.estimation.monte_carlo.MonteCarloEstimator[source]¶
Bases:
objectSample random coalitions and delegate attribution to an estimand plugin.
- bind_snapshot(snapshot: ConversationSnapshot) None[source]¶
Attach the conversation snapshot under explanation.
- sample_masks(player_set: PlayerSet, budget_fraction: float, include_minimal_masks: bool, seed: int) Iterator[CoalitionMask][source]¶
Yield random coalition masks up to the configured budget.
- estimate_attributions(masks: Sequence[CoalitionMask], payoffs: Sequence[float], aggregator: EstimandAggregator) list[float][source]¶
Aggregate sampled coalition payoffs with the selected estimand plugin.
Complementary pair sampling estimator.
- class nlp_shap.estimation.complementary.ComplementaryEstimator[source]¶
Bases:
objectSample complementary coalition pairs and aggregate CC attributions.
- bind_snapshot(snapshot: ConversationSnapshot) None[source]¶
Attach the conversation snapshot under explanation.
- reset_sampling_state(num_players: int) None[source]¶
Reset complementary M-matrix counts before a new sampling run.
Neyman complementary allocation estimator.
- class nlp_shap.estimation.neyman.NeymanEstimator(initial_fraction: float | None = None, initial_num_samples: int | None = None, use_standard_method: bool = False)[source]¶
Bases:
ComplementaryEstimatorTwo-phase complementary estimator with Neyman coalition-size allocation.
- bind_snapshot(snapshot: ConversationSnapshot) None[source]¶
Attach the conversation snapshot under explanation.
- sample_masks(player_set: PlayerSet, budget_fraction: float, include_minimal_masks: bool, seed: int) Iterator[CoalitionMask][source]¶
Yield phase-one Neyman masks until the initial M-matrix grid is filled.
- begin_allocation(masks: Sequence[CoalitionMask], payoffs: Sequence[float]) None[source]¶
Estimate Neyman allocation after phase-one payoffs are available.
- sample_allocation_masks() Iterator[CoalitionMask][source]¶
Yield phase-two masks according to the estimated Neyman allocation.
Shapley estimand aggregation.
- class nlp_shap.estimation.estimands.shapley.ShapleyAggregator[source]¶
Bases:
objectAggregate coalition samples with Shapley coalition weights.
Banzhaf estimand aggregation.
- class nlp_shap.estimation.estimands.banzhaf.BanzhafAggregator[source]¶
Bases:
objectAggregate coalition samples with uniform Banzhaf coalition weights.
Post-aggregation attribution normalizers.
- class nlp_shap.estimation.normalizers.IdentityNormalizer[source]¶
Bases:
objectReturn attributions unchanged.
- class nlp_shap.estimation.normalizers.AbsSumNormalizer[source]¶
Bases:
objectScale attributions by the sum of absolute values.
- class nlp_shap.estimation.normalizers.PowerShiftNormalizer(power: float = 1.0)[source]¶
Bases:
objectShift to non-negative values, apply a power, then scale to sum one.