Normalizing flows in PyTorch. An extension of nflows.
Project description
nflows-extended: An extension of nflows
The original nflows
package is a comprehensive collection of normalizing flows using PyTorch.
Our nflows-extended
, or enflows
, is as the name suggests an extension.
The main focus lies in implementing more flow layers from the literature in one consistent framework.
In particular, we support conditional transformations based on hypernetworks.
In the original package, conditional networks were restricted to using a conditional base distribution. In enflows
, nearly every layer can be conditional :).
The bijective layers we additionally provide includes but are not limited to Planar Flows, invertible ResNets/DenseNets, a variant of neural autoregressive flows, and a basic support of continuous normalizing flows (and FFJORD) based torchdiffeq
package.
Setting up the Environment.
The .yml
file for the environment is given in env/conda_env.yml
, and can be created from the base directory via:
(base) $ conda env create --file env/conda_env.yml
(base) $ conda activate environment.yml
# This code should then work:
(enflows) $ python examples/conditional_toy_2d.py
Ideally, after a successfull install you should be able to run and pass the unit tests with:
(enflows) /lagrangian_flow_net$ pytest
Usage
As the core is based on nflows
, its usage is similar. To define a flow:
from enflows 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.
Changes and added features compared to nflows
The core logic of the code for LFlows (i.e. the nflows/
directory) is based on the nflows package.
Added Layers / Flwos:
- (Conditional)Sum-of-Sigmoid Layers
- Cholesky Outer Product for flows on symmetric positive definite matrices
- Lipschitz Constrained invertible DenseNets In particular, we provide three ways to condition these of these transformations without affecting the invertibility.
- Transformations for which the inverse is only known to exist, but not available:
- Conditional Versions of existing non-conditional transformations from nflows. Can be found for imports at
nflows.transforms.conditional.*
:- LU Transform
- Orthogonal Transforms based on parameterized Householder projections
- SVD based on the Orthogonal transforms
- Shift Transform
- Conditional Versions of existing auto-regressive Variations, i.e. getting rid of the autoregressive parts.
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
File details
Details for the file enflows-0.0.1.tar.gz
.
File metadata
- Download URL: enflows-0.0.1.tar.gz
- Upload date:
- Size: 112.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74565072229ae8d6e35241d562ceb460646e48ae89c69897a283b4f9f76835f5 |
|
MD5 | 365121b610ef555260f2f07dba2ecd56 |
|
BLAKE2b-256 | 77d476f602f07c111b51f4cfea188e34a5bfea97dbec69c42a55dc5a9f024985 |
File details
Details for the file enflows-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: enflows-0.0.1-py3-none-any.whl
- Upload date:
- Size: 125.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2795a7fb89340d0797e347068a28d934506227e8a30367d42635f14cc1acdeb8 |
|
MD5 | bd8c2d81c096c719e8bf07ad84680cf8 |
|
BLAKE2b-256 | a6bdcd79548763539b3f2f4e1ce80386b7367d6cf17a6244c29e64953ca98d97 |