CateSim
CateSim (catesim) constructs calibrated data-generating processes for conditional average treatment effects.
Supply a finite covariate population, callable shape functions, and nine
scientific targets. calibrate freezes one mechanism. Ordinary Python loops
then handle sample sizes, replications, and comparisons.
Install
Install with Python 3.11 or later:
python -m pip install catesim
Calibration and sampling use NumPy and SciPy only. Truth-assisted fitting is optional:
python -m pip install 'catesim[fit]'
Calibrate a mechanism
For a self-contained example with no downloads:
from catesim import calibrate
from catesim.examples import make_example
population, shapes, targets = make_example(population_size=512, seed=7)
dgp = calibrate(population, shapes, targets)
data = dgp.sample(n=1000, seed=123)
truth = dgp.truth(data.X)
The factory generates a uniformly weighted population with four Gaussian covariates and returns deterministic input shapes and feasible default targets. Its seed controls the population; the sampling seed controls observations. The population support size and sample size are separate choices.
To change a target while retaining the same population and input shapes:
from dataclasses import replace
from catesim import calibrate
from catesim.examples import make_example
population, shapes, targets = make_example()
weaker = calibrate(population, shapes, replace(targets, q=0.06))
The other eight scalar targets stay fixed when feasible. Final conditional functions may change through calibration; input shapes are not those final functions. Modified targets receive the usual feasibility checks.
The same example can be constructed explicitly from a user-provided covariate matrix, callables, and targets:
import numpy as np
from catesim import EmpiricalPopulation, Shapes, Targets, calibrate
X = np.random.default_rng(7).normal(size=(512, 4))
pop = EmpiricalPopulation(X, weights=None, name="example")
shapes = Shapes(
assignment=lambda x: x[:, 0],
baseline=lambda x: x[:, 1] + 0.3 * x[:, 0] ** 2,
effect=lambda x: np.sin(x[:, 2]) + 0.2 * x[:, 3] ** 2,
)
targets = Targets(
pi=0.3, q=0.12, R0_squared=0.6,
delta=0.2, s_tau=0.7, nu=1.0,
rho_be=0.4, rho_ue=-0.2, rho_ub=0.1,
)
dgp = calibrate(pop, shapes, targets)
data = dgp.sample(n=1000, seed=123)
truth = dgp.truth(data.X)
The nine targets are:
pi: treatment prevalence, the population mean of the propensity.q: average overlap, the population mean of propensity times one minus propensity.R0_squared: baseline prognostic strength, from zero up to but not including one.delta: population mean CATE, in noise-RMS units.s_tau: population standard deviation of CATE, in the same units. Zero is a constant effect.nu: treated-to-control arm-noise RMS ratio. Zero makes the treated arm noiseless.rho_be: correlation of the control conditional mean with propensity.rho_ue: correlation of CATE with propensity.rho_ub: correlation of the control conditional mean with CATE.
Undefined correlations are None, not zero. Attainable values and the cases
where a correlation is undefined are documented in help(Targets).
The initial gauge fixes the population mean of the control conditional mean
at zero and factual noise RMS at one, so delta and s_tau are in noise units.
Noise RMS is the square root of the population average conditional noise
variance, not the factual outcome SD or the average conditional SD.
Treatment is binary, outcomes are continuous, and arm errors are independent
standard Gaussians. A finite arm-noise ratio may be zero, which makes the
treated arm noiseless. Fully noiseless mechanisms are outside this gauge.
Shape callables take a covariate matrix and return one value per row. They are not copied at calibration time, so they must be deterministic and their captured state must stay fixed. Omitted noise shapes default to the constant one. An unused assignment, baseline, or effect shape may be omitted and is not called.
dgp.calibration reports targets, achieved values, residuals, tolerances,
and the frozen coefficients. dgp.characteristics() and
dgp.approximation() can take a separate evaluation population without
recalibrating.
Sample and compare
draw_randomness builds a reusable draw collection;
draws.prefix(n) is the nested-sample contract. sample(n, seed) is the
same mechanism applied to draw_randomness(n, seed).
cate_mse scores a CATE prediction against conditional truth under explicit
weights. Pass population.weights when the truth and predictions cover the
calibration population.
Core API docstrings describe parameter shapes, units, feasibility, returned
objects, and runnable examples. Use help(Targets), help(calibrate),
help(dgp.sample), or help(cate_mse) in Python to inspect the API.
Examples in those docstrings are exercised by the test suite and use only
the core dependencies.
Truth-assisted fitting
Optional truth-assisted fitting is available in catesim.fitting.
From a source tree, python -m pip install '.[fit]' installs the extra
shown above.
The fitter requires known CATE on every declared population row. It estimates
propensity and a pooled baseline from Y - T * cate(X), with a common Gaussian
noise SD estimated from cross-fitted baseline residuals. It does not estimate
an unknown causal effect from observational outcomes.
from catesim import calibrate
from catesim.examples import make_example
from catesim.fitting import fit_truth_assisted
population, shapes, targets = make_example(population_size=128)
source = calibrate(population, shapes, targets)
observed = source.sample(n=1000, seed=123)
fit = fit_truth_assisted(
population, observed.X, observed.T, observed.Y,
cate=source.truth().tau, seed=7, propensity_clip=None,
)
fitted = calibrate(fit.population, fit.shapes, fit.targets)
generated = fitted.sample(n=1000, seed=456)
original_units_Y = fit.outcome_offset + fit.outcome_scale * generated.Y
original_units_cate = fit.outcome_scale * fitted.truth(generated.X).tau
The result contains read-only fitted surface tables, raw propensity scores, calibration inputs, and diagnostics. Fitted shapes support only the declared covariate rows; there is no covariate generation or extrapolation. Population weights define calibration and sampling, not observation-fitting weights. The original-unit transformation is separate from the core's noise-based gauge. Changing the returned targets intentionally changes the fitted mechanism.
By default, propensity clipping at 1e-6 is explicit and counted. Raw decision
scores are retained because clipping can erase ordering needed for later
calibration; use propensity_clip=None to keep the original finite score family,
as above. Residual diagnostics expose mean-model error and deviations from the
assumed Gaussian, constant-variance noise law. Residual RMS need not equal true
irreducible noise SD. Defaults and overrides are recorded; there is no tuning
or automatic reconstruction-quality guarantee. See help(fit_truth_assisted).
Importing the module or inspecting a result needs no optional dependencies;
scikit-learn and threadpoolctl are loaded only when fitting is called.
Metadata
Release files for catesim 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| catesim-0.1.0.tar.gz | 45.3 kB | With provenance | Details for catesim-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| catesim-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for catesim-0.1.0-py3-none-any.whl |
Total release size: 82.6 kB
Release files / catesim-0.1.0.tar.gz
| Download URL | catesim-0.1.0.tar.gz |
|---|---|
| Size | 45.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6d2be72b15b90345b8b41a6241f6cff8919351e98dc246ae474a89d39ebc1fe5
|
|
BLAKE2b-256 checksum How to use checksums |
7a9a000dcbdb3b4248841142ab09ff5079923e238d6bb4a29c04b70ca85e9cab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / catesim-0.1.0-py3-none-any.whl
| Download URL | catesim-0.1.0-py3-none-any.whl |
|---|---|
| Size | 37.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
745d3c724d133771409a7b8910352154ead7389fbb3a60e7140d5db61002eae8
|
|
BLAKE2b-256 checksum How to use checksums |
9ab6ca9c93c65daf12ff66a837185c785ea1c40d3861c037b6f457463fd34fce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logSecurity for catesim 0.1.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for catesim-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logA 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.