Metadata-Version: 2.4
Name: engression-pytorch
Version: 0.1.1
Summary: The engression loss (energy score) proposed by Shen et al. for distributional regression with a few convenient wrappers, in Pytorch.
Author-email: Emilio Cantu <ecantuc@umich.edu>
Project-URL: Homepage, https://pypi.org/project/engression-pytorch/
Project-URL: Repository, https://github.com/ecantuc/engression-pytorch
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: einops>=0.8.1
Requires-Dist: torch>=2.7.0
Provides-Extra: examples
Requires-Dist: matplotlib; extra == "examples"
Dynamic: license-file

## Engression - Pytorch

The engression loss (energy score) proposed by [Shen et al.](https://arxiv.org/abs/2307.00835) for [distributional regression](https://doi.org/10.1016/j.ecosta.2021.07.006) with a few convenient wrappers, in Pytorch.

The paper's original code by Xinwei Shen is available [here](https://github.com/xwshen51/engression). 

### Install
```
pip install engression-pytorch
```

### Usage
```python
import torch
from engression_pytorch import EnergyScoreLoss, gConcat

x = torch.randn(batch_size, input_dim)
y = torch.randn(batch_size, out_dim)
preds = torch.randn(batch_size, m, out_dim)

g = gConcat(
    model = model,
    noise_dim = 100,
    noise_type = 'normal',
    noise_scale = 1.0,
    m_train = 2, 
    m_eval = 512,
)

g.train() # change m to m_train
preds = g(x) # (batch_size, m_train, output_dim)

# loss = energy_score(y, preds, beta = 1.0, p = 2)
loss = EnergyScoreLoss(beta = 1.0, p = 2)(y, preds)
loss.backward()

g.eval() # changes m to m_predict
sample = g(x) # (batch_size, m_eval, output_dim)
```

### Citations
```bibtex
@misc{shen2024engressionextrapolationlensdistributional,
      title={Engression: Extrapolation through the Lens of Distributional Regression}, 
      author={Xinwei Shen and Nicolai Meinshausen},
      year={2024},
      eprint={2307.00835},
      archivePrefix={arXiv},
      primaryClass={stat.ME},
      url={https://arxiv.org/abs/2307.00835}, 
}
```
```bibtex
@article{KNEIB202399,
title = {Rage Against the Mean – A Review of Distributional Regression Approaches},
journal = {Econometrics and Statistics},
volume = {26},
pages = {99-123},
year = {2023},
issn = {2452-3062},
doi = {https://doi.org/10.1016/j.ecosta.2021.07.006},
url = {https://www.sciencedirect.com/science/article/pii/S2452306221000824},
author = {Thomas Kneib and Alexander Silbersdorff and Benjamin Säfken},
}
```
