Skip to main content

DOCAS

DOCAS: dose-response curve alignment

Dose-response curve alignment via synthetic augmentation

DOCAS makes any fit / predict regressor follow a stated target dose-response curve (DRC) when you change its dose input, without changing the model or its loss. It trains the model on synthetic what-if rows only, with one extra input, the residual: the baseline's forecast at zero dose. The alignment error (AE) measures how far the model's what-if predictions are from the curve, in the units of the outcome, next to the usual RMSE.

Why

Models trained on observational data learn how treatment was given, not what it does. In type 1 diabetes, for example, patients bolus insulin when glucose is high or when they eat, so large doses appear together with high glucose. A forecaster can therefore predict glucose well on held-out data and still predict higher glucose for more insulin. Ceteris paribus plots (ICE curves and partial dependence plots) show this visually. The alignment error (AE) quantifies it: the RMSE between each ICE curve and the target DRC, reported next to the usual RMSE.

Note that the target DRC is the observed change in outcome when a dose is taken, whereas an ICE curve is the change in the model's prediction when only the dose input changes. The target DRC is a stated reference, e.g. a population curve from pharmacology, and not an individual ground truth.

How it works

DOCAS in three phases: target curve, synthetic rows, training and audit

  1. Target curve (A-B). State the dose-response curve the model should follow.
  2. Residual (C). Fit the baseline on the observed rows. Its forecast minus the curve's effect of the logged dose is the residual r, the forecast at zero dose.
  3. Synthetic rows (D-E). Draw training rows with replacement, add small Gaussian noise to the context, replace the dose with a probe dose (half drawn from the observed doses, half uniform), and label each row r + DRC(probe dose).
  4. Train and audit (F-G). Train the unchanged model once on the synthetic rows with r as an extra input. At prediction time r comes from the same baseline. Audit the learned response with ICE curves and the alignment error.

Install

pip install docas

Core: numpy. Examples and tests: scikit-learn.

Quick start

Toy data, not patient data. A hidden severity raises both the dose and the outcome. Glucose records that reason; drop it, and a normal regressor reads the dose itself as a sign of severity, so a larger dose predicts a higher outcome.

import numpy as np
from sklearn.ensemble import HistGradientBoostingRegressor

from docas import Aligner
from docas.datasets import make_synthetic_glucose

data = make_synthetic_glucose(n=2_000, seed=0)
X, y = data.X[:, 1:], data.y  # insulin, carbs; glucose is left out

result = Aligner(
    HistGradientBoostingRegressor(max_depth=3, max_iter=80, random_state=0),
    treatment_idx=0,                                              # the dose column
    target=lambda u: data.true_effect * data.span * np.asarray(u, float),
    span=data.span,                                               # dose at u = 1
    synth_ratio=1.0,                                              # synthetic budget
    jitter={1: 5.0},                                              # noise on carbs
).fit(X, y)

u = np.linspace(0, 1, 6)
print("align. error :", round(result.alignment_error, 3))
print("baseline     :", np.round(result.baseline_curve(X, u=u), 2))
print("aligned      :", np.round(result.curve(X, u=u), 2))

The baseline curve rises with the dose; the aligned curve falls along the target. result.predict(X) gives the aligned model's ordinary forecasts.

What you can change

Argument Default Meaning
model required Any unfitted fit / predict regressor (CatBoost, an MLP, scikit-learn)
treatment_idx required Column of X that holds the dose
target required Target DRC in y units: target(u) or target(X, u), with u the fractional dose in [0, 1]
span 1.0 Physical dose at u = 1
synth_ratio 1.0 Synthetic budget: synthetic rows per observed row
jitter None {column: sd} Gaussian noise on the copied contexts
seed 42 Sampling seed

A target that uses X can scale the response with the context, for example a larger glucose drop at higher current glucose: lambda X, u: -0.15 * X[:, 0] * u. interp_target(knots, values) and linear_fraction(drop) build simple curves.

Public API

Symbol Role
Aligner(...).fit(X, y) Fit the baseline and the aligned model; returns an AlignResult
AlignResult predict, curve, baseline_curve, alignment_error, n_synth, model, baseline
alignment_error(model, X, ...) AE of any model against a target curve
probe / centred_ice / audit_curve ICE curves and partial dependence
interp_target / linear_fraction Build a target curve
docas.datasets.make_synthetic_glucose Confounded toy data
python examples/01_quickstart.py       # the quick start
python examples/02_custom_target.py    # target curve from knots
python examples/03_sklearn_pipeline.py # ridge regression

The type 1 diabetes study (OhioT1DM, AZT1D, HUPA-UCM, and T1D-UOM; UVa/Padova target curve; ReplayBG evaluation) lives in the manuscript repository.

License

MIT

Metadata

Release files for docas 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docas 0.7.0
File Size Uploaded Provenance Actions
docas-0.7.0.tar.gz 12.6 kB Without provenance Details for docas-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for docas 0.7.0
File Interpreter ABI Platform Actions
docas-0.7.0-py3-none-any.whl Python 3 none any Details for docas-0.7.0-py3-none-any.whl

Total release size: 23.2 kB

Release files / docas-0.7.0.tar.gz

Download URL docas-0.7.0.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
09e2dc2d4d4def6383d9ab33248b485063abd55c7f6cd377a81e658186af8afd
BLAKE2b-256 checksum
How to use checksums
ea39f2bf07ec726204862106b3775ed93f58af65f7f72b36316cca8eac64d75c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / docas-0.7.0-py3-none-any.whl

Download URL docas-0.7.0-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6877bc693d0491ef4fecdd116e2cd93e6c333ba5e9c78936570539b3821ff066
BLAKE2b-256 checksum
How to use checksums
5e9abb90131b067d35dc4efbf02b9e636972b31978b994ab47f52908056aec01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.21 {"installer":{"name":"uv","version":"0.12.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for docas 0.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page