BayesFlow
BayesFlow: Amortized Bayesian Workflows With Neural Networks - Published in JOSS (2023)
Science Score: 77.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 3 DOI reference(s) in README -
✓Academic publication links
Links to: arxiv.org, ieee.org, joss.theoj.org -
✓Committers with academic emails
3 of 27 committers (11.1%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (17.4%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
A Python library for amortized Bayesian workflows using generative neural networks.
Basic Info
- Host: GitHub
- Owner: bayesflow-org
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://bayesflow.org/
- Size: 579 MB
Statistics
- Stars: 600
- Watchers: 16
- Forks: 75
- Open Issues: 29
- Releases: 16
Topics
Metadata Files
README.md
BayesFlow 
BayesFlow is a Python library for simulation-based Amortized Bayesian Inference with neural networks. It provides users and researchers with:
- A user-friendly API for rapid Bayesian workflows
- A rich collection of neural network architectures
- Multi-backend support via Keras3: You can use PyTorch, TensorFlow, or JAX
BayesFlow (version 2+) is designed to be a flexible and efficient tool that enables rapid statistical inference fueled by continuous progress in generative AI and Bayesian inference.
[!IMPORTANT] As the 2.0 version introduced many new features, we still have to make breaking changes from time to time. This especially concerns saving and loading of models. We aim to stabilize this from the 2.1 release onwards. Until then, consider pinning your BayesFlow 2.0 installation to an exact version, or re-training after an update for less costly models.
Important Note for Existing Users
You are currently looking at BayesFlow 2.0+, which is a complete rewrite of the library. While it shares the same overall goals with the 1.x versions, the API is not compatible.
[!CAUTION] A few features, most notably hierarchical models, have not been ported to BayesFlow 2.0+ yet. We are working on those features and plan to add them soon. You can find the complete list in the FAQ below.
The Moving from BayesFlow v1.1 to v2.0 guide highlights how concepts and classes relate between the two versions.
Conceptual Overview
A cornerstone idea of amortized Bayesian inference is to employ generative neural networks for parameter estimation, model comparison, and model validation when working with intractable simulators whose behavior as a whole is too complex to be described analytically.
Install
We currently support Python 3.10 to 3.12. You can install the latest stable version from PyPI using:
bash
pip install "bayesflow>=2.0"
If you want the latest features, you can install from source:
bash
pip install git+https://github.com/bayesflow-org/bayesflow.git@dev
If you encounter problems with this or require more control, please refer to the instructions to install from source below.
Backend
To use BayesFlow, you will also need to install one of the following machine learning backends. Note that BayesFlow will not run without a backend.
If you don't know which backend to use, we recommend JAX as it is currently the fastest backend.
As of version 2.0.7, the backend will be set automatically. If you have multiple backends, you can manually set the backend environment variable as described by keras.
For example, inside your Python script write:
python
import os
os.environ["KERAS_BACKEND"] = "jax"
import bayesflow
If you use conda, you can alternatively set this individually for each environment in your terminal. For example:
bash
conda env config vars set KERAS_BACKEND=jax
Or just plainly set the environment variable in your shell:
bash
export KERAS_BACKEND=jax
Getting Started
Using the high-level interface is easy, as demonstrated by the minimal working example below:
```python import bayesflow as bf
workflow = bf.BasicWorkflow( inferencenetwork=bf.networks.CouplingFlow(), summarynetwork=bf.networks.TimeSeriesNetwork(), inferencevariables=["parameters"], summaryvariables=["observables"], simulator=bf.simulators.SIR() )
history = workflow.fitonline(epochs=15, batchsize=32, numbatchesper_epoch=200)
diagnostics = workflow.plotdefaultdiagnostics(test_data=300) ```
For an in-depth exposition, check out our expanding list of resources below.
Books
Many examples from Bayesian Cognitive Modeling: A Practical Course by Lee & Wagenmakers (2013) in BayesFlow.
Tutorial notebooks
- Linear regression starter example
- From ABC to BayesFlow
- Two moons starter example
- Rapid iteration with point estimators
- SIR model with custom summary network
- Bayesian experimental design
- Simple model comparison example
- Likelihood estimation
- Multimodal data
- Moving from BayesFlow v1.1 to v2.0
More tutorials are always welcome! Please consider making a pull request if you have a cool application that you want to contribute.
Contributing
If you want to contribute to BayesFlow, we recommend installing it from source, see CONTRIBUTING.md for more details.
Reporting Issues
If you encounter any issues, please don't hesitate to open an issue here on Github or ask questions on our Discourse Forums.
Documentation & Help
Documentation is available at https://bayesflow.org. Please use the BayesFlow Forums for any BayesFlow-related questions and discussions, and GitHub Issues for bug reports and feature requests.
Citing BayesFlow
You can cite BayesFlow along the lines of:
- We approximated the posterior using neural posterior estimation (NPE) with learned summary statistics (Radev et al., 2020), as implemented in the BayesFlow framework for amortized Bayesian inference (Radev et al., 2023a).
- We approximated the likelihood using neural likelihood estimation (NLE) without hand-crafted summary statistics (Papamakarios et al., 2019), leveraging its implementation in BayesFlow for efficient and flexible inference.
- Radev, S. T., Schmitt, M., Schumacher, L., Elsemüller, L., Pratz, V., Schälte, Y., Köthe, U., & Bürkner, P.-C. (2023a). BayesFlow: Amortized Bayesian workflows with neural networks. The Journal of Open Source Software, 8(89), 5702.(arXiv)(JOSS)
- Radev, S. T., Mertens, U. K., Voss, A., Ardizzone, L., Köthe, U. (2020). BayesFlow: Learning complex stochastic models with invertible neural networks. IEEE Transactions on Neural Networks and Learning Systems, 33(4), 1452-1466. (arXiv)(IEEE TNNLS)
- Radev, S. T., Schmitt, M., Pratz, V., Picchini, U., Köthe, U., & Bürkner, P.-C. (2023b). JANA: Jointly amortized neural approximation of complex Bayesian models. Proceedings of the Thirty-Ninth Conference on Uncertainty in Artificial Intelligence, 216, 1695-1706. (arXiv)(PMLR)
BibTeX:
``` @article{bayesflow2023software, title = {{BayesFlow}: Amortized {B}ayesian workflows with neural networks}, author = {Radev, Stefan T. and Schmitt, Marvin and Schumacher, Lukas and Elsemüller, Lasse and Pratz, Valentin and Schälte, Yannik and Köthe, Ullrich and Bürkner, Paul-Christian}, journal = {Journal of Open Source Software}, volume = {8}, number = {89}, pages = {5702}, year = {2023} }
@article{bayesflow2020original, title = {{BayesFlow}: Learning complex stochastic models with invertible neural networks}, author = {Radev, Stefan T. and Mertens, Ulf K. and Voss, Andreas and Ardizzone, Lynton and K{\"o}the, Ullrich}, journal = {IEEE transactions on neural networks and learning systems}, volume = {33}, number = {4}, pages = {1452--1466}, year = {2020} }
@inproceedings{bayesflow2023jana, title = {{JANA}: Jointly amortized neural approximation of complex {B}ayesian models}, author = {Radev, Stefan T. and Schmitt, Marvin and Pratz, Valentin and Picchini, Umberto and K\"othe, Ullrich and B\"urkner, Paul-Christian}, booktitle = {Proceedings of the Thirty-Ninth Conference on Uncertainty in Artificial Intelligence}, pages = {1695--1706}, year = {2023}, volume = {216}, series = {Proceedings of Machine Learning Research}, publisher = {PMLR} } ```
FAQ
Question: I am starting with Bayesflow, which backend should I use?
Answer: We recommend JAX as it is currently the fastest backend.
Question:
I am getting ModuleNotFoundError: No module named 'tensorflow' when I try to import BayesFlow.
Answer: One of these applies: - You want to use tensorflow as your backend, but you have not installed it. See here.
You want to use a backend other than tensorflow, but have not set the environment variable correctly. See here.
You have set the environment variable, but it is not being picked up by Python. This can happen silently in some development environments (e.g., VSCode or PyCharm). Try setting the backend as shown here in your Python script via
os.environ.
Question: What is the difference between Bayesflow 2.0+ and previous versions?
Answer: BayesFlow 2.0+ is a complete rewrite of the library. It shares the same overall goals with previous versions, but has much better modularity and extensibility. What is more, the new BayesFlow has multi-backend support via Keras3, while the old version was based on TensorFlow.
Question: Should I switch to BayesFlow 2.0+ now? Are there features that are still missing?
Answer: In general, we recommend to switch, as the new version is easier to use and will continue to receive improvements and new features. However, a few features are still missing, so you might want to wait until everything you need has been ported to BayesFlow 2.0+.
Depending on your needs, you might not want to upgrade yet if one of the following applies:
- You have an ongoing project that uses BayesFlow 1.x, and you do not want to allocate time for migrating it to the new API.
- You have already trained models in BayesFlow 1.x, that you do not want to re-train with the new version. Loading models from version 1.x in version 2.0+ is not supported.
- You require a feature that was not ported to BayesFlow 2.0+ yet. To our knowledge,
this applies to:
- Two-level/Hierarchical models (planned for version 2.1):
TwoLevelGenerativeModel,TwoLevelPrior. - Sensitivity analysis (partially discontinued): functionality from the
bayesflow.sensitivitymodule. This is still possible, but we do no longer offer a special module for it. We plan to add a tutorial on this, see #455. - MCMC (discontinued): The
bayesflow.mcmcmodule. We are considering other options to enable the use of BayesFlow in an MCMC setting. - Networks:
EvidentialNetwork. - Model misspecification detection: MMD test in the summary space (see #384).
- Two-level/Hierarchical models (planned for version 2.1):
If you encounter any functionality that is missing and not listed here, please let us know by opening an issue.
Question: I still need the old BayesFlow for some of my projects. How can I install it?
Answer:
You can find and install the old Bayesflow version via the stable-legacy branch on GitHub.
The corresponding documentation can be
accessed by selecting the "stable-legacy" entry in the version picker of the documentation.
You can also install the latest version of BayesFlow v1.x from PyPI using
pip install "bayesflow<2.0"
Awesome Amortized Inference
If you are interested in a curated list of resources, including reviews, software, papers, and other resources related to amortized inference, feel free to explore our community-driven list. If you'd like a paper (by yourself or someone else) featured, please add it to the list with a pull request, an issue, or a message to the maintainers.
Acknowledgments
This project is currently managed by researchers from Rensselaer Polytechnic Institute, TU Dortmund University, and Heidelberg University. It is partially funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) Projects 528702768 and 508399956. The project is further supported by Germany's Excellence Strategy -- EXC-2075 - 390740016 (Stuttgart Cluster of Excellence SimTech) and EXC-2181 - 390900948 (Heidelberg Cluster of Excellence STRUCTURES), the collaborative research cluster TRR 391 – 520388526, as well as the Informatics for Life initiative funded by the Klaus Tschira Foundation.
BayesFlow is a NumFOCUS Affiliated Project.
Owner
- Name: BayesFlow
- Login: bayesflow-org
- Kind: organization
- Location: Germany
- Repositories: 1
- Profile: https://github.com/bayesflow-org
An organization for applications and extensions of amortized Bayesian inference.
Citation (CITATION.cff)
cff-version: "1.2.0"
authors:
- family-names: Radev
given-names: Stefan T.
orcid: "https://orcid.org/0000-0002-6702-9559"
- family-names: Schmitt
given-names: Marvin
orcid: "https://orcid.org/0000-0003-1293-820X"
- family-names: Schumacher
given-names: Lukas
orcid: "https://orcid.org/0000-0003-1512-8288"
- family-names: Elsemüller
given-names: Lasse
orcid: "https://orcid.org/0000-0003-0368-720X"
- family-names: Pratz
given-names: Valentin
orcid: "https://orcid.org/0000-0001-8371-3417"
- family-names: Schälte
given-names: Yannik
orcid: "https://orcid.org/0000-0003-1293-820X"
- family-names: Köthe
given-names: Ullrich
orcid: "https://orcid.org/0000-0001-6036-1287"
- family-names: Bürkner
given-names: Paul-Christian
orcid: "https://orcid.org/0000-0001-5765-8995"
contact:
- family-names: Radev
given-names: Stefan T.
orcid: "https://orcid.org/0000-0002-6702-9559"
doi: 10.5281/zenodo.8346393
message: If you use this software, please cite our article in the
Journal of Open Source Software.
preferred-citation:
authors:
- family-names: Radev
given-names: Stefan T.
orcid: "https://orcid.org/0000-0002-6702-9559"
- family-names: Schmitt
given-names: Marvin
orcid: "https://orcid.org/0000-0003-1293-820X"
- family-names: Schumacher
given-names: Lukas
orcid: "https://orcid.org/0000-0003-1512-8288"
- family-names: Elsemüller
given-names: Lasse
orcid: "https://orcid.org/0000-0003-0368-720X"
- family-names: Pratz
given-names: Valentin
orcid: "https://orcid.org/0000-0001-8371-3417"
- family-names: Schälte
given-names: Yannik
orcid: "https://orcid.org/0000-0003-1293-820X"
- family-names: Köthe
given-names: Ullrich
orcid: "https://orcid.org/0000-0001-6036-1287"
- family-names: Bürkner
given-names: Paul-Christian
orcid: "https://orcid.org/0000-0001-5765-8995"
date-published: 2023-09-22
doi: 10.21105/joss.05702
issn: 2475-9066
issue: 89
journal: Journal of Open Source Software
publisher:
name: Open Journals
start: 5702
title: "BayesFlow: Amortized Bayesian Workflows With Neural Networks"
type: article
url: "https://joss.theoj.org/papers/10.21105/joss.05702"
volume: 8
title: "BayesFlow: Amortized Bayesian Workflows With Neural Networks"
GitHub Events
Total
- Fork event: 25
- Create event: 104
- Commit comment event: 1
- Release event: 7
- Issues event: 218
- Watch event: 222
- Delete event: 89
- Issue comment event: 886
- Member event: 5
- Push event: 824
- Pull request review comment event: 288
- Pull request review event: 300
- Pull request event: 354
Last Year
- Fork event: 25
- Create event: 105
- Commit comment event: 1
- Release event: 7
- Issues event: 218
- Watch event: 222
- Delete event: 89
- Issue comment event: 886
- Member event: 5
- Push event: 824
- Pull request review comment event: 288
- Pull request review event: 300
- Pull request event: 354
Committers
Last synced: 11 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| stefanradev93 | s****3@g****m | 874 |
| larskue | l****s@k****e | 523 |
| Valentin Pratz | g****t@v****e | 139 |
| marvinschmitt | m****l@m****e | 129 |
| Paul-Christian Bürkner | p****r@g****m | 70 |
| Chase-Grajeda | c****a@g****m | 45 |
| rene-bucchia | r****a@g****m | 38 |
| elseml | 6****l | 37 |
| Xenovortex | L****n@g****e | 30 |
| Leona Odole | e****e@u****u | 24 |
| han-ol | g@h****m | 18 |
| Yannik Schaelte | y****e@g****m | 16 |
| Pritom Gogoi | p****1@g****m | 14 |
| MarcoD | m****2@g****m | 12 |
| Kucharssim | k****m@g****m | 11 |
| Radev | r****s@w****u | 10 |
| arrjon | j****a@u****e | 7 |
| AlexAndorra | a****e@g****m | 6 |
| Lukas Schumacher | 3****r | 6 |
| leonhard volz | 4****z | 3 |
| dependabot[bot] | 4****] | 2 |
| Jerry Huang | 5****g | 2 |
| Daniel Habermann | 1****n | 1 |
| desi | d****a@g****m | 1 |
| noahg2 | 6****2 | 1 |
| Jonas Jürgensen | j****n@J****x | 1 |
| zimea | l****n@o****e | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 148
- Total pull requests: 338
- Average time to close issues: 24 days
- Average time to close pull requests: 5 days
- Total issue authors: 28
- Total pull request authors: 17
- Average comments per issue: 1.86
- Average comments per pull request: 2.53
- Merged pull requests: 251
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 145
- Pull requests: 337
- Average time to close issues: 13 days
- Average time to close pull requests: 4 days
- Issue authors: 27
- Pull request authors: 17
- Average comments per issue: 1.67
- Average comments per pull request: 2.52
- Merged pull requests: 251
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- vpratz (48)
- LarsKue (17)
- han-ol (14)
- marvinschmitt (8)
- paul-buerkner (7)
- Kucharssim (7)
- stefanradev93 (6)
- arrjon (5)
- elseml (5)
- maltelueken (4)
- philippreiser (4)
- thegialeo (4)
- jerrymhuang (2)
- sjedhoff (2)
- payelghosh537482 (2)
Pull Request Authors
- vpratz (124)
- LarsKue (71)
- han-ol (26)
- stefanradev93 (19)
- arrjon (17)
- Kucharssim (14)
- paul-buerkner (14)
- eodole (13)
- elseml (11)
- daniel-habermann (9)
- jerrymhuang (8)
- marvinschmitt (3)
- thegialeo (3)
- enbrown (2)
- Chase-Grajeda (2)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 1,858 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 14
- Total maintainers: 1
pypi.org: bayesflow
Amortizing Bayesian Inference With Neural Networks
- Documentation: https://bayesflow.readthedocs.io/
- License: MIT License Copyright (c) 2024 The BayesFlow Developers 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.
-
Latest release: 2.0.7
published 6 months ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v2 composite
- actions/setup-python v2 composite