Source code for nlp_shap.domain.estimands
"""Estimand labels for attribution outputs and archive manifests."""
from enum import StrEnum
from typing import Literal
EstimandWire = Literal["shapley", "banzhaf"]
"""Wire values used in manifests and configuration payloads."""
[docs]
class Estimand(StrEnum):
"""Supported cooperative-game value formulations."""
SHAPLEY = "shapley"
"""Shapley value with coalition weights k!(n-k-1)!/n!."""
BANZHAF = "banzhaf"
"""Banzhaf index with uniform coalition weights 1/2^(n-1)."""
[docs]
def estimand_to_wire(estimand: Estimand) -> EstimandWire:
"""Serialize an estimand enum member to its wire value."""
match estimand:
case Estimand.SHAPLEY:
return "shapley"
case Estimand.BANZHAF:
return "banzhaf"
case _ as unreachable:
raise AssertionError(f"unsupported estimand: {unreachable!r}")