Skip to main content

Normalizing flows in PyTorch.

Project description

nflows

DOI

nflows is a comprehensive collection of normalizing flows using PyTorch.

Installation

To install from PyPI:

pip install nflows

Usage

To define a flow:

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:

log_prob = flow.log_prob(inputs)

To sample from the flow:

samples = flow.sample(num_samples)

Additional examples of the workflow are provided in examples folder.

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:

@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.

If you're using spline-based flows in particular, consider citing the Neural Spline Flows paper: [bibtex].

References

nflows is derived from bayesiains/nsf originally published with

C. Durkan, A. Bekasov, I. Murray, G. Papamakarios, Neural Spline Flows, NeurIPS 2019. [arXiv] [bibtex]

nflows has been used in

Conor Durkan, Iain Murray, George Papamakarios, On Contrastive Learning for Likelihood-free Inference, ICML 2020. [arXiv].

Artur Bekasov, Iain Murray, Ordering Dimensions with Nested Dropout Normalizing Flows. [arXiv].

Tim Dockhorn, James A. Ritchie, Yaoliang Yu, Iain Murray, Density Deconvolution with Normalizing Flows. [arXiv].

nflows is used by the conditional density estimation package pyknos, and in turn the likelihood-free inference framework sbi.

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

nflows-0.14.tar.gz (45.8 kB view details)

Uploaded Source

File details

Details for the file nflows-0.14.tar.gz.

File metadata

  • Download URL: nflows-0.14.tar.gz
  • Upload date:
  • Size: 45.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.6.1 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.19.4 CPython/3.5.2

File hashes

Hashes for nflows-0.14.tar.gz
Algorithm Hash digest
SHA256 6299844a62f9999fcdf2d95cb2d01c091a50136bd17826e303aba646b2d11b55
MD5 f06b37d8dbe9735f1d90a3b565e12dc3
BLAKE2b-256 bd16a484db41aab28332f42080435c9342fa87cfc9a4fce5495521ea1e80ca27

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