Normalizing flows in PyTorch (fork for cel package).
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)
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cel_nflows-0.14.1.tar.gz.
File metadata
- Download URL: cel_nflows-0.14.1.tar.gz
- Upload date:
- Size: 41.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f203b45ccae9203ec58887d3fba5df1142ffa91668c50961e1dc60e0e2b57ff2
|
|
| MD5 |
deb190fef314111fc1fbb83d40c661ac
|
|
| BLAKE2b-256 |
cb33d55db219fbe017cc5462a1fde6d6f8d5ebd9433652a6785fe57c56e5f66e
|
File details
Details for the file cel_nflows-0.14.1-py3-none-any.whl.
File metadata
- Download URL: cel_nflows-0.14.1-py3-none-any.whl
- Upload date:
- Size: 57.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc92408a60c7c2bb141f5ece6ef6292470e3f525d41e22916c9ada775e90af90
|
|
| MD5 |
dce9e91d8079e1154e3420065d459c3e
|
|
| BLAKE2b-256 |
e2298bbf690e2d8fe4c870ba9ff0e38fcf9f054c15051d598c248a8ce127c190
|