API¶
DOCAS: align a regressor’s dose response with a stated target curve via synthetic rows.
- class docas.aligner.AlignedModel(model, baseline, target, treatment_idx: int, span: float)[source]¶
The aligned forecaster: the final model on
[X, r].ris the residual, the baseline’s forecast with the target effect of the logged dose removed (the forecast at zero dose). Under a what-if query only the dose changes andrstays at the logged row.
- class docas.aligner.AlignResult(model: 'AlignedModel', baseline: 'object', n_synth: 'int', alignment_error: 'float', treatment_idx: 'int', span: 'float')[source]¶
- docas.aligner.alignment_error(model, X, *, treatment_idx: int, target, span: float = 1.0, u=None) float[source]¶
RMSE between the model’s centred ICE curves and the target DRC (outcome units).
- class docas.aligner.Aligner(model, *, treatment_idx: int, target, span: float = 1.0, synth_ratio: float = 1.0, jitter: dict | None = None, seed: int = 42)[source]¶
Train a regressor on synthetic what-if rows so its dose response follows
target.- Parameters:
model – Unfitted estimator with
fit/predict(copied for the baseline and the final fit).treatment_idx – Column of
Xthat holds the dose.target – Target dose-response curve: expected change in the outcome at fractional dose
uin[0, 1]versus no dose, inyunits.target(u)ortarget(X, u).span – Physical dose at
u = 1.synth_ratio – Synthetic budget: synthetic rows as a multiple of the training size.
jitter –
{column: sd}Gaussian noise added to copied contexts.seed – Sampling seed.
Ceteris-paribus probes of a treatment column: ICE curves and partial dependence.
- docas.intervene.probe(model, X, *, treatment_idx: int, u, span: float = 1.0)[source]¶
Predictions of
modelover the dose gridu, all else fixed. Shape(n, |u|).
- docas.intervene.centred_ice(model, X, *, treatment_idx: int, u=None, span: float = 1.0)[source]¶
ICE curves minus the prediction at zero dose. Shape
(n, |u|).
- docas.intervene.audit_curve(model, X, *, treatment_idx: int, u=None, span: float = 1.0)[source]¶
Partial dependence: the mean ICE curve over the rows of
X. Shape(|u|,).
Helpers to build a target dose-response curve target(u).
- docas.targets.interp_target(u_knots, drc_knots)[source]¶
Piecewise-linear target DRC from knots;
uis the fractional dose in[0, 1].
- docas.targets.linear_fraction(drop_at_full: float = -0.3)[source]¶
DRC(u) = drop_at_full * u. A negative drop means the outcome falls with dose.
Synthetic confounded glucose / insulin toy data (no real patient records).
Severity drives both high treatment and high outcome. A regressor that is not shown the glucose column then learns the wrong sign for the dose. Useful for README and unit demos.
- class docas.datasets.synthetic_glucose.SyntheticGlucose(X: ndarray, y: ndarray, treatment_idx: int = 1, feature_names: tuple[str, ...] = ('glucose', 'insulin', 'carbs'), true_effect: float = -25.0)[source]¶
Toy panel for dose–response demos.
Columns of
Xare current glucose, the treatment dose (treatment_idx), and the meal load.yis the change in glucose over a short horizon (negative means lowering).
- docas.datasets.synthetic_glucose.make_synthetic_glucose(n: int = 2000, *, seed: int = 0, noise: float = 8.0, true_treatment_effect: float = -25.0) SyntheticGlucose[source]¶
Draw a confounded synthetic glucose panel.
- Parameters:
n – Number of rows.
seed – RNG seed.
noise – Gaussian noise std on
y(outcome units).true_treatment_effect – True interventional slope of treatment → Δglucose at unit dose (negative = treatment lowers the outcome). Observational association is typically positive because of severity confounding.