Estimand aggregators and exact estimation

Exact coalition enumeration estimator.

class nlp_shap.estimation.exact.ExactEstimator[source]

Bases: object

Enumerate all coalitions and delegate attribution to an estimand plugin.

property name: str

Return the registered estimator identifier.

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.

Shapley estimand aggregation.

class nlp_shap.estimation.estimands.shapley.ShapleyAggregator[source]

Bases: object

Aggregate coalition samples with Shapley coalition weights.

property estimand: Estimand

Return the Shapley estimand label.

coalition_weight(coalition_size: int, num_players: int) float[source]

Return Shapley coalition weight k!(n-k-1)!/n!.

aggregate(masks: Sequence[Sequence[bool]], payoffs: Sequence[float]) list[float][source]

Aggregate coalition samples into Shapley values.

Banzhaf estimand aggregation.

class nlp_shap.estimation.estimands.banzhaf.BanzhafAggregator[source]

Bases: object

Aggregate coalition samples with uniform Banzhaf coalition weights.

property estimand: Estimand

Return the Banzhaf estimand label.

coalition_weight(coalition_size: int, num_players: int) float[source]

Return uniform Banzhaf coalition weight 1/2^(n-1).

aggregate(masks: Sequence[Sequence[bool]], payoffs: Sequence[float]) list[float][source]

Aggregate coalition samples into Banzhaf indices.