cleverly.interventions.RegimeSet#

class cleverly.interventions.RegimeSet(names: tuple[str, ...], values: ndarray[tuple[Any, ...], dtype[float64]], reference: float = 0.0)[source]#

The regimes a fit targets, and their evaluated densities.

Keyed by an internal float code exactly as the arms are, with the labels carried alongside – the same convention, and for the same reason: every array that is per regime (the clever covariate’s columns, the counterfactual predictions, the influence curves) can then be handled by code that does not count regimes or know what they mean, while every reported name uses what the user called them.

Parameters:
namestuple of str

Regime labels in code order.

valuesndarray

(n, K, R) evaluated densities.

referencefloat

Code of the regime contrasts are taken against.

Attributes:
names:

Regime labels in code order, so names[r] is the label of code float(r).

values:

(n, K, R) densities: values[i, a, r] is \(g^\star_r(a \mid W_i)\).

reference:

The regime code contrasts are taken against, defaulting to the first supplied.

Methods#

RegimeSet.column(code: float) → ndarray[tuple[Any, ...], dtype[float64]][source]#

Return one regime’s evaluated density.

Parameters:
codefloat

Regime code.

Returns:
ndarray

(n, K) density for that regime alone.

classmethod RegimeSet.evaluate(interventions: Sequence[Intervention], data: CausalData, *, reference: str | None = None) → RegimeSet[source]#

Evaluate every intervention on data and assemble the set.

Parameters:
interventionssequence of Intervention

The regimes to evaluate, in the order their codes will follow.

dataCausalData

Validated study data to evaluate them on.

referencestr or None

Label of the regime contrasts are taken against. None uses the first one supplied, mirroring the arm convention where the reference is the lowest code.

Returns:
RegimeSet

The evaluated densities, keyed by code.

Notes

It runs refuse_regime_densities() on every intervention before it evaluates any density, so a Rule or a user-written Intervention meets its declaration check as a Stochastic does. A regime changed with object.__setattr__ can reach this method directly with a declaration this version refuses.

RegimeSet.label(code: float) → str[source]#

Return the label a regime code was supplied under.

Parameters:
codefloat

Regime code.

Returns:
str

The label, as the caller spelled it.

RegimeSet.subset(index: Any) → RegimeSet[source]#

The same regimes on a row subset – a bootstrap resample, a validation fold.

The densities are sliced rather than re-evaluated. For a regime that is a function of \(W\) alone the two agree exactly, and slicing is what keeps a loaded result (which carries the evaluated densities but not the callables that made them) usable everywhere a fitted one is.

Parameters:
indexarray_like

Row positions or a boolean mask.

Returns:
RegimeSet

The same regimes over the selected rows.

Attributes#

RegimeSet.codes#

Regime codes, (0.0, ..., R-1.0), in the order the regimes were supplied.

RegimeSet.is_static#

Whether every regime puts all its mass on one arm, the same one for every row.

The condition under which the regime path is estimating exactly what the arm path estimates, and so the one the equivalence test checks.

RegimeSet.labels#

Code to label, which is what parameter_name() is given.

RegimeSet.n#

Return the number of observations.

RegimeSet.n_arms#

Return the number of treatment arms.

RegimeSet.n_regimes#

Return the number of regimens.

RegimeSet.reference: float = 0.0#
RegimeSet.names: tuple[str, ...]#
RegimeSet.values: ndarray[tuple[Any, ...], dtype[float64]]#