Metadata-Version: 2.4
Name: calpit
Version: 0.2.0
Author-email: Biprateep Dey <biprateep@pitt.edu>
License: MIT License
        
        Copyright (c) 2023 Biprateep Dey
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Source Code, https://github.com/lee-group-cmu/Cal-PIT
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: scipy>=1.6
Provides-Extra: torch
Requires-Dist: lightning>=2.0; extra == "torch"
Requires-Dist: spline-basis; extra == "torch"
Requires-Dist: torch; extra == "torch"
Provides-Extra: sklearn
Requires-Dist: scikit-learn>=1.4; extra == "sklearn"
Provides-Extra: qp
Requires-Dist: qp-prob; extra == "qp"
Provides-Extra: hdf5
Requires-Dist: h5py; extra == "hdf5"
Provides-Extra: plot
Requires-Dist: matplotlib; extra == "plot"
Provides-Extra: all
Requires-Dist: calpit[hdf5,plot,qp,sklearn,torch]; extra == "all"
Provides-Extra: dev
Requires-Dist: calpit[all]; extra == "dev"
Requires-Dist: jupyter; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Dynamic: license-file

# Cal-PIT

[![Documentation](https://readthedocs.org/projects/cal-pit/badge/?version=latest)](https://docs.readthedocs.io/en/stable/badges.html) [![Template](https://img.shields.io/badge/Template-LINCC%20Frameworks%20Python%20Project%20Template-brightgreen)](https://lincc-ppt.readthedocs.io/en/latest/)

Full Documentation
---------------------------
Full documentation for the project is available on [Read the Docs](https://cal-pit.readthedocs.io/en/latest/)

Overview
---------------------------

`calpit` diagnoses and recalibrates conditional density estimates (CDEs). It learns how the probability integral transform (PIT) of the CDEs varies with the features, which gives local P-P plots that show where the CDEs are miscalibrated, and a recalibration of the CDEs themselves.

- CDEs can be densities on a grid, quantiles, samples or [qp](https://github.com/LSSTDESC/qp) ensembles.
- Cal-PIT can be learned by any PyTorch network, trained with PyTorch Lightning, or by any scikit-learn classifier.
- `CalPIT` follows the scikit-learn API, and every piece of the training is importable for hand-written training loops.


Basic Usage
---------------------------

```python
import calpit

recalibrator = calpit.CalPIT().fit(x_calib, y_calib, calpit.GridCDE(pdf_calib, y_grid))

local = recalibrator.diagnose(x_test)  # Local P-P curves and their distance from the diagonal.
cde_new = recalibrator.transform(x_test, calpit.GridCDE(pdf_test, y_grid))  # Recalibrated CDEs.
```

See the [user guide](https://cal-pit.readthedocs.io/en/latest/usage.html) for quantile, sample and qp CDEs, scikit-learn models and [hand-written training loops](https://cal-pit.readthedocs.io/en/latest/training_loop.html).


Installation
---------------------------

```console
   pip install 'calpit[torch]'
```

The core needs only NumPy and SciPy; models and file formats come with extras:

| Extra | Installs | Needed for |
|---|---|---|
| `torch` | `torch`, `lightning`, `spline-basis` | PyTorch models, including the default `calpit.nn.IsplineNN` |
| `sklearn` | `scikit-learn` | scikit-learn models |
| `qp` | `qp-prob` | `calpit.qp_io` |
| `hdf5` | `h5py` | `calpit.nn.PhotometryDataset` |
| `plot` | `matplotlib` | `calpit.utils.plot_pit`, `calpit.diagnostics.plot_local_pp` |
| `all` | all of the above | |

`calpit` needs Python 3.11 or later.

To install the latest version of the code from Github, you can run the following command:

```console
  pip install git+https://github.com/lee-group-cmu/Cal-PIT
```

If you would like to install the package for development purposes, you can clone the repository and install the package in editable mode:

```console
   >> git clone https://github.com/lee-group-cmu/Cal-PIT.git
   >> cd Cal-PIT
   >> pip install -e '.[dev]'
```

