Skip to main content

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)

or use already implemented flow architectures:

from nflows.flows import MaskedAutoregressiveFlow, SimpleRealNVP

features=2
hidden_features=4

maf = MaskedAutoregressiveFlow(features=features, hidden_features=hidden_features)
rnvp = SimpleRealNVP(features=features, hidden_features=hidden_features)
nice = SimpleRealNVP(feautres=features, hidden_features=hidden_features, use_volumne_perserving=True)

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.

Metadata

Release files for cel-nflows 0.14.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cel-nflows 0.14.1
File Size Uploaded Provenance Actions
cel_nflows-0.14.1.tar.gz 41.4 kB Without provenance Details for cel_nflows-0.14.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cel-nflows 0.14.1
File Interpreter ABI Platform Actions
cel_nflows-0.14.1-py3-none-any.whl Python 3 none any Details for cel_nflows-0.14.1-py3-none-any.whl

Total release size: 99.2 kB

Release files / cel_nflows-0.14.1.tar.gz

Download URL cel_nflows-0.14.1.tar.gz
Size 41.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f203b45ccae9203ec58887d3fba5df1142ffa91668c50961e1dc60e0e2b57ff2
BLAKE2b-256 checksum
How to use checksums
cb33d55db219fbe017cc5462a1fde6d6f8d5ebd9433652a6785fe57c56e5f66e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / cel_nflows-0.14.1-py3-none-any.whl

Download URL cel_nflows-0.14.1-py3-none-any.whl
Size 57.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc92408a60c7c2bb141f5ece6ef6292470e3f525d41e22916c9ada775e90af90
BLAKE2b-256 checksum
How to use checksums
e2298bbf690e2d8fe4c870ba9ff0e38fcf9f054c15051d598c248a8ce127c190
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Security for cel-nflows 0.14.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.14.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page