cleverly.interventions.Piece#
- class cleverly.interventions.Piece(lower: float | Callable[[Any], Any], upper: float | Callable[[Any], Any], map: Callable[[Any, Any], Any] | None = None, inverse: Callable[[Any, Any], Any] | None = None, derivative: Callable[[Any, Any], Any] | None = None, closed: Literal['left', 'right'] = 'left', to_atom: float | None = None)[source]#
One interval of a declared policy and the strictly monotone map it applies there.
Assumption 4 of Díaz, Williams, Hoffman and Schenck (2023, Section 4) asks a policy on a continuous treatment to be piecewise smooth invertible: the dose range splits into intervals \(I_j(h)\), and on each one the policy is a strictly monotone smooth map \(d_j\) with inverse \(b_j\). The density the policy induces is then their Equation (3), which reads \(b_j\) and \(b_j'\).
- Parameters:
- lower
floatorcallable() The lower end of the interval, or a function of the policy frame that returns one value per row.
- upper
floatorcallable() The upper end, in the same form.
- map
callable()orNone map(a, h), the dose the policy assigns on this piece.Nonemarks an identity piece, which leaves the dose unchanged.- inverse
callable()orNone inverse(b, h), the dose on this piece that the map sends tob. Required unless the piece is an identity piece.- derivative
callable()orNone derivative(b, h), the derivative ofinversewith respect tob. Required unless the piece is an identity piece or sends its interval to an atom.- closed{“left”, “right”}
Which end of the interval belongs to it:
"left"is[lower, upper)and"right"is(lower, upper].- to_atom
floatorNone The dose the piece sends its whole interval to. The dose must be a declared atom of the node (
dose_atoms=): a dose with a recorded point mass. The density ratio at the atom then adds the mass of the interval, and the fit refuses the piece when the dose is not a declared atom. A piece withto_atomdeclares nomap,inverseorderivative.
- lower
- Attributes:
is_identityboolWhether the piece leaves the dose unchanged.
Methods#
Attributes#
- Piece.is_identity#
Whether the piece leaves the dose unchanged.