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.

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,
})
sklearn_model = cde.Condensite(tree_predictor, h=0.01, M=100, name='sklearn_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()
sklearn_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(sklearn_model, x_test, y_test, n_grid=100).item()
print(f'{sklearn_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.2

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.2
File Size Uploaded Provenance
condensite-0.0.2.tar.gz 12.1 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 25.6 kB

Release files / condensite-0.0.2.tar.gz

Download URL condensite-0.0.2.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dc1dbcf656d83cda210f8c3e13c2e63a338766b4e37bbb445ed2dc82c9c6f5fe
BLAKE2b-256 checksum
How to use checksums
e993de88fd688c99dd44df73203e4fd0feacffab4b01ee4d81585ad71a7e2a94
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.2-py3-none-any.whl

Download URL condensite-0.0.2-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52aea22e547b8d1ffe3399cd703b3a964e3f4568077b36497ccbb0b7f18a51ab
BLAKE2b-256 checksum
How to use checksums
557d25ba3e95e829daaba8592c924c83363ebdbd31328d7c5c23bf629bdf1149
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.2

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