Skip to main content

Normalizing flows in PyTorch. An extension of nflows.

Project description

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:

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

enflows-0.0.1.tar.gz (112.5 kB view details)

Uploaded Source

Built Distribution

enflows-0.0.1-py3-none-any.whl (125.7 kB view details)

Uploaded Python 3

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

Hashes for enflows-0.0.1.tar.gz
Algorithm Hash digest
SHA256 74565072229ae8d6e35241d562ceb460646e48ae89c69897a283b4f9f76835f5
MD5 365121b610ef555260f2f07dba2ecd56
BLAKE2b-256 77d476f602f07c111b51f4cfea188e34a5bfea97dbec69c42a55dc5a9f024985

See more details on using hashes here.

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

Hashes for enflows-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2795a7fb89340d0797e347068a28d934506227e8a30367d42635f14cc1acdeb8
MD5 bd8c2d81c096c719e8bf07ad84680cf8
BLAKE2b-256 a6bdcd79548763539b3f2f4e1ce80386b7367d6cf17a6244c29e64953ca98d97

See more details on using hashes here.

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