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:
lowerfloat or callable()

The lower end of the interval, or a function of the policy frame that returns one value per row.

upperfloat or callable()

The upper end, in the same form.

mapcallable() or None

map(a, h), the dose the policy assigns on this piece. None marks an identity piece, which leaves the dose unchanged.

inversecallable() or None

inverse(b, h), the dose on this piece that the map sends to b. Required unless the piece is an identity piece.

derivativecallable() or None

derivative(b, h), the derivative of inverse with respect to b. 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_atomfloat or None

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 with to_atom declares no map, inverse or derivative.

Attributes:
is_identitybool

Whether the piece leaves the dose unchanged.

Methods#

Attributes#

Piece.closed: Literal['left', 'right'] = 'left'#
Piece.derivative: Callable[[Any, Any], Any] | None = None#
Piece.inverse: Callable[[Any, Any], Any] | None = None#
Piece.is_identity#

Whether the piece leaves the dose unchanged.

Piece.map: Callable[[Any, Any], Any] | None = None#
Piece.to_atom: float | None = None#
Piece.lower: float | Callable[[Any], Any]#
Piece.upper: float | Callable[[Any], Any]#