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].

r is 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 and r stays at the logged row.

class docas.aligner.AlignResult(model: 'AlignedModel', baseline: 'object', n_synth: 'int', alignment_error: 'float', treatment_idx: 'int', span: 'float')[source]
predict(X)[source]

Predictions of the aligned model.

curve(X, *, u=None)[source]

Partial dependence of the aligned model as the fractional dose goes from 0 to 1.

baseline_curve(X, *, u=None)[source]

The same curve for the observational baseline.

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 X that holds the dose.

  • target – Target dose-response curve: expected change in the outcome at fractional dose u in [0, 1] versus no dose, in y units. target(u) or target(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.

synthetic_rows(X, r)[source]

Synthetic rows [X, r] and their labels r + DRC(probe dose).

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 model over the dose grid u, 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; u is 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 X are current glucose, the treatment dose (treatment_idx), and the meal load. y is the change in glucose over a short horizon (negative means lowering).

property span: float

the 95th percentile of the treatment column.

Type:

A practical full dose

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.