Skip to main content

Normalizing flows in PyTorch.

Project description

nflows

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]"

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.13.tar.gz (44.8 kB view hashes)

Uploaded Source

Supported by

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