Isotonic Distributional Regression (IDR)
Project description
isodistrreg: Python bindings
Python bindings for Isotonic Distributional Regression (IDR) and Survival-IDR (S-IDR), built with PyO3 and maturin. See the main README for background and references.
Installation
pip install isodistrreg
Pre-built wheels are provided for Linux, macOS, and Windows on CPython 3.13+. On other platforms pip builds from the source distribution, which requires a Rust toolchain.
The scikit-learn–compatible estimator is available through an optional extra:
pip install "isodistrreg[scikit-learn]"
Examples
We use numpy to set up a toy problem, but plain python lists can also be used.
Precision
CDF outputs (cdf, cdf_at, cdf_grid) are always np.float32. Covariates and
thresholds are stored at the dtype of the input arrays passed to IDR(...):
float32 inputs stay float32, float64 inputs stay float64, and .X /
.thresholds return zero-copy views at the storage dtype. See the docstring on
IDR.cdf and IDR.from_cdfs in _core.pyi for the full rules.
Example 1: Covariate 1-dimensional, outcome censored
import numpy as np
# we visualize with matplotlib
from matplotlib import pyplot as plt
from isodistrreg import IDR
# Generate an instance of increasing conditional CDFs with censoring, and a one-dimensional covariate
n = 500
rng = np.random.default_rng(seed=123)
x = rng.uniform(size=n)
y = x + rng.uniform(size=n)
c = x + rng.uniform(size=n)
t = np.minimum(y, c)
d = y <= c
# Fit the IDR / S-IDR model, censoring is indicated by "False"
fit = IDR(t, x, d)
# Sorted and deduplicated covariates and thresholds are available
sorted_x = fit.X
sorted_y = fit.thresholds
# Estimate and plot the complete distributional estimate
cdf_for_each_x = fit.cdf(sorted_x)
def plot_cdfs_nicely(cdfs, centers, times):
"""Plot a picture with the right scale; plt.imshow is simpler, but spacing along the axis is not to scale"""
plt.pcolormesh(
[centers[0] - (centers[1] - centers[0]) / 2]
+ list((centers[1:] + centers[:-1]) / 2)
+ [centers[-1] + (centers[-1] - centers[-2]) / 2],
list(times) + [times[-1] + (times[-1] - times[0]) / len(times)],
cdfs.T,
vmin=0.0,
vmax=1.0,
)
plot_cdfs_nicely(cdf_for_each_x, sorted_x, sorted_y)
plt.colorbar()
# Estimate and plot the mean
mean_for_each_x = fit.predict(sorted_x)
# Due to censoring, the estimated sub-CDF may not always have a mean
plt.plot(sorted_x, sorted_x + 0.5, color="lightblue", label="true mean")
plt.plot(sorted_x, mean_for_each_x, color="red", label="mean")
# Estimate and plot quantiles
probabilities = np.array([0.2, 0.8])
quantiles = fit.quantile(sorted_x[:, np.newaxis], probabilities)
plt.plot(sorted_x, quantiles, label=[f"{p} quantile" for p in probabilities])
plt.legend(loc="lower right")
plt.show()
Example 2: Covariate 3-dimensional
import numpy as np
from isodistrreg import IDR
## toy data (3-dimensional covariate)
X = np.column_stack([np.arange(1, 5)] * 3)
y = np.array([1, 0, 2, 2])
## fit
idr_fit = IDR(X = X, y = y)
## get CDF for new x at all relevant thresholds
new_x = np.array([[1, 1, 1], [1.5, 1.5, 1.5]])
idr_fit.cdf(new_x) # (one CDF per row = per x)
## broadcasting
idr_fit.cdf_at(new_x, 0) # (evaluate CDF at 0 for all covariates)
idr_fit.cdf_at(new_x, [0,1]) # (evaluate CDF for x1 at 0, x2 at 1)
idr_fit.cdf_at(new_x, np.column_stack([[1, 2, 3], [0, 1, 2]])) # (CDF at 1,2,3 for x1, and 0,1,2 for x2)
## same for quantiles
idr_fit.quantile(new_x, 0.5)
idr_fit.quantile(new_x, [0.25, 0.5])
idr_fit.quantile(new_x, np.column_stack([[0.25, 0.5, 0.75], [0.1, 0.2, 0.3]]))
# Fast grid evaluation for 1-dimensional covariate
X = np.arange(5)
y = np.arange(5)
idr_fit = IDR(X = X, y = y)
idr_fit.cdf_grid(X, y) # (CDF at all covariate-threshold-combinations)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file isodistrreg-0.5.2.tar.gz.
File metadata
- Download URL: isodistrreg-0.5.2.tar.gz
- Upload date:
- Size: 289.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d261db2a5e885b75a8bc8ef582a143be8b253182ccde99f65948a30a7418970e
|
|
| MD5 |
9cd7ee18d0b897ded5c1a269cdad2fff
|
|
| BLAKE2b-256 |
3bd960e8dac16f6b366bbeb10d6c5df1992b707ce1e85f7af7d92cf52da1c7e0
|
Provenance
The following attestation bundles were made for isodistrreg-0.5.2.tar.gz:
Publisher:
release.yml on AlexanderHenzi/isodistrreg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
isodistrreg-0.5.2.tar.gz -
Subject digest:
d261db2a5e885b75a8bc8ef582a143be8b253182ccde99f65948a30a7418970e - Sigstore transparency entry: 2138827833
- Sigstore integration time:
-
Permalink:
AlexanderHenzi/isodistrreg@0666128ac49dab4b21a8a4a49a354d886f906161 -
Branch / Tag:
refs/tags/v0.5.2 - Owner: https://github.com/AlexanderHenzi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0666128ac49dab4b21a8a4a49a354d886f906161 -
Trigger Event:
release
-
Statement type:
File details
Details for the file isodistrreg-0.5.2-cp313-abi3-win_amd64.whl.
File metadata
- Download URL: isodistrreg-0.5.2-cp313-abi3-win_amd64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.13+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02e9e4adade5acc74fbc75e27ec711ad5e5a642664108eae49fd3dcb634d1621
|
|
| MD5 |
4398f380ec610a2dc35229fdac1fc4f9
|
|
| BLAKE2b-256 |
f88d97685defecb0b068d5101a6bd5e7a7a32ffc3b90d396118781fd4ed3310d
|
Provenance
The following attestation bundles were made for isodistrreg-0.5.2-cp313-abi3-win_amd64.whl:
Publisher:
release.yml on AlexanderHenzi/isodistrreg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
isodistrreg-0.5.2-cp313-abi3-win_amd64.whl -
Subject digest:
02e9e4adade5acc74fbc75e27ec711ad5e5a642664108eae49fd3dcb634d1621 - Sigstore transparency entry: 2138827870
- Sigstore integration time:
-
Permalink:
AlexanderHenzi/isodistrreg@0666128ac49dab4b21a8a4a49a354d886f906161 -
Branch / Tag:
refs/tags/v0.5.2 - Owner: https://github.com/AlexanderHenzi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0666128ac49dab4b21a8a4a49a354d886f906161 -
Trigger Event:
release
-
Statement type:
File details
Details for the file isodistrreg-0.5.2-cp313-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: isodistrreg-0.5.2-cp313-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.13+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
954e9664664379104c932bd787475c12aeb8984d5d25ba31fbff595dae1518e7
|
|
| MD5 |
e0acd512c6d83a46f2f81a6d02f0c8b5
|
|
| BLAKE2b-256 |
82376d7ca5c9e402b7ea55ea8fe3d8e0be1fb547e0ecc258628d51249e15d0c5
|
Provenance
The following attestation bundles were made for isodistrreg-0.5.2-cp313-abi3-manylinux_2_34_x86_64.whl:
Publisher:
release.yml on AlexanderHenzi/isodistrreg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
isodistrreg-0.5.2-cp313-abi3-manylinux_2_34_x86_64.whl -
Subject digest:
954e9664664379104c932bd787475c12aeb8984d5d25ba31fbff595dae1518e7 - Sigstore transparency entry: 2138827906
- Sigstore integration time:
-
Permalink:
AlexanderHenzi/isodistrreg@0666128ac49dab4b21a8a4a49a354d886f906161 -
Branch / Tag:
refs/tags/v0.5.2 - Owner: https://github.com/AlexanderHenzi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0666128ac49dab4b21a8a4a49a354d886f906161 -
Trigger Event:
release
-
Statement type:
File details
Details for the file isodistrreg-0.5.2-cp313-abi3-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: isodistrreg-0.5.2-cp313-abi3-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.13+, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e31579d6277f7790b44869cf632466d8e02d04e9a1c1a66bc43d043fd721fbd
|
|
| MD5 |
79522b1c3fe5f0098959ca26a78ea63c
|
|
| BLAKE2b-256 |
3f6c83d7e2ce56d1e867606f027703584e74ac10ce17ce506cc5c077de1d871e
|
Provenance
The following attestation bundles were made for isodistrreg-0.5.2-cp313-abi3-manylinux_2_34_aarch64.whl:
Publisher:
release.yml on AlexanderHenzi/isodistrreg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
isodistrreg-0.5.2-cp313-abi3-manylinux_2_34_aarch64.whl -
Subject digest:
1e31579d6277f7790b44869cf632466d8e02d04e9a1c1a66bc43d043fd721fbd - Sigstore transparency entry: 2138827882
- Sigstore integration time:
-
Permalink:
AlexanderHenzi/isodistrreg@0666128ac49dab4b21a8a4a49a354d886f906161 -
Branch / Tag:
refs/tags/v0.5.2 - Owner: https://github.com/AlexanderHenzi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0666128ac49dab4b21a8a4a49a354d886f906161 -
Trigger Event:
release
-
Statement type:
File details
Details for the file isodistrreg-0.5.2-cp313-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: isodistrreg-0.5.2-cp313-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.13+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37473092cc988acb93095cde0dda306bd095b095081bb6337cac40b2578e4854
|
|
| MD5 |
cac504a3ad858181333c7be606b55884
|
|
| BLAKE2b-256 |
e0fd5c65410a71f2f78688c620ca4ca0cbefe1e87243eb9a2881b193f5f85499
|
Provenance
The following attestation bundles were made for isodistrreg-0.5.2-cp313-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on AlexanderHenzi/isodistrreg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
isodistrreg-0.5.2-cp313-abi3-macosx_11_0_arm64.whl -
Subject digest:
37473092cc988acb93095cde0dda306bd095b095081bb6337cac40b2578e4854 - Sigstore transparency entry: 2138827910
- Sigstore integration time:
-
Permalink:
AlexanderHenzi/isodistrreg@0666128ac49dab4b21a8a4a49a354d886f906161 -
Branch / Tag:
refs/tags/v0.5.2 - Owner: https://github.com/AlexanderHenzi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0666128ac49dab4b21a8a4a49a354d886f906161 -
Trigger Event:
release
-
Statement type:
File details
Details for the file isodistrreg-0.5.2-cp313-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: isodistrreg-0.5.2-cp313-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.13+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cb25203038c12bbf7f0649b424c1500e46e83253a7f6857e865bee8f3cfc709
|
|
| MD5 |
007c1c8a28addc9fc18a086daa6809a9
|
|
| BLAKE2b-256 |
9d42778ac69c2996cb840b44e90860645335ec8d17f808d79463c2d41e486047
|
Provenance
The following attestation bundles were made for isodistrreg-0.5.2-cp313-abi3-macosx_10_12_x86_64.whl:
Publisher:
release.yml on AlexanderHenzi/isodistrreg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
isodistrreg-0.5.2-cp313-abi3-macosx_10_12_x86_64.whl -
Subject digest:
5cb25203038c12bbf7f0649b424c1500e46e83253a7f6857e865bee8f3cfc709 - Sigstore transparency entry: 2138827893
- Sigstore integration time:
-
Permalink:
AlexanderHenzi/isodistrreg@0666128ac49dab4b21a8a4a49a354d886f906161 -
Branch / Tag:
refs/tags/v0.5.2 - Owner: https://github.com/AlexanderHenzi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0666128ac49dab4b21a8a4a49a354d886f906161 -
Trigger Event:
release
-
Statement type: