You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BayesFlow is a Python library for simulation-based **Amortized Bayesian Inference** with neural networks.
4
-
It provides users with:
4
+
It provides users and researchers with:
5
5
6
6
- A user-friendly API for rapid Bayesian workflows
7
7
- A rich collection of neural network architectures
8
-
- Multi-Backend Support via [Keras3](https://keras.io/keras_3/): You can use [PyTorch](https://github.com/pytorch/pytorch), [TensorFlow](https://github.com/tensorflow/tensorflow), or [JAX](https://github.com/google/jax)
8
+
- Multi-backend support via [Keras3](https://keras.io/keras_3/): You can use [PyTorch](https://github.com/pytorch/pytorch), [TensorFlow](https://github.com/tensorflow/tensorflow), or [JAX](https://github.com/google/jax)
9
9
10
-
BayesFlow is designed to be a flexible and efficient tool that enables rapid statistical inference
10
+
BayesFlow (version 2+) is designed to be a flexible and efficient tool that enables rapid statistical inference
11
11
fueled by continuous progress in generative AI and Bayesian inference.
12
12
13
13
## Conceptual Overview
@@ -25,78 +25,108 @@ neural networks for parameter estimation, model comparison, and model validation
25
25
when working with intractable simulators whose behavior as a whole is too
26
26
complex to be described analytically.
27
27
28
-
## Disclaimer
28
+
## Getting Started
29
29
30
-
This is the current dev version of BayesFlow, which constitutes a complete refactor of the library built on Keras 3. This way, you can now use any of the major deep learning libraries as backend for BayesFlow. The refactor is still work in progress with some of the advanced features not yet implemented. We are actively working on them and promise to catch up soon.
30
+
Using the high-level interface is easy, as demonstrated by the minimal working example below:
31
31
32
-
If you encounter any issues, please don't hesitate to open an issue here on [Github](https://github.com/bayesflow-org/bayesflow/issues) or ask questions on our [Discourse Forums](https://discuss.bayesflow.org/).
7.[Simple model comparison example](examples/One_Sample_TTest.ipynb)
47
57
48
-
Once installed, [set the backend environment variable as required by keras](https://keras.io/getting_started/#configuring-your-backend). For example, inside your Python script write:
58
+
More tutorials are always welcome! Please consider making a pull request if you have a cool application that you want to contribute.
49
59
50
-
```python
51
-
import os
52
-
os.environ["KERAS_BACKEND"] ="jax"
53
-
import bayesflow
54
-
```
60
+
## Install
61
+
62
+
```{eval-rst}
63
+
.. tab-set::
55
64
56
-
If you use conda, you can alternatively set this individually for each environment in your terminal. For example:
This way, you also don't have to manually set the backend every time you are starting Python to use BayesFlow.
78
+
### Backend
79
+
80
+
To use BayesFlow, you will also need to install one of the following machine learning backends.
81
+
Note that BayesFlow **will not run** without a backend.
63
82
64
-
**Caution:** Some people report that the IDE (e.g., VSCode or PyCharm) can silently overwrite environment variables. If you have set your backend as an environment variable and you still get keras-related import errors when loading BayesFlow, these IDE shenanigans might be the culprit. Try setting the keras backend in your Python script via `import os; os.environ["KERAS_BACKEND"] = "<YOUR-BACKEND>"`.
If you don't know which backend to use, we recommend JAX as it is currently the fastest backend.
67
88
68
-
You can then install BayesFlow itself using one of the following options:
89
+
Once installed, [set the backend environment variable as required by keras](https://keras.io/getting_started/#configuring-your-backend) to one of the following:
90
+
91
+
-`KERAS_BACKEND=jax`
92
+
-`KERAS_BACKEND=torch`
93
+
-`KERAS_BACKEND=tensorflow`
94
+
95
+
For example, to set the backend to `jax`, you can use one of the following:
**Caution:** Some development environments (e.g., VSCode or PyCharm) can silently overwrite environment variables. If you have set your backend as an environment variable and you still get keras-related import errors when loading BayesFlow, these IDE shenanigans might be the culprit. Try setting the keras backend in your Python script via `import os; os.environ["KERAS_BACKEND"] = "<YOUR-BACKEND>"`.
92
122
93
-
This will create a new conda environment. Please activate it and install your preferred backend.
94
-
```
123
+
## Contributing
95
124
96
-
## Getting Started
125
+
To contribute to BayesFlow, please check out the [git repository](https://github.com/bayesflow-org/bayesflow)
126
+
127
+
### Reporting Issues
97
128
98
-
To get started, take a look at our [Getting Started Tutorial](_examples/Linear_Regression_Starter.ipynb).
99
-
After that, check out some of our walk-through notebooks in the [Examples](examples) section.
129
+
If you encounter any issues, please don't hesitate to open an issue here on [Github](https://github.com/bayesflow-org/bayesflow/issues) or ask questions on our [Discourse Forums](https://discuss.bayesflow.org/).
100
130
101
131
## Getting Help
102
132
@@ -106,9 +136,8 @@ Please use the [BayesFlow Forums](https://discuss.bayesflow.org/) for any BayesF
106
136
107
137
You can cite BayesFlow along the lines of:
108
138
109
-
- We approximated the posterior with neural posterior estimation and learned summary statistics (NPE; Radev et al., 2020), as implemented in the BayesFlow software for amortized Bayesian workflows (Radev et al., 2023a).
110
-
- We approximated the likelihood with neural likelihood estimation (NLE; Papamakarios et al., 2019) without hand-crafted summary statistics, as implemented in the BayesFlow software for amortized Bayesian workflows (Radev et al., 2023b).
111
-
- We performed simultaneous posterior and likelihood estimation with jointly amortized neural approximation (JANA; Radev et al., 2023a), as implemented in the BayesFlow software for amortized Bayesian workflows (Radev et al., 2023b).
139
+
- 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).
140
+
- 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.
112
141
113
142
1. 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](https://arxiv.org/abs/2306.16015))([JOSS](https://joss.theoj.org/papers/10.21105/joss.05702))
114
143
2. 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](https://arxiv.org/abs/2003.06281))([IEEE TNNLS](https://ieeexplore.ieee.org/document/9298920))
@@ -149,6 +178,61 @@ You can cite BayesFlow along the lines of:
149
178
}
150
179
```
151
180
181
+
## FAQ
182
+
183
+
-------------
184
+
185
+
**Question:**
186
+
I am starting with Bayesflow, which backend should I use?
187
+
188
+
**Answer:**
189
+
We recommend JAX as it is currently the fastest backend.
190
+
191
+
-------------
192
+
193
+
**Question:**
194
+
I am getting `ModuleNotFoundError: No module named 'tensorflow'` when I try to import BayesFlow.
195
+
196
+
**Answer:**
197
+
One of these applies:
198
+
- You want to use tensorflow as your backend, but you have not installed it.
199
+
See [here](https://www.tensorflow.org/install).
200
+
201
+
202
+
- You want to use a backend other than tensorflow, but have not set the environment variable correctly.
203
+
See [here](https://keras.io/getting_started/#configuring-your-backend).
204
+
205
+
206
+
- You have set the environment variable, but it is not being picked up by Python.
207
+
This can happen silently in some development environments (e.g., VSCode or PyCharm).
208
+
Try setting the backend as shown [here](https://keras.io/getting_started/#configuring-your-backend)
209
+
in your Python script via `os.environ`.
210
+
211
+
-------------
212
+
213
+
**Question:**
214
+
What is the difference between Bayesflow 2.0+ and previous versions?
215
+
216
+
**Answer:**
217
+
BayesFlow 2.0+ is a complete rewrite of the library. It shares the same
218
+
overall goals with previous versions, but has much better modularity
219
+
and extensibility. What is more, the new BayesFlow has multi-backend support via Keras3,
220
+
while the old version was based on TensorFlow.
221
+
222
+
-------------
223
+
224
+
**Question:**
225
+
I still need the old BayesFlow for some of my projects. How can I install it?
226
+
227
+
**Answer:**
228
+
You can find and install the old Bayesflow version via the `stable-legacy` branch on GitHub.
229
+
230
+
-------------
231
+
232
+
## Awesome Amortized Inference
233
+
234
+
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](https://github.com/bayesflow-org/awesome-amortized-inference).
235
+
152
236
## Acknowledgments
153
237
154
238
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, Project 528702768). 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), as well as the Informatics for Life initiative funded by the Klaus Tschira Foundation.
0 commit comments