Skip to content

Commit 8260ea4

Browse files
Update README.md
1 parent 18dd8f6 commit 8260ea4

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

README.md

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# BayesFlow <img src="img/bayesflow_hex.png" align="right" width=20% height=20% />
1+
# BayesFlow <img src="https://github.com/stefanradev93/BayesFlow/blob/master/img/bayesflow_hex.png?raw=true" align="right" width=20% height=20% />
22

33
[![Actions Status](https://github.com/stefanradev93/bayesflow/workflows/Tests/badge.svg)](https://github.com/stefanradev93/bayesflow/actions)
44
[![Licence](https://img.shields.io/github/license/stefanradev93/BayesFlow)](https://img.shields.io/github/license/stefanradev93/BayesFlow)
@@ -17,7 +17,7 @@ For starters, check out some of our walk-through notebooks:
1717

1818
## Project Documentation
1919

20-
The project documentation is available at <https://bayesflow.org>
20+
The project documentation is available at <https://bayesflow.readthedocs.io>
2121

2222
## Installation
2323

@@ -31,7 +31,7 @@ when working with intractable simulators whose behavior as a whole is too
3131
complex to be described analytically. The figure below presents a higher-level
3232
overview of neurally bootstrapped Bayesian inference.
3333

34-
<img src="img/high_level_framework.png" width=80% height=80%>
34+
<img src="https://github.com/stefanradev93/BayesFlow/blob/master/img/high_level_framework.png?raw=true" width=80% height=80%>
3535

3636
## Getting Started: Parameter Estimation
3737

@@ -77,13 +77,13 @@ Next, we create our BayesFlow setup consisting of a summary and an inference net
7777
```python
7878
summary_net = bf.networks.DeepSet()
7979
inference_net = bf.networks.InvertibleNetwork(num_params=2)
80-
amortizer = bf.amortizers.AmortizedPosterior(inference_net, summary_net)
80+
amortized_posterior = bf.amortizers.AmortizedPosterior(inference_net, summary_net)
8181
```
8282

8383
Finally, we connect the networks with the generative model via a `Trainer` instance:
8484

8585
```python
86-
trainer = bf.trainers.Trainer(amortizer=amortizer, generative_model=generative_model)
86+
trainer = bf.trainers.Trainer(amortizer=amortized_posterior, generative_model=generative_model)
8787
```
8888

8989
We are now ready to train an amortized posterior approximator. For instance,
@@ -101,7 +101,7 @@ the model-amortizer combination:
101101
fig = trainer.diagnose_sbc_histograms()
102102
```
103103

104-
<img src="img/showcase_sbc.png" width=65% height=65%>
104+
<img src="https://github.com/stefanradev93/BayesFlow/blob/master/img/showcase_sbc.png?raw=true" width=65% height=65%>
105105

106106
The histograms are roughly uniform and lie within the expected range for
107107
well-calibrated inference algorithms as indicated by the shaded gray areas.
@@ -113,7 +113,7 @@ per data set:
113113

114114
```python
115115
new_sims = trainer.configurator(generative_model(200))
116-
posterior_draws = amortizer.sample(new_sims, n_samples=500)
116+
posterior_draws = amortized_posterior.sample(new_sims, n_samples=500)
117117
```
118118

119119
We can then quickly inspect the how well the model can recover its parameters
@@ -123,7 +123,7 @@ across the simulated data sets.
123123
fig = bf.diagnostics.plot_recovery(posterior_draws, new_sims['parameters'])
124124
```
125125

126-
<img src="img/showcase_recovery.png" width=65% height=65%>
126+
<img src="https://github.com/stefanradev93/BayesFlow/blob/master/img/showcase_recovery.png?raw=true" width=65% height=65%>
127127

128128
For any individual data set, we can also compare the parameters' posteriors with
129129
their corresponding priors:
@@ -132,7 +132,7 @@ their corresponding priors:
132132
fig = bf.diagnostics.plot_posterior_2d(posterior_draws[0], prior=generative_model.prior)
133133
```
134134

135-
<img src="img/showcase_posterior.png" width=45% height=45%>
135+
<img src="https://github.com/stefanradev93/BayesFlow/blob/master/img/showcase_posterior.png?raw=true" width=45% height=45%>
136136

137137
We see clearly how the posterior shrinks relative to the prior for both
138138
model parameters as a result of conditioning on the data.
@@ -161,13 +161,13 @@ amortized inference if the generative model is a poor representation of reality?
161161
A modified loss function optimizes the learned summary statistics towards a unit
162162
Gaussian and reliably detects model misspecification during inference time.
163163

164-
![](docs/source/images/model_misspecification_amortized_sbi.png?raw=true)
164+
![](https://github.com/stefanradev93/BayesFlow/blob/master/docs/source/images/model_misspecification_amortized_sbi.png?raw=true)
165165

166166
In order to use this method, you should only provide the `summary_loss_fun` argument
167167
to the `AmortizedPosterior` instance:
168168

169169
```python
170-
amortizer = bf.amortizers.AmortizedPosterior(inference_net, summary_net, summary_loss_fun='MMD')
170+
amortized_posterior = bf.amortizers.AmortizedPosterior(inference_net, summary_net, summary_loss_fun='MMD')
171171
```
172172

173173
The amortizer knows how to combine its losses and you can inspect the summary space for outliers during inference.
@@ -207,13 +207,13 @@ Next, we construct our neural network with a `PMPNetwork` for approximating post
207207
```python
208208
summary_net = bf.networks.DeepSet()
209209
probability_net = bf.networks.PMPNetwork(num_models=2)
210-
amortizer = bf.amortizers.AmortizedModelComparison(probability_net, summary_net)
210+
amortized_bmc = bf.amortizers.AmortizedModelComparison(probability_net, summary_net)
211211
```
212212

213213
We combine all previous steps with a `Trainer` instance and train the neural approximator:
214214

215215
```python
216-
trainer = bf.trainers.Trainer(amortizer=amortizer, generative_model=meta_model)
216+
trainer = bf.trainers.Trainer(amortizer=amortized_bmc, generative_model=meta_model)
217217
losses = trainer.train_online(epochs=3, iterations_per_epoch=100, batch_size=32)
218218
```
219219

@@ -226,7 +226,7 @@ sims = trainer.configurator(meta_model(5000))
226226
When feeding the data to our trained network, we almost immediately obtain posterior model probabilities for each of the 5000 data sets:
227227

228228
```python
229-
model_probs = amortizer.posterior_probs(sims)
229+
model_probs = amortized_bmc.posterior_probs(sims)
230230
```
231231

232232
How good are these predicted probabilities in the closed world? We can have a look at the calibration:
@@ -235,15 +235,15 @@ How good are these predicted probabilities in the closed world? We can have a lo
235235
cal_curves = bf.diagnostics.plot_calibration_curves(sims["model_indices"], model_probs)
236236
```
237237

238-
<img src="img/showcase_calibration_curves.png" width=65% height=65%>
238+
<img src="https://github.com/stefanradev93/BayesFlow/blob/master/img/showcase_calibration_curves.png?raw=true" width=65% height=65%>
239239

240240
Our approximator shows excellent calibration, with the calibration curve being closely aligned to the diagonal, an expected calibration error (ECE) near 0 and most predicted probabilities being certain of the model underlying a data set. We can further assess patterns of misclassification with a confusion matrix:
241241

242242
```python
243243
conf_matrix = bf.diagnostics.plot_confusion_matrix(sims["model_indices"], model_probs)
244244
```
245245

246-
<img src="img/showcase_confusion_matrix.png" width=44% height=44%>
246+
<img src="https://github.com/stefanradev93/BayesFlow/blob/master/img/showcase_confusion_matrix.png?raw=true" width=44% height=44%>
247247

248248
For the vast majority of simulated data sets, the "true" data-generating model is correctly identified. With these diagnostic results backing us up, we can proceed and apply our trained network to empirical data.
249249

@@ -257,13 +257,35 @@ C. (2021). Amortized Bayesian Model Comparison with Evidental Deep Learning.
257257
doi:10.1109/TNNLS.2021.3124052 available for free at: https://arxiv.org/abs/2004.10629
258258

259259
- Schmitt, M., Radev, S. T., & Bürkner, P. C. (2022). Meta-Uncertainty in
260-
Bayesian Model Comparison. <em>ArXiv preprint</em>, available for free at:
261-
https://arxiv.org/abs/2210.07278
260+
Bayesian Model Comparison. In <em>International Conference on Artificial Intelligence
261+
and Statistics</em>, 11-29, PMLR, available for free at: https://arxiv.org/abs/2210.07278
262262

263263
- Elsemüller, L., Schnuerch, M., Bürkner, P. C., & Radev, S. T. (2023). A Deep
264264
Learning Method for Comparing Bayesian Hierarchical Models. <em>ArXiv preprint</em>,
265265
available for free at: https://arxiv.org/abs/2301.11873
266266

267-
## Likelihood emulation
267+
## Likelihood Emulation
268268

269-
Example coming soon...
269+
In order to learn the exchangeable (i.e., permutation invariant) likelihood from the minimal example instead of the posterior, you may use the `AmortizedLikelihood` wrapper:
270+
271+
```python
272+
likelihood_net = bf.networks.InvertibleNetwork(num_params=2)
273+
amortized_likelihood = bf.amortizers.AmortizedLikelihood(likelihood_net)
274+
```
275+
276+
This wrapper can interact with a `Trainer` instance in the same way as the `AmortizedPosterior`. Finally, you can also learn the likelihood and the posterior *simultaneously* by using the `AmortizedPosteriorLikelihood` wrapper and choosing your preferred training scheme:
277+
278+
```python
279+
joint_amortizer = bf.amortizers.AmortizedPosteriorLikelihood(amortized_posterior, amortized_likelihood)
280+
```
281+
282+
Learning both densities enables us to approximate marginal likelihoods or perform approximate leave-one-out cross-validation (LOO-CV) for prior or posterior predictive model comparison, respectively.
283+
284+
### References and Further Reading
285+
286+
Radev, S. T., Schmitt, M., Pratz, V., Picchini, U., Köthe, U., & Bürkner, P. C. (2023).
287+
JANA: Jointly Amortized Neural Approximation of Complex Bayesian Models. <em>arXiv preprint</em>,
288+
available for free at: https://arxiv.org/abs/2302.09125
289+
290+
## Support
291+
This work is supported by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) under Germany’s Excellence Strategy -– EXC-2181 - 390900948 (the Heidelberg Cluster of Excellence STRUCTURES) and -- EXC-2075 - 390740016 (the Stuttgart Cluster of Excellence SimTech), the Informatics for Life initiative funded by the Klaus Tschira Foundation, and Google Cloud through the Academic Research Grants program.

0 commit comments

Comments
 (0)