Skip to main content

The engression loss (energy score) proposed by Shen et al. for distributional regression with a few convenient wrappers, in Pytorch.

Project description

Engression - Pytorch

The engression loss (energy score) proposed by Shen et al. for distributional regression with a few convenient wrappers, in Pytorch.

The paper's original code by Xinwei Shen is available here.

Install

pip install engression-pytorch

Usage

import torch
from engression_pytorch import EnergyScoreLoss, gConcat

batch_size, input_dim, out_dim = 32, 1, 1
noise_dim = 100

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

model = nn.Linear(input_dim + noise_dim, out_dim)

g = gSampler(
    model = model,
    noise_dim = noise_dim,
    noise_type = noise_type,
    noise_scale = 1.0,
    merge_mode = 'concat', # 'add', or lambda x, eps: ...
    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_eval
sample = g(x) # (batch_size, m_eval, output_dim)

Citations

@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}, 
}
@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},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

engression_pytorch-0.1.3.tar.gz (83.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

engression_pytorch-0.1.3-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file engression_pytorch-0.1.3.tar.gz.

File metadata

  • Download URL: engression_pytorch-0.1.3.tar.gz
  • Upload date:
  • Size: 83.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for engression_pytorch-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a9eac6bd6b4bbd228416ea72a932fd1924025e92e0af07897a75bf5a72979ce0
MD5 8789a993ac1668d34ab364e739519429
BLAKE2b-256 efdeaf00230dbaa1ead9e1ea353ff0a0cac92ce8bbee87784bd79e3c1e924d88

See more details on using hashes here.

File details

Details for the file engression_pytorch-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for engression_pytorch-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 aef13055d9d1769d4c09a26a1d9416c20a7a46c209c84caaed562d1f26668de6
MD5 628d7193a06b6bca71e393f7d7c606c4
BLAKE2b-256 138b917ec0597781332ab0a88f7418d440d13a6f82699494db53e91acd9e0837

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page