cleverly.interventions.Intervention#

class cleverly.interventions.Intervention(*args, **kwargs)[source]#

A conditional distribution over the treatment arms.

Implement density(), carry a name, and declare density_kind; everything else – the clever covariate, the influence curve, the positivity report, the parameter names – is written against the (n, K) matrix and needs to know nothing about which kind of intervention produced it.

density receives the data of the fit, so it can compute \(g^\star\) from the analysis sample, and no code can inspect what it computes. So a user-written class declares density_kind. "known" says that density(data) returns a fixed function of the covariates, chosen independently of the analysis sample, and it is the one value a fit accepts. refuse_regime_densities() refuses None and "estimated" before any learner. A plain class attribute density_kind = "known" satisfies the protocol. Static, Rule and Stochastic carry their own declarations. A subclass of Static can override density, so it declares density_kind itself.

Parameters:
*args, **kwargs

Present because typing.runtime_checkable() gives a protocol a synthetic constructor. A protocol is implemented, not instantiated.

Attributes:
namestr

What this regime is called in reported parameter names: ey[treat_all].

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

The declaration that density() is a fixed function of the covariates.

Methods#

Intervention.density(data: CausalData) → ndarray[tuple[Any, ...], dtype[float64]][source]#

Evaluate this regime’s arm probabilities for every row.

Parameters:
dataCausalData

Validated study data, which supplies the covariates and the arm order.

Returns:
ndarray

(n, K) array of \(g^\star(a \mid W_i)\), columns in arm-code order.

Attributes#

Intervention.density_kind#

The declaration that density() is a fixed function of the covariates.

"known" is the one value a fit accepts. None means undeclared, and it is refused with "estimated", a density computed from the analysis sample. Any other value is a DataError.

Intervention.name#

What this regime is called in reported parameter names: ey[treat_all].

A read-only property rather than a mutable attribute so that the frozen dataclasses below satisfy the protocol: an intervention that could be renamed after a fit had used it would put the reported parameter names out of step with the densities they came from.