hl-gauss-pytorch


Namehl-gauss-pytorch JSON
Version 0.1.19 PyPI version JSON
download
home_pageNone
SummaryHL Gauss - Pytorch
upload_time2025-02-11 22:30:35
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT License Copyright (c) 2025 Phil Wang 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.
keywords artificial intelligence deep learning regression as classification
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="./fig2.png" width="500px"></img>

## HL Gauss - Pytorch

The Gaussian Histogram Loss (HL-Gauss) proposed by [Imani et al.](https://proceedings.mlr.press/v80/imani18a/imani18a.pdf) with a few convenient wrappers, in Pytorch.

A team at Deepmind wrote a [paper](https://arxiv.org/abs/2403.03950) with a lot of positive findings for its use in value-based RL.

Put into action [here](https://github.com/lucidrains/phasic-policy-gradient), seems to work well

## Install

```bash
$ pip install hl-gauss-pytorch
```

## Usage

The `HLGaussLoss` module as defined in Appendix A. of the [Stop Regressing paper](https://arxiv.org/abs/2403.03950)

```python
import torch
from hl_gauss_pytorch import HLGaussLoss

hl_gauss = HLGaussLoss(
    min_value = 0.,
    max_value = 5.,
    num_bins = 32,
    sigma = 0.5,
    clamp_to_range = True # this was added because if any values fall outside of the bins, the loss is 0 with the current logic
)

logits = torch.randn(3, 16, 32).requires_grad_()
targets = torch.randint(0, 5, (3, 16)).float()

loss = hl_gauss(logits, targets)
loss.backward()

# after much training

pred_target = hl_gauss(logits) # (3, 16)
```

For a convenient layer that predicts from embedding to logits, import `HLGaussLayer`

```python
import torch
from hl_gauss_pytorch import HLGaussLayer

hl_gauss_layer = HLGaussLayer(
    dim = 256, # input embedding dimension
    hl_gauss_loss = dict(
        min_value = 0.,
        max_value = 5.,
        num_bins = 32,
        sigma = 0.5,
    )
)

embed = torch.randn(7, 256)
targets = torch.randint(0, 5, (7,)).float()

loss = hl_gauss_layer(embed, targets)
loss.backward()

# after much training

pred_target = hl_gauss_layer(embed) # (7,)
```

For ablating the proposal, you can make the `HLGaussLayer` fall back to regular regression by setting `use_regression = True`, keeping the code above unchanged

```python
HLGaussLayer(..., use_regression = True)
```

## Citations

```bibtex
@article{Imani2024InvestigatingTH,
    title   = {Investigating the Histogram Loss in Regression},
    author  = {Ehsan Imani and Kai Luedemann and Sam Scholnick-Hughes and Esraa Elelimy and Martha White},
    journal = {ArXiv},
    year    = {2024},
    volume  = {abs/2402.13425},
    url     = {https://api.semanticscholar.org/CorpusID:267770096}
}
```

```bibtex
@inproceedings{Imani2018ImprovingRP,
    title   = {Improving Regression Performance with Distributional Losses},
    author  = {Ehsan Imani and Martha White},
    booktitle = {International Conference on Machine Learning},
    year    = {2018},
    url     = {https://api.semanticscholar.org/CorpusID:48365278}
}
```

```bibtex
@article{Farebrother2024StopRT,
    title   = {Stop Regressing: Training Value Functions via Classification for Scalable Deep RL},
    author  = {Jesse Farebrother and Jordi Orbay and Quan Ho Vuong and Adrien Ali Taiga and Yevgen Chebotar and Ted Xiao and Alex Irpan and Sergey Levine and Pablo Samuel Castro and Aleksandra Faust and Aviral Kumar and Rishabh Agarwal},
    journal = {ArXiv},
    year   = {2024},
    volume = {abs/2403.03950},
    url    = {https://api.semanticscholar.org/CorpusID:268253088}
}
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "hl-gauss-pytorch",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "artificial intelligence, deep learning, regression as classification",
    "author": null,
    "author_email": "Phil Wang <lucidrains@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/79/6c/c25965f6b1b964624df716c91b6e51ee9a80eca81e6b2e8bcd85c61e4465/hl_gauss_pytorch-0.1.19.tar.gz",
    "platform": null,
    "description": "<img src=\"./fig2.png\" width=\"500px\"></img>\n\n## HL Gauss - Pytorch\n\nThe Gaussian Histogram Loss (HL-Gauss) proposed by [Imani et al.](https://proceedings.mlr.press/v80/imani18a/imani18a.pdf) with a few convenient wrappers, in Pytorch.\n\nA team at Deepmind wrote a [paper](https://arxiv.org/abs/2403.03950) with a lot of positive findings for its use in value-based RL.\n\nPut into action [here](https://github.com/lucidrains/phasic-policy-gradient), seems to work well\n\n## Install\n\n```bash\n$ pip install hl-gauss-pytorch\n```\n\n## Usage\n\nThe `HLGaussLoss` module as defined in Appendix A. of the [Stop Regressing paper](https://arxiv.org/abs/2403.03950)\n\n```python\nimport torch\nfrom hl_gauss_pytorch import HLGaussLoss\n\nhl_gauss = HLGaussLoss(\n    min_value = 0.,\n    max_value = 5.,\n    num_bins = 32,\n    sigma = 0.5,\n    clamp_to_range = True # this was added because if any values fall outside of the bins, the loss is 0 with the current logic\n)\n\nlogits = torch.randn(3, 16, 32).requires_grad_()\ntargets = torch.randint(0, 5, (3, 16)).float()\n\nloss = hl_gauss(logits, targets)\nloss.backward()\n\n# after much training\n\npred_target = hl_gauss(logits) # (3, 16)\n```\n\nFor a convenient layer that predicts from embedding to logits, import `HLGaussLayer`\n\n```python\nimport torch\nfrom hl_gauss_pytorch import HLGaussLayer\n\nhl_gauss_layer = HLGaussLayer(\n    dim = 256, # input embedding dimension\n    hl_gauss_loss = dict(\n        min_value = 0.,\n        max_value = 5.,\n        num_bins = 32,\n        sigma = 0.5,\n    )\n)\n\nembed = torch.randn(7, 256)\ntargets = torch.randint(0, 5, (7,)).float()\n\nloss = hl_gauss_layer(embed, targets)\nloss.backward()\n\n# after much training\n\npred_target = hl_gauss_layer(embed) # (7,)\n```\n\nFor ablating the proposal, you can make the `HLGaussLayer` fall back to regular regression by setting `use_regression = True`, keeping the code above unchanged\n\n```python\nHLGaussLayer(..., use_regression = True)\n```\n\n## Citations\n\n```bibtex\n@article{Imani2024InvestigatingTH,\n    title   = {Investigating the Histogram Loss in Regression},\n    author  = {Ehsan Imani and Kai Luedemann and Sam Scholnick-Hughes and Esraa Elelimy and Martha White},\n    journal = {ArXiv},\n    year    = {2024},\n    volume  = {abs/2402.13425},\n    url     = {https://api.semanticscholar.org/CorpusID:267770096}\n}\n```\n\n```bibtex\n@inproceedings{Imani2018ImprovingRP,\n    title   = {Improving Regression Performance with Distributional Losses},\n    author  = {Ehsan Imani and Martha White},\n    booktitle = {International Conference on Machine Learning},\n    year    = {2018},\n    url     = {https://api.semanticscholar.org/CorpusID:48365278}\n}\n```\n\n```bibtex\n@article{Farebrother2024StopRT,\n    title   = {Stop Regressing: Training Value Functions via Classification for Scalable Deep RL},\n    author  = {Jesse Farebrother and Jordi Orbay and Quan Ho Vuong and Adrien Ali Taiga and Yevgen Chebotar and Ted Xiao and Alex Irpan and Sergey Levine and Pablo Samuel Castro and Aleksandra Faust and Aviral Kumar and Rishabh Agarwal},\n    journal = {ArXiv},\n    year   = {2024},\n    volume = {abs/2403.03950},\n    url    = {https://api.semanticscholar.org/CorpusID:268253088}\n}\n```\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2025 Phil Wang\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.",
    "summary": "HL Gauss - Pytorch",
    "version": "0.1.19",
    "project_urls": {
        "Homepage": "https://pypi.org/project/hl-gauss-pytorch/",
        "Repository": "https://github.com/lucidrains/hl-gauss-pytorch"
    },
    "split_keywords": [
        "artificial intelligence",
        " deep learning",
        " regression as classification"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "02b71e2f32cb333d1a444950170447c842657b18233dde3d9859f84083825849",
                "md5": "52f7eb17ab446cd5caf9f6b37aae7fce",
                "sha256": "cb5248f78b1e368155ac3bae2f436321c89704d1a33287309ed4cc5104e0b929"
            },
            "downloads": -1,
            "filename": "hl_gauss_pytorch-0.1.19-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "52f7eb17ab446cd5caf9f6b37aae7fce",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 8793,
            "upload_time": "2025-02-11T22:30:31",
            "upload_time_iso_8601": "2025-02-11T22:30:31.315916Z",
            "url": "https://files.pythonhosted.org/packages/02/b7/1e2f32cb333d1a444950170447c842657b18233dde3d9859f84083825849/hl_gauss_pytorch-0.1.19-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "796cc25965f6b1b964624df716c91b6e51ee9a80eca81e6b2e8bcd85c61e4465",
                "md5": "e8687bc725f4412f019f0c9ff5f471b8",
                "sha256": "826dfa0aed5ffacf5f8214cb178347138442aba7af03217585a3f5110af86e79"
            },
            "downloads": -1,
            "filename": "hl_gauss_pytorch-0.1.19.tar.gz",
            "has_sig": false,
            "md5_digest": "e8687bc725f4412f019f0c9ff5f471b8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 138549,
            "upload_time": "2025-02-11T22:30:35",
            "upload_time_iso_8601": "2025-02-11T22:30:35.769201Z",
            "url": "https://files.pythonhosted.org/packages/79/6c/c25965f6b1b964624df716c91b6e51ee9a80eca81e6b2e8bcd85c61e4465/hl_gauss_pytorch-0.1.19.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-11 22:30:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lucidrains",
    "github_project": "hl-gauss-pytorch",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "hl-gauss-pytorch"
}
        
Elapsed time: 1.21631s