Skip to main content

nflows-extended: An extension of nflows

Build status

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:

Metadata

Release files for enflows 0.0.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 enflows 0.0.1
File Size Uploaded
enflows-0.0.1.tar.gz 112.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for enflows 0.0.1
File Interpreter ABI Platform
enflows-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 238.2 kB

Release files / enflows-0.0.1.tar.gz

Download URL enflows-0.0.1.tar.gz
Size 112.5 kB
Tags Source
SHA-256 checksum
How to use checksums
74565072229ae8d6e35241d562ceb460646e48ae89c69897a283b4f9f76835f5
BLAKE2b-256 checksum
How to use checksums
77d476f602f07c111b51f4cfea188e34a5bfea97dbec69c42a55dc5a9f024985
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / enflows-0.0.1-py3-none-any.whl

Download URL enflows-0.0.1-py3-none-any.whl
Size 125.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2795a7fb89340d0797e347068a28d934506227e8a30367d42635f14cc1acdeb8
BLAKE2b-256 checksum
How to use checksums
a6bdcd79548763539b3f2f4e1ce80386b7367d6cf17a6244c29e64953ca98d97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

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