cleverly.interventions.ModifiedPolicy#

class cleverly.interventions.ModifiedPolicy(name: str, pieces: tuple[Piece, ...] | Mapping[object, tuple[Piece, ...]] | None = None, apply: Callable[[...], Any] | None = None, randomizer: Randomizer | None = None, policy_kind: Literal['known', 'estimated'] | None = None)[source]#

A modified treatment policy that the analyst declares.

On a continuous treatment the policy is a tuple of Piece objects, as Assumption 4 of Díaz, Williams, Hoffman and Schenck (2023) requires. The fit checks on the observed doses that the pieces partition the range, that each map is strictly monotone, and that each declared inverse inverts its map. On a categorical treatment the policy is apply(a, h), which maps each unit’s label to a label, and the density ratio is the discrete formula of the same paper. A categorical node whose labels are numbers also takes pieces, applied to the label values.

A randomized policy adds a Randomizer with finitely many values. Then pieces maps each value to its pieces, or apply takes a third argument, the value.

ModifiedPolicy(
    "halve above 4",
    pieces=(
        Piece(-np.inf, 4.0),
        Piece(4.0, np.inf, lambda a, h: a / 2, lambda b, h: 2 * b, lambda b, h: 2.0),
    ),
    policy_kind="known",
)
Parameters:
namestr

The report label.

piecestuple of Piece, mapping, or None

The pieces, or a mapping from randomizer value to that value’s pieces.

applycallable() or None

apply(a, h), or apply(a, h, e) with a randomizer, on a categorical treatment. It returns one label per row.

randomizerRandomizer or None

The known law of the randomizer.

policy_kind{“known”, “estimated”} or None

The declaration that the policy is a known function. A fit accepts "known" only.

Methods#

Attributes#

ModifiedPolicy.apply: Callable[[...], Any] | None = None#
ModifiedPolicy.pieces: tuple[Piece, ...] | Mapping[object, tuple[Piece, ...]] | None = None#
ModifiedPolicy.policy_kind: Literal['known', 'estimated'] | None = None#
ModifiedPolicy.randomizer: Randomizer | None = None#
ModifiedPolicy.name: str#