blackjax-nightly


Nameblackjax-nightly JSON
Version 1.1.1.post7 PyPI version JSON
download
home_pageNone
SummaryFlexible and fast sampling in Python
upload_time2024-04-08 11:36:09
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseApache License 2.0
keywords probability machine learning statistics mcmc sampling
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # BlackJAX
![Continuous integration](https://github.com/blackjax-devs/blackjax/actions/workflows/test.yml/badge.svg)
![codecov](https://codecov.io/gh/blackjax-devs/blackjax/branch/main/graph/badge.svg)
![PyPI version](https://img.shields.io/pypi/v/blackjax)


![BlackJAX animation: sampling BlackJAX with BlackJAX](./docs/examples/scatter.gif)

## What is BlackJAX?

BlackJAX is a library of samplers for [JAX](https://github.com/google/jax) that
works on CPU as well as GPU.

It is *not* a probabilistic programming library. However it integrates really
well with PPLs as long as they can provide a (potentially unnormalized)
log-probability density function compatible with JAX.

## Who should use BlackJAX?

BlackJAX should appeal to those who:
- Have a logpdf and just need a sampler;
- Need more than a general-purpose sampler;
- Want to sample on GPU;
- Want to build upon robust elementary blocks for their research;
- Are building a probabilistic programming language;
- Want to learn how sampling algorithms work.

## Quickstart

### Installation

You can install BlackJAX using `pip`:

```bash
pip install blackjax
```

or via conda-forge:

```bash
conda install -c conda-forge blackjax
```

Nightly builds (bleeding edge) of Blackjax can also be installed using `pip`:

```bash
pip install blackjax-nightly
```

BlackJAX is written in pure Python but depends on XLA via JAX. By default, the
version of JAX that will be installed along with BlackJAX will make your code
run on CPU only. **If you want to use BlackJAX on GPU/TPU** we recommend you follow
[these instructions](https://github.com/google/jax#installation) to install JAX
with the relevant hardware acceleration support.

### Example

Let us look at a simple self-contained example sampling with NUTS:

```python
import jax
import jax.numpy as jnp
import jax.scipy.stats as stats
import numpy as np

import blackjax

observed = np.random.normal(10, 20, size=1_000)
def logdensity_fn(x):
    logpdf = stats.norm.logpdf(observed, x["loc"], x["scale"])
    return jnp.sum(logpdf)

# Build the kernel
step_size = 1e-3
inverse_mass_matrix = jnp.array([1., 1.])
nuts = blackjax.nuts(logdensity_fn, step_size, inverse_mass_matrix)

# Initialize the state
initial_position = {"loc": 1., "scale": 2.}
state = nuts.init(initial_position)

# Iterate
rng_key = jax.random.key(0)
for step in range(100):
    nuts_key = jax.random.fold_in(rng_key, step)
    state, _ = nuts.step(nuts_key, state)
```

See [the documentation](https://blackjax-devs.github.io/blackjax/index.html) for more examples of how to use the library: how to write inference loops for one or several chains, how to use the Stan warmup, etc.

## Philosophy

### What is BlackJAX?

BlackJAX bridges the gap between "one liner" frameworks and modular, customizable
libraries.

Users can import the library and interact with robust, well-tested and performant
samplers with a few lines of code. These samplers are aimed at PPL developers,
or people who have a logpdf and just need a sampler that works.

But the true strength of BlackJAX lies in its internals and how they can be used
to experiment quickly on existing or new sampling schemes. This lower level
exposes the building blocks of inference algorithms: integrators, proposal,
momentum generators, etc and makes it easy to combine them to build new
algorithms. It provides an opportunity to accelerate research on sampling
algorithms by providing robust, performant and reusable code.

### Why BlackJAX?

Sampling algorithms are too often integrated into PPLs and not decoupled from
the rest of the framework, making them hard to use for people who do not need
the modeling language to build their logpdf. Their implementation is most of
the time monolithic and it is impossible to reuse parts of the algorithm to
build custom kernels. BlackJAX solves both problems.

### How does it work?

BlackJAX allows to build arbitrarily complex algorithms because it is built
around a very general pattern. Everything that takes a state and returns a state
is a transition kernel, and is implemented as:

```python
new_state, info =  kernel(rng_key, state)
```

kernels are stateless functions and all follow the same API; state and
information related to the transition are returned separately. They can thus be
easily composed and exchanged. We specialize these kernels by closure instead of
passing parameters.

## Contributions

Please follow our [short guide](https://github.com/blackjax-devs/blackjax/blob/main/CONTRIBUTING.md).

## Citing Blackjax

To cite this repository:

```
@misc{cabezas2024blackjax,
      title={BlackJAX: Composable {B}ayesian inference in {JAX}},
      author={Alberto Cabezas and Adrien Corenflos and Junpeng Lao and RĂ©mi Louf},
      year={2024},
      eprint={2402.10797},
      archivePrefix={arXiv},
      primaryClass={cs.MS}
}
```
In the above bibtex entry, names are in alphabetical order, the version number should be the last tag on the `main` branch.

## Acknowledgements

Some details of the NUTS implementation were largely inspired by
[Numpyro](https://github.com/pyro-ppl/numpyro)'s.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "blackjax-nightly",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "probability, machine learning, statistics, mcmc, sampling",
    "author": null,
    "author_email": "The Blackjax team <remi@thetypicalset.com>",
    "download_url": "https://files.pythonhosted.org/packages/59/98/66c27f02c67297a96b56cb4201e2e4c7d93ffbc6123c566d7e1b695c6ee7/blackjax-nightly-1.1.1.post7.tar.gz",
    "platform": "Linux",
    "description": "# BlackJAX\n![Continuous integration](https://github.com/blackjax-devs/blackjax/actions/workflows/test.yml/badge.svg)\n![codecov](https://codecov.io/gh/blackjax-devs/blackjax/branch/main/graph/badge.svg)\n![PyPI version](https://img.shields.io/pypi/v/blackjax)\n\n\n![BlackJAX animation: sampling BlackJAX with BlackJAX](./docs/examples/scatter.gif)\n\n## What is BlackJAX?\n\nBlackJAX is a library of samplers for [JAX](https://github.com/google/jax) that\nworks on CPU as well as GPU.\n\nIt is *not* a probabilistic programming library. However it integrates really\nwell with PPLs as long as they can provide a (potentially unnormalized)\nlog-probability density function compatible with JAX.\n\n## Who should use BlackJAX?\n\nBlackJAX should appeal to those who:\n- Have a logpdf and just need a sampler;\n- Need more than a general-purpose sampler;\n- Want to sample on GPU;\n- Want to build upon robust elementary blocks for their research;\n- Are building a probabilistic programming language;\n- Want to learn how sampling algorithms work.\n\n## Quickstart\n\n### Installation\n\nYou can install BlackJAX using `pip`:\n\n```bash\npip install blackjax\n```\n\nor via conda-forge:\n\n```bash\nconda install -c conda-forge blackjax\n```\n\nNightly builds (bleeding edge) of Blackjax can also be installed using `pip`:\n\n```bash\npip install blackjax-nightly\n```\n\nBlackJAX is written in pure Python but depends on XLA via JAX. By default, the\nversion of JAX that will be installed along with BlackJAX will make your code\nrun on CPU only. **If you want to use BlackJAX on GPU/TPU** we recommend you follow\n[these instructions](https://github.com/google/jax#installation) to install JAX\nwith the relevant hardware acceleration support.\n\n### Example\n\nLet us look at a simple self-contained example sampling with NUTS:\n\n```python\nimport jax\nimport jax.numpy as jnp\nimport jax.scipy.stats as stats\nimport numpy as np\n\nimport blackjax\n\nobserved = np.random.normal(10, 20, size=1_000)\ndef logdensity_fn(x):\n    logpdf = stats.norm.logpdf(observed, x[\"loc\"], x[\"scale\"])\n    return jnp.sum(logpdf)\n\n# Build the kernel\nstep_size = 1e-3\ninverse_mass_matrix = jnp.array([1., 1.])\nnuts = blackjax.nuts(logdensity_fn, step_size, inverse_mass_matrix)\n\n# Initialize the state\ninitial_position = {\"loc\": 1., \"scale\": 2.}\nstate = nuts.init(initial_position)\n\n# Iterate\nrng_key = jax.random.key(0)\nfor step in range(100):\n    nuts_key = jax.random.fold_in(rng_key, step)\n    state, _ = nuts.step(nuts_key, state)\n```\n\nSee [the documentation](https://blackjax-devs.github.io/blackjax/index.html) for more examples of how to use the library: how to write inference loops for one or several chains, how to use the Stan warmup, etc.\n\n## Philosophy\n\n### What is BlackJAX?\n\nBlackJAX bridges the gap between \"one liner\" frameworks and modular, customizable\nlibraries.\n\nUsers can import the library and interact with robust, well-tested and performant\nsamplers with a few lines of code. These samplers are aimed at PPL developers,\nor people who have a logpdf and just need a sampler that works.\n\nBut the true strength of BlackJAX lies in its internals and how they can be used\nto experiment quickly on existing or new sampling schemes. This lower level\nexposes the building blocks of inference algorithms: integrators, proposal,\nmomentum generators, etc and makes it easy to combine them to build new\nalgorithms. It provides an opportunity to accelerate research on sampling\nalgorithms by providing robust, performant and reusable code.\n\n### Why BlackJAX?\n\nSampling algorithms are too often integrated into PPLs and not decoupled from\nthe rest of the framework, making them hard to use for people who do not need\nthe modeling language to build their logpdf. Their implementation is most of\nthe time monolithic and it is impossible to reuse parts of the algorithm to\nbuild custom kernels. BlackJAX solves both problems.\n\n### How does it work?\n\nBlackJAX allows to build arbitrarily complex algorithms because it is built\naround a very general pattern. Everything that takes a state and returns a state\nis a transition kernel, and is implemented as:\n\n```python\nnew_state, info =  kernel(rng_key, state)\n```\n\nkernels are stateless functions and all follow the same API; state and\ninformation related to the transition are returned separately. They can thus be\neasily composed and exchanged. We specialize these kernels by closure instead of\npassing parameters.\n\n## Contributions\n\nPlease follow our [short guide](https://github.com/blackjax-devs/blackjax/blob/main/CONTRIBUTING.md).\n\n## Citing Blackjax\n\nTo cite this repository:\n\n```\n@misc{cabezas2024blackjax,\n      title={BlackJAX: Composable {B}ayesian inference in {JAX}},\n      author={Alberto Cabezas and Adrien Corenflos and Junpeng Lao and R\u00e9mi Louf},\n      year={2024},\n      eprint={2402.10797},\n      archivePrefix={arXiv},\n      primaryClass={cs.MS}\n}\n```\nIn the above bibtex entry, names are in alphabetical order, the version number should be the last tag on the `main` branch.\n\n## Acknowledgements\n\nSome details of the NUTS implementation were largely inspired by\n[Numpyro](https://github.com/pyro-ppl/numpyro)'s.\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "Flexible and fast sampling in Python",
    "version": "1.1.1.post7",
    "project_urls": {
        "documentation": "https://blackjax-devs.github.io/blackjax/",
        "homepage": "https://github.com/blackjax-devs/blackjax",
        "repository": "https://github.com/blackjax-devs/blackjax"
    },
    "split_keywords": [
        "probability",
        " machine learning",
        " statistics",
        " mcmc",
        " sampling"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6d42c307b47a28ede6da82abf7d6fbd20b2a26a318f9809022ab7d30dad61886",
                "md5": "20e44b4632391487497a9f08f103865d",
                "sha256": "e3f0ee4fd3cd1f1622b55286930e24e29c42d137cfdde41ea97aa4166597827b"
            },
            "downloads": -1,
            "filename": "blackjax_nightly-1.1.1.post7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "20e44b4632391487497a9f08f103865d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 4628972,
            "upload_time": "2024-04-08T11:36:06",
            "upload_time_iso_8601": "2024-04-08T11:36:06.089307Z",
            "url": "https://files.pythonhosted.org/packages/6d/42/c307b47a28ede6da82abf7d6fbd20b2a26a318f9809022ab7d30dad61886/blackjax_nightly-1.1.1.post7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "599866c27f02c67297a96b56cb4201e2e4c7d93ffbc6123c566d7e1b695c6ee7",
                "md5": "6596a66c6c39836c7d0e27baa0f98a0a",
                "sha256": "59094d6a856b72631a89fcf493c2f2d2dee1f3e0a6f182c81b2ef8c31bb54724"
            },
            "downloads": -1,
            "filename": "blackjax-nightly-1.1.1.post7.tar.gz",
            "has_sig": false,
            "md5_digest": "6596a66c6c39836c7d0e27baa0f98a0a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 4616964,
            "upload_time": "2024-04-08T11:36:09",
            "upload_time_iso_8601": "2024-04-08T11:36:09.233955Z",
            "url": "https://files.pythonhosted.org/packages/59/98/66c27f02c67297a96b56cb4201e2e4c7d93ffbc6123c566d7e1b695c6ee7/blackjax-nightly-1.1.1.post7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-08 11:36:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "blackjax-devs",
    "github_project": "blackjax",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "blackjax-nightly"
}
        
Elapsed time: 0.25605s