# nflows
<a href="https://doi.org/10.5281/zenodo.4296287"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.4296287.svg" alt="DOI"></a>
`nflows` is a comprehensive collection of [normalizing flows](https://arxiv.org/abs/1912.02762) using [PyTorch](https://pytorch.org).
## Installation
To install from PyPI:
```
pip install nflows
```
## Usage
To define a flow:
```python
from nflows import transforms, distributions, flows
# Define an invertible transformation.
transform = transforms.CompositeTransform([
transforms.MaskedAffineAutoregressiveTransform(features=2, hidden_features=4),
transforms.RandomPermutation(features=2)
])
# Define a base distribution.
base_distribution = distributions.StandardNormal(shape=[2])
# Combine into a flow.
flow = flows.Flow(transform=transform, distribution=base_distribution)
```
To evaluate log probabilities of inputs:
```python
log_prob = flow.log_prob(inputs)
```
To sample from the flow:
```python
samples = flow.sample(num_samples)
```
Additional examples of the workflow are provided in [examples folder](examples/).
## Development
You can install all the dependencies using the `environment.yml` file to create a conda environment:
```
conda env create -f environment.yml
```
Alternatively, you can install via `setup.py` (the `dev` flag installs development and testing dependencies):
```
pip install -e ".[dev]"
```
## Citing nflows
To cite the package:
```bibtex
@software{nflows,
author = {Conor Durkan and
Artur Bekasov and
Iain Murray and
George Papamakarios},
title = {{nflows}: normalizing flows in {PyTorch}},
month = nov,
year = 2020,
publisher = {Zenodo},
version = {v0.14},
doi = {10.5281/zenodo.4296287},
url = {https://doi.org/10.5281/zenodo.4296287}
}
```
The version number is intended to be the one from `nflows/version.py`. The year/month correspond to the date of the release. BibTeX entries for other versions could be found on [Zenodo](https://doi.org/10.5281/zenodo.4296286).
If you're using spline-based flows in particular, consider citing the _Neural Spline Flows_ paper: [[bibtex]](https://gpapamak.github.io/bibtex/neural_spline_flows.bib).
## References
`nflows` is derived from [bayesiains/nsf](https://github.com/bayesiains/nsf) originally published with
> C. Durkan, A. Bekasov, I. Murray, G. Papamakarios, _Neural Spline Flows_, NeurIPS 2019.
> [[arXiv]](https://arxiv.org/abs/1906.04032) [[bibtex]](https://gpapamak.github.io/bibtex/neural_spline_flows.bib)
`nflows` has been used in
> Conor Durkan, Iain Murray, George Papamakarios, _On Contrastive Learning for Likelihood-free Inference_, ICML 2020.
> [[arXiv]](https://arxiv.org/abs/2002.03712).
> Artur Bekasov, Iain Murray, _Ordering Dimensions with Nested Dropout Normalizing Flows_.
> [[arXiv]](https://arxiv.org/abs/2006.08777).
> Tim Dockhorn, James A. Ritchie, Yaoliang Yu, Iain Murray, _Density Deconvolution with Normalizing Flows_.
> [[arXiv]](https://arxiv.org/abs/2006.09396).
`nflows` is used by the conditional density estimation package [pyknos](https://github.com/mackelab/pyknos), and in turn the likelihood-free inference framework [sbi](https://github.com/mackelab/sbi).
Raw data
{
"_id": null,
"home_page": "https://github.com/bayesiains/nflows",
"name": "nflows",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Conor Durkan, Artur Bekasov, George Papamakarios, Iain Murray",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/bd/16/a484db41aab28332f42080435c9342fa87cfc9a4fce5495521ea1e80ca27/nflows-0.14.tar.gz",
"platform": "",
"description": "# nflows\n\n<a href=\"https://doi.org/10.5281/zenodo.4296287\"><img src=\"https://zenodo.org/badge/DOI/10.5281/zenodo.4296287.svg\" alt=\"DOI\"></a>\n\n`nflows` is a comprehensive collection of [normalizing flows](https://arxiv.org/abs/1912.02762) using [PyTorch](https://pytorch.org).\n\n## Installation\n\nTo install from PyPI:\n```\npip install nflows\n```\n\n## Usage\n\nTo define a flow:\n\n```python\nfrom nflows import transforms, distributions, flows\n\n# Define an invertible transformation.\ntransform = transforms.CompositeTransform([\n transforms.MaskedAffineAutoregressiveTransform(features=2, hidden_features=4),\n transforms.RandomPermutation(features=2)\n])\n\n# Define a base distribution.\nbase_distribution = distributions.StandardNormal(shape=[2])\n\n\n# Combine into a flow.\nflow = flows.Flow(transform=transform, distribution=base_distribution)\n```\n\nTo evaluate log probabilities of inputs:\n```python\nlog_prob = flow.log_prob(inputs)\n```\n\nTo sample from the flow:\n```python\nsamples = flow.sample(num_samples)\n```\n\nAdditional examples of the workflow are provided in [examples folder](examples/).\n\n## Development\n\nYou can install all the dependencies using the `environment.yml` file to create a conda environment: \n```\nconda env create -f environment.yml\n```\n\nAlternatively, you can install via `setup.py` (the `dev` flag installs development and testing dependencies):\n```\npip install -e \".[dev]\"\n```\n\n## Citing nflows\n\nTo cite the package:\n```bibtex\n@software{nflows,\n author = {Conor Durkan and\n Artur Bekasov and\n Iain Murray and\n George Papamakarios},\n title = {{nflows}: normalizing flows in {PyTorch}},\n month = nov,\n year = 2020,\n publisher = {Zenodo},\n version = {v0.14},\n doi = {10.5281/zenodo.4296287},\n url = {https://doi.org/10.5281/zenodo.4296287}\n}\n```\n\nThe version number is intended to be the one from `nflows/version.py`. The year/month correspond to the date of the release. BibTeX entries for other versions could be found on [Zenodo](https://doi.org/10.5281/zenodo.4296286).\n\nIf you're using spline-based flows in particular, consider citing the _Neural Spline Flows_ paper: [[bibtex]](https://gpapamak.github.io/bibtex/neural_spline_flows.bib).\n\n## References\n`nflows` is derived from [bayesiains/nsf](https://github.com/bayesiains/nsf) originally published with\n> C. Durkan, A. Bekasov, I. Murray, G. Papamakarios, _Neural Spline Flows_, NeurIPS 2019.\n> [[arXiv]](https://arxiv.org/abs/1906.04032) [[bibtex]](https://gpapamak.github.io/bibtex/neural_spline_flows.bib)\n\n\n`nflows` has been used in \n> Conor Durkan, Iain Murray, George Papamakarios, _On Contrastive Learning for Likelihood-free Inference_, ICML 2020.\n> [[arXiv]](https://arxiv.org/abs/2002.03712).\n\n> Artur Bekasov, Iain Murray, _Ordering Dimensions with Nested Dropout Normalizing Flows_.\n> [[arXiv]](https://arxiv.org/abs/2006.08777).\n\n> Tim Dockhorn, James A. Ritchie, Yaoliang Yu, Iain Murray, _Density Deconvolution with Normalizing Flows_.\n> [[arXiv]](https://arxiv.org/abs/2006.09396).\n\n`nflows` is used by the conditional density estimation package [pyknos](https://github.com/mackelab/pyknos), and in turn the likelihood-free inference framework [sbi](https://github.com/mackelab/sbi).",
"bugtrack_url": null,
"license": "MIT",
"summary": "Normalizing flows in PyTorch.",
"version": "0.14",
"project_urls": {
"Download": "https://github.com/bayesiains/nflows/archive/v0.14.tar.gz",
"Homepage": "https://github.com/bayesiains/nflows"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "bd16a484db41aab28332f42080435c9342fa87cfc9a4fce5495521ea1e80ca27",
"md5": "f06b37d8dbe9735f1d90a3b565e12dc3",
"sha256": "6299844a62f9999fcdf2d95cb2d01c091a50136bd17826e303aba646b2d11b55"
},
"downloads": -1,
"filename": "nflows-0.14.tar.gz",
"has_sig": false,
"md5_digest": "f06b37d8dbe9735f1d90a3b565e12dc3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 45784,
"upload_time": "2020-12-02T11:55:56",
"upload_time_iso_8601": "2020-12-02T11:55:56.545223Z",
"url": "https://files.pythonhosted.org/packages/bd/16/a484db41aab28332f42080435c9342fa87cfc9a4fce5495521ea1e80ca27/nflows-0.14.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2020-12-02 11:55:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "bayesiains",
"github_project": "nflows",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "matplotlib",
"specs": []
},
{
"name": "numpy",
"specs": []
},
{
"name": "tensorboard",
"specs": []
},
{
"name": "torch",
"specs": []
},
{
"name": "tqdm",
"specs": []
},
{
"name": "autoflake",
"specs": []
},
{
"name": "black",
"specs": []
},
{
"name": "flake8",
"specs": []
},
{
"name": "isort",
"specs": []
},
{
"name": "pytest",
"specs": []
},
{
"name": "pyyaml",
"specs": []
},
{
"name": "torchtestcase",
"specs": []
},
{
"name": "umnn",
"specs": []
}
],
"lcname": "nflows"
}