flowjax


Nameflowjax JSON
Version 12.1.2 PyPI version JSON
download
home_pageNone
SummaryEasy to use distributions, bijections and normalizing flows in JAX.
upload_time2024-04-22 12:30:57
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseThe MIT License (MIT) Copyright (c) 2022 Daniel Ward Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords jax neural-networks equinox
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">
<img src="./logo.png?raw=true" alt="logo" width="500" ></img>
</div>

# FlowJax: Distributions and Normalizing Flows in Jax

## Documentation
Available [here](https://danielward27.github.io/flowjax/index.html).

## Short example
Training a flow can be done in a few lines of code:

```python
from flowjax.flows import block_neural_autoregressive_flow
from flowjax.train import fit_to_data
from flowjax.distributions import Normal
from jax import random
import jax.numpy as jnp

data_key, flow_key, train_key, sample_key = random.split(random.PRNGKey(0), 4)

x = random.uniform(data_key, (5000, 2))  # Toy data
base_dist = Normal(jnp.zeros(x.shape[1]))
flow = block_neural_autoregressive_flow(flow_key, base_dist=base_dist)
flow, losses = fit_to_data(
    key=train_key,
    dist=flow,
    x=x,
    learning_rate=5e-3,
    max_epochs=200,
    )

# We can now evaluate the log-probability of arbitrary points
log_probs = flow.log_prob(x)

# And sample the distribution
samples = flow.sample(sample_key, (1000, ))
```

The package currently includes:
- Many simple bijections and distributions, implemented as [Equinox](https://arxiv.org/abs/2111.00254) modules.
- `coupling_flow` ([Dinh et al., 2017](https://arxiv.org/abs/1605.08803)) and `masked_autoregressive_flow` ([Kingma et al., 2016](https://arxiv.org/abs/1606.04934), [Papamakarios et al., 2017](https://arxiv.org/abs/1705.07057v4)) normalizing flow architectures.
    - These can be used with arbitrary bijections as transformers, such as `Affine` or `RationalQuadraticSpline` (the latter used in neural spline flows; [Durkan et al., 2019](https://arxiv.org/abs/1906.04032)). 
- `block_neural_autoregressive_flow`, as introduced by [De Cao et al., 2019](https://arxiv.org/abs/1904.04676).
- `planar_flow`, as introduced by [Rezende and Mohamed, 2015](https://arxiv.org/pdf/1505.05770.pdf).
- `triangular_spline_flow`, introduced here.
- Training scripts for fitting by maximum likelihood, variational inference, or using contrastive learning for sequential neural posterior estimation ([Greenberg et al., 2019](https://arxiv.org/abs/1905.07488); [Durkan et al., 2020](https://arxiv.org/abs/2002.03712])).
- A bisection search algorithm that allows inverting some bijections without a
known inverse, allowing for example both sampling and density evaluation to be
performed with block neural autoregressive flows.

## Installation
```bash
pip install flowjax
```

## Warning
This package is in its early stages of development and may undergo significant changes, including breaking changes, between major releases. Whilst ideally we should be on version 0.y.z to indicate its state, we have already progressed beyond that stage.

## Development
We can install a version for development as follows
```bash
git clone https://github.com/danielward27/flowjax.git
cd flowjax
pip install -e .[dev]
sudo apt-get install pandoc  # Required for building documentation
```

## Related
We make use of the [Equinox](https://arxiv.org/abs/2111.00254) package, which
facilitates defining models using a PyTorch-like syntax with Jax. 

## Citation
If you found this package useful in academic work, please consider citing it using the
template below, filling in ``[version number]`` and ``[release year of version]`` to the
appropriate values. Version specific DOIs
can be obtained from [zenodo](https://zenodo.org/records/10402073) if desired.

```bibtex
@software{ward2023flowjax,
  title = {FlowJax: Distributions and Normalizing Flows in Jax},
  author = {Daniel Ward},
  url = {https://github.com/danielward27/flowjax},
  version = {[version number]},
  year = {[release year of version]},
  doi = {10.5281/zenodo.10402073},
}
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "flowjax",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "jax, neural-networks, equinox",
    "author": null,
    "author_email": "Daniel Ward <danielward27@outlook.com>",
    "download_url": "https://files.pythonhosted.org/packages/17/d9/9171bd8007c7f1c3ddb40fde5e8b7ea5341cca318e29e2c1d53643f4830a/flowjax-12.1.2.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n<img src=\"./logo.png?raw=true\" alt=\"logo\" width=\"500\" ></img>\n</div>\n\n# FlowJax: Distributions and Normalizing Flows in Jax\n\n## Documentation\nAvailable [here](https://danielward27.github.io/flowjax/index.html).\n\n## Short example\nTraining a flow can be done in a few lines of code:\n\n```python\nfrom flowjax.flows import block_neural_autoregressive_flow\nfrom flowjax.train import fit_to_data\nfrom flowjax.distributions import Normal\nfrom jax import random\nimport jax.numpy as jnp\n\ndata_key, flow_key, train_key, sample_key = random.split(random.PRNGKey(0), 4)\n\nx = random.uniform(data_key, (5000, 2))  # Toy data\nbase_dist = Normal(jnp.zeros(x.shape[1]))\nflow = block_neural_autoregressive_flow(flow_key, base_dist=base_dist)\nflow, losses = fit_to_data(\n    key=train_key,\n    dist=flow,\n    x=x,\n    learning_rate=5e-3,\n    max_epochs=200,\n    )\n\n# We can now evaluate the log-probability of arbitrary points\nlog_probs = flow.log_prob(x)\n\n# And sample the distribution\nsamples = flow.sample(sample_key, (1000, ))\n```\n\nThe package currently includes:\n- Many simple bijections and distributions, implemented as [Equinox](https://arxiv.org/abs/2111.00254) modules.\n- `coupling_flow` ([Dinh et al., 2017](https://arxiv.org/abs/1605.08803)) and `masked_autoregressive_flow` ([Kingma et al., 2016](https://arxiv.org/abs/1606.04934), [Papamakarios et al., 2017](https://arxiv.org/abs/1705.07057v4)) normalizing flow architectures.\n    - These can be used with arbitrary bijections as transformers, such as `Affine` or `RationalQuadraticSpline` (the latter used in neural spline flows; [Durkan et al., 2019](https://arxiv.org/abs/1906.04032)). \n- `block_neural_autoregressive_flow`, as introduced by [De Cao et al., 2019](https://arxiv.org/abs/1904.04676).\n- `planar_flow`, as introduced by [Rezende and Mohamed, 2015](https://arxiv.org/pdf/1505.05770.pdf).\n- `triangular_spline_flow`, introduced here.\n- Training scripts for fitting by maximum likelihood, variational inference, or using contrastive learning for sequential neural posterior estimation ([Greenberg et al., 2019](https://arxiv.org/abs/1905.07488); [Durkan et al., 2020](https://arxiv.org/abs/2002.03712])).\n- A bisection search algorithm that allows inverting some bijections without a\nknown inverse, allowing for example both sampling and density evaluation to be\nperformed with block neural autoregressive flows.\n\n## Installation\n```bash\npip install flowjax\n```\n\n## Warning\nThis package is in its early stages of development and may undergo significant changes, including breaking changes, between major releases. Whilst ideally we should be on version 0.y.z to indicate its state, we have already progressed beyond that stage.\n\n## Development\nWe can install a version for development as follows\n```bash\ngit clone https://github.com/danielward27/flowjax.git\ncd flowjax\npip install -e .[dev]\nsudo apt-get install pandoc  # Required for building documentation\n```\n\n## Related\nWe make use of the [Equinox](https://arxiv.org/abs/2111.00254) package, which\nfacilitates defining models using a PyTorch-like syntax with Jax. \n\n## Citation\nIf you found this package useful in academic work, please consider citing it using the\ntemplate below, filling in ``[version number]`` and ``[release year of version]`` to the\nappropriate values. Version specific DOIs\ncan be obtained from [zenodo](https://zenodo.org/records/10402073) if desired.\n\n```bibtex\n@software{ward2023flowjax,\n  title = {FlowJax: Distributions and Normalizing Flows in Jax},\n  author = {Daniel Ward},\n  url = {https://github.com/danielward27/flowjax},\n  version = {[version number]},\n  year = {[release year of version]},\n  doi = {10.5281/zenodo.10402073},\n}\n```\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)  Copyright (c) 2022 Daniel Ward  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Easy to use distributions, bijections and normalizing flows in JAX.",
    "version": "12.1.2",
    "project_urls": {
        "documentation": "https://danielward27.github.io/flowjax/index.html",
        "repository": "https://github.com/danielward27/flowjax"
    },
    "split_keywords": [
        "jax",
        " neural-networks",
        " equinox"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f052daf6a757fb04638959222dca1b2554e950d3a6004efbb28282b291e9a029",
                "md5": "00923f04c6f77c84061baf0792980ca0",
                "sha256": "3ace861bf335a5cb0f69ff4a787defb3d3261d28b889d31190cb3e62a86e2553"
            },
            "downloads": -1,
            "filename": "flowjax-12.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "00923f04c6f77c84061baf0792980ca0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 57557,
            "upload_time": "2024-04-22T12:30:54",
            "upload_time_iso_8601": "2024-04-22T12:30:54.927324Z",
            "url": "https://files.pythonhosted.org/packages/f0/52/daf6a757fb04638959222dca1b2554e950d3a6004efbb28282b291e9a029/flowjax-12.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "17d99171bd8007c7f1c3ddb40fde5e8b7ea5341cca318e29e2c1d53643f4830a",
                "md5": "9f3771e5629d0a2e89a04451e948a6e5",
                "sha256": "70544d59054194f46e51f6798b079583cd049d66579224d102683fa8c753bede"
            },
            "downloads": -1,
            "filename": "flowjax-12.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "9f3771e5629d0a2e89a04451e948a6e5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 777157,
            "upload_time": "2024-04-22T12:30:57",
            "upload_time_iso_8601": "2024-04-22T12:30:57.029480Z",
            "url": "https://files.pythonhosted.org/packages/17/d9/9171bd8007c7f1c3ddb40fde5e8b7ea5341cca318e29e2c1d53643f4830a/flowjax-12.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-22 12:30:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "danielward27",
    "github_project": "flowjax",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "flowjax"
}
        
Elapsed time: 0.23825s