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 lightGBM as a regressor. 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.4

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.4
File Size Uploaded Provenance
condensite-0.0.4.tar.gz 13.6 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 29.7 kB

Release files / condensite-0.0.4.tar.gz

Download URL condensite-0.0.4.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0d663768de507d844fc28c22918fadebed74784087866b1825247b0643306410
BLAKE2b-256 checksum
How to use checksums
6d1367f263650ace37e29dbf4090d734d91d762d7f5d7503f9f744308b8da379
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.4-py3-none-any.whl

Download URL condensite-0.0.4-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee428dd406894657ee57c5e80cd1ce51de886cda39e9eefe15536d7d5676337b
BLAKE2b-256 checksum
How to use checksums
8daccd258d55fa1dac2491114b9cf6aca93ea18f2d63f5066fd5a41a7fab4a2b
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.4

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