Skip to main content

condensité

(pronounciation: kon-dahn-see-tay, like the French word for "density")

Installation

pip install condensite

Paper Transforming Conditional Density Estimation Into a Single Nonparametric Regression Task

Summary The approach behind condensité enables transforming conditional density estimation into a single nonparametric regression task. This package provides an implementation that allows turning regressors from popular machine learning libraries such as sklearn or torch into conditional density estimators. See below for a complete example, further ones can be found in src/examples.

Benchmarking For a benchmarking effort of conditional density estimators, see https://scoringbench.com/, which includes condensité using a HistGradBoostingRegressor. Note that condensité is a general approach that could be used in combination with any regressor.

Example

import torch
import numpy as np
import condensite as cde
from sklearn.ensemble import HistGradientBoostingRegressor

# create a condensité predictor based on sklearn's HistGradientBoostingRegressor
class TreePredictor(cde.CondensitePredictor):
    def __init__(self, params):
        self.tree = HistGradientBoostingRegressor(**params)

    def device(self):
        return "cpu"

    def to(self, device):
        return self

    def forward(self, x):
        return self.tree.predict(x)

    def predict(self, x):
        return torch.tensor(self.forward(x), dtype=torch.float32)

    def fit(self, dataset: cde.RepeatDataset):
        # create data loader (c.f. cde.RepeatDataset and cde.concat_collate)
        train_DL = torch.utils.data.DataLoader(dataset=dataset,                 
                                               batch_size=dataset.n*dataset.M, 
                                               shuffle=True, 
                                               collate_fn=cde.concat_collate)
        xtorch, ytorch = next(iter(train_DL))  # single batch of all data
        x, y = xtorch.numpy(), ytorch.numpy()
        self.tree.fit(x, y)
        return np.mean(np.square(self.tree.predict(x)-y))  # mse

# instantiate and wrap using Condensite
tree_predictor = TreePredictor(params={
    'max_bins': 40,
    'max_leaf_nodes': 100,
    'l2_regularization': 0.1,
})
hgb_model = cde.Condensite(tree_predictor, h=0.01, M=100, name='hgb_model')

# generate some data and fit
def sample_data(n_obs=1000, n_features=10):
    x = torch.empty((n_obs, n_features)).normal_(0,1)
    x1 = x[:, 0]
    std = torch.sqrt(0.25 + x1**2)
    noise = torch.distributions.Normal(torch.zeros_like(x1), std).sample()
    y = x1 + noise
    return x, y

# fit conditional density estimator
x_train, y_train = sample_data()
hgb_model.fit(x_train, y_train, train_frac=0.8, n_grid_ISE=100)

# evaluate fit out-of-sample
x_test, y_test = sample_data()
test_ISE = cde.utils.ISE(hgb_model, x_test, y_test, n_grid=100).item()
print(f'{hgb_model.name}:\t {test_ISE=:.4f}')

Reference If you find our algorithms useful please consider citing

@misc{reisach2025condensite,
    title={Transforming Conditional Density Estimation Into a Single Nonparametric Regression Task}, 
    author={Alexander G. Reisach and Olivier Collier and Alex Luedtke and Antoine Chambaz},
    year={2025},
    url={https://arxiv.org/abs/2511.18530}, 
}

Metadata

Release files for condensite 0.0.3

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

Source distribution (sdist)

Source distribution for condensite 0.0.3
File Size Uploaded Provenance
condensite-0.0.3.tar.gz 13.2 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 28.2 kB

Release files / condensite-0.0.3.tar.gz

Download URL condensite-0.0.3.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
77a383f2cd5cf08da16ef85c3df978c3883a54b7be41750a9c7a40fa108ef1f8
BLAKE2b-256 checksum
How to use checksums
f32f64de83020df66e74ee7070a9490550cdb5a3673ebc669231009fb8c9bfba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / condensite-0.0.3-py3-none-any.whl

Download URL condensite-0.0.3-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
69c1baeaaf4958bf467645d2b950f2224190dd7cfb8dd028e5c18f80a5dd4899
BLAKE2b-256 checksum
How to use checksums
a3cc71e7e148e9ac6cf39f30fcf1df7d362247517b098f9364163a626b56744a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Security for condensite 0.0.3

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.

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