Skip to content

Commit eaf24af

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into dev
2 parents 84d9ab8 + 4251bbd commit eaf24af

File tree

15 files changed

+166
-564
lines changed

15 files changed

+166
-564
lines changed

.github/workflows/multiversion-docs.yaml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ on:
66
workflow_dispatch:
77
push:
88
branches:
9-
- dev
9+
- main
10+
- stable-legacy
1011

1112
jobs:
1213

@@ -17,16 +18,11 @@ jobs:
1718
- name: Checkout main
1819
uses: actions/checkout@v3
1920
with:
20-
path: dev
21+
path: repo
22+
ref: main
2123
fetch-depth: 0
2224
fetch-tags: true
2325

24-
- name: Checkout gh-pages-dev
25-
uses: actions/checkout@v3
26-
with:
27-
path: gh-pages-dev
28-
ref: gh-pages-dev
29-
3026
- name: Set up Python
3127
uses: actions/setup-python@v4
3228
with:
@@ -35,22 +31,31 @@ jobs:
3531

3632
- name: Install dependencies
3733
run: |
38-
cd ./dev
34+
cd ./repo
3935
python -m pip install .[docs]
36+
4037
- name: Create local branches
4138
run: |
42-
cd ./dev
43-
git branch main remotes/origin/main
39+
cd ./repo
40+
git branch stable-legacy remotes/origin/stable-legacy
41+
4442
- name: Make the Sphinx docs
4543
run: |
46-
cd ./dev/docsrc
44+
cd ./repo/docsrc
4745
make clean
4846
make docs-sequential
47+
48+
- name: Checkout gh-pages-dev
49+
uses: actions/checkout@v3
50+
with:
51+
path: gh-pages-dev
52+
ref: gh-pages-dev
53+
4954
- name: Commit changes to docs
5055
run: |
5156
cd ./gh-pages-dev
5257
git rm --quiet -rf .
53-
cp -R ../dev/docs/* ./
58+
cp -R ../repo/docs/* ./
5459
git config --local user.email ""
5560
git config --local user.name "github-actions"
5661
git add -A

.github/workflows/test-docs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
pull_request:
66
branches:
77
- dev
8+
- main
89

910
jobs:
1011
build_docs:

.github/workflows/tests.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
name: Tests
33

44
on:
5+
workflow_dispatch:
56
pull_request:
7+
branches:
8+
- main
9+
- dev
610
push:
711
branches:
812
- main
913
- dev
10-
- streamlined-backend
1114

1215

1316
jobs:
@@ -82,7 +85,7 @@ jobs:
8285
- name: Install PyTorch
8386
if: ${{ matrix.backend == 'torch' }}
8487
run: |
85-
conda install pytorch torchvision torchaudio cpuonly -c pytorch
88+
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
8689
8790
- name: Show Environment Info
8891
run: |
@@ -92,6 +95,7 @@ jobs:
9295
conda config --show
9396
printenv | sort
9497
conda env export
98+
pip list
9599
96100
- name: Run Tests
97101
run: |
@@ -101,6 +105,12 @@ jobs:
101105
run: |
102106
coverage xml
103107
108+
- name: Upload test results to Codecov
109+
if: ${{ !cancelled() }}
110+
uses: codecov/test-results-action@v1
111+
with:
112+
token: ${{ secrets.CODECOV_TOKEN }}
113+
104114
- name: Upload Coverage Reports to CodeCov
105115
uses: codecov/codecov-action@v4
106116
with:

README.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# BayesFlow <img src="img/bayesflow_hex.png" style="float: right; width: 20%; height: 20%;" align="right" alt="BayesFlow Logo" />
22
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/bayesflow-org/bayesflow/tests.yaml?style=for-the-badge&label=Tests)
3-
![Codecov](https://img.shields.io/codecov/c/github/bayesflow-org/bayesflow/dev?style=for-the-badge)
3+
![Codecov](https://img.shields.io/codecov/c/github/bayesflow-org/bayesflow?style=for-the-badge&link=https%3A%2F%2Fapp.codecov.io%2Fgh%2Fbayesflow-org%2Fbayesflow%2Ftree%2Fmain)
44
[![DOI](https://img.shields.io/badge/DOI-10.21105%2Fjoss.05702-blue?style=for-the-badge)](https://doi.org/10.21105/joss.05702)
55
![PyPI - License](https://img.shields.io/pypi/l/bayesflow?style=for-the-badge)
66

7-
BayesFlow 2 is a Python library for simulation-based **Amortized Bayesian Inference** with neural networks.
7+
BayesFlow is a Python library for simulation-based **Amortized Bayesian Inference** with neural networks.
88
It provides users and researchers with:
99

1010
- A user-friendly API for rapid Bayesian workflows
1111
- A rich collection of neural network architectures
1212
- 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)
1313

14-
BayesFlow is designed to be a flexible and efficient tool that enables rapid statistical inference
14+
BayesFlow (version 2+) is designed to be a flexible and efficient tool that enables rapid statistical inference
1515
fueled by continuous progress in generative AI and Bayesian inference.
1616

1717
## Conceptual Overview
@@ -49,7 +49,7 @@ history = workflow.fit_online(epochs=50, batch_size=32, num_batches_per_epoch=50
4949
diagnostics = workflow.plot_default_diagnostics(test_data=300)
5050
```
5151

52-
For an in-depth exposition, check out our walkthrough notebooks below. More tutorials are always welcome!
52+
For an in-depth exposition, check out our walkthrough notebooks below.
5353

5454
1. [Linear regression starter example](examples/Linear_Regression_Starter.ipynb)
5555
2. [From ABC to BayesFlow](examples/From_ABC_to_BayesFlow.ipynb)
@@ -59,6 +59,8 @@ For an in-depth exposition, check out our walkthrough notebooks below. More tuto
5959
6. [Bayesian experimental design](examples/Bayesian_Experimental_Design.ipynb)
6060
7. [Simple model comparison example](examples/One_Sample_TTest.ipynb)
6161

62+
More tutorials are always welcome! Please consider making a pull request if you have a cool application that you want to contribute.
63+
6264
## Install
6365

6466
### Backend
@@ -69,9 +71,8 @@ First, install one machine learning backend of choice. Note that BayesFlow **wil
6971
- [Install PyTorch](https://pytorch.org/get-started/locally/)
7072
- [Install TensorFlow](https://www.tensorflow.org/install)
7173

72-
If you don't know which backend to use, we recommend JAX to get started.
73-
It is the fastest backend and already works pretty reliably with the current
74-
dev version of bayesflow.
74+
If you don't know which backend to use, we recommend JAX as it is currently
75+
the fastest backend.
7576

7677
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:
7778

@@ -93,22 +94,22 @@ This way, you also don't have to manually set the backend every time you are sta
9394

9495
### Using pip
9596

96-
You can install the dev version with pip:
97+
You can install the Bayesflow from Github with pip:
9798

9899
```bash
99-
pip install git+https://github.com/bayesflow-org/bayesflow@dev
100+
pip install git+https://github.com/bayesflow-org/bayesflow@main
100101
```
101102

102-
### Using Conda (coming soon)
103+
### Using Conda
103104

104-
The dev version is not conda-installable yet.
105+
Bayesflow is currently not conda-installable.
105106

106107
### From Source
107108

108-
If you want to contribute to BayesFlow, we recommend installing the dev branch from source:
109+
If you want to contribute to BayesFlow, we recommend installing it from source:
109110

110111
```bash
111-
git clone -b dev [email protected]:bayesflow-org/bayesflow.git
112+
git clone -b main [email protected]:bayesflow-org/bayesflow.git
112113
cd <local-path-to-bayesflow-repository>
113114
conda env create --file environment.yaml --name bayesflow
114115
```
@@ -167,10 +168,24 @@ You can cite BayesFlow along the lines of:
167168
}
168169
```
169170

171+
## FAQ
172+
173+
- *I am starting with Bayesflow, which backend shall I use?*
174+
**A**: We recommend JAX as it is currently the fastest backend.
175+
176+
- *What is the difference between Bayesflow 2.0+ and previous versions?*
177+
**A**: BayesFlow 2.0+ is a complete rewrite of the library. It shares the same
178+
overall goals with previous versions, but has much better modularity
179+
and extensibility. What is more, the new BayesFlow has multi-backend support via Keras3,
180+
while the old version was based on TensorFlow.
181+
182+
- *I still need the old BayesFlow for some of my projects. How can I install it?*
183+
**A**: You can find and install the old Bayesflow version via the `stable-legacy` branch on GitHub.
184+
170185
## Awesome Amortized Inference
171186

172187
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).
173188

174189
## Acknowledgments
175190

176-
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.
191+
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/adapters/adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def apply(
241241
exclude: str | Sequence[str] = None,
242242
**kwargs,
243243
):
244-
"""Append a :py:class:`~transforms.LambdaTransform` to the adapter.
244+
"""Append a :py:class:`~transforms.NumpyTransform` to the adapter.
245245
246246
Parameters
247247
----------

bayesflow/adapters/transforms/numpy_transform.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class NumpyTransform(ElementwiseTransform):
99
"""
1010
A class to apply element-wise transformations using plain NumPy functions.
1111
12-
Attributes:
12+
Attributes
1313
----------
1414
_forward : str
1515
The name of the NumPy function to apply in the forward transformation.
@@ -31,11 +31,11 @@ def __init__(self, forward: str, inverse: str = None):
3131
"""
3232
Initializes the NumpyTransform with specified forward and inverse functions.
3333
34-
Parameters:
34+
Parameters
3535
----------
36-
forward: str
36+
forward : str
3737
The name of the NumPy function to use for the forward transformation.
38-
inverse: str, optional
38+
inverse : str, optional
3939
The name of the NumPy function to use for the inverse transformation.
4040
By default, the inverse is inferred from the forward argument for supported methods.
4141
"""

bayesflow/approximators/point_approximator.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ def estimate(
2323
conditions: dict[str, np.ndarray],
2424
split: bool = False,
2525
**kwargs,
26-
) -> dict[str, dict[str, np.ndarray]]:
26+
) -> dict[str, dict[str, np.ndarray | dict[str, np.ndarray]]]:
2727
"""
28-
Provides point estimates based on provided conditions (e.g., observables).
28+
Estimates point summaries of inference variables based on specified conditions.
2929
3030
This method processes input conditions, computes estimates, applies necessary adapter transformations,
3131
and optionally splits the resulting arrays along the last axis.
3232
3333
Parameters
3434
----------
3535
conditions : dict[str, np.ndarray]
36-
A dictionary mapping variable names to NumPy arrays representing the conditions
36+
A dictionary mapping variable names to arrays representing the conditions
3737
for the estimation process.
3838
split : bool, optional
3939
If True, the estimated arrays are split along the last axis, by default False.
@@ -42,9 +42,15 @@ def estimate(
4242
4343
Returns
4444
-------
45-
dict[str, dict[str, np.ndarray]]
46-
A nested dictionary where the top-level keys correspond to original variable names,
47-
and values contain dictionaries mapping estimation results to NumPy arrays.
45+
estimates : dict[str, dict[str, np.ndarray or dict[str, np.ndarray]]]
46+
The estimates of inference variables in a nested dictionary.
47+
48+
1. Each first-level key is the name of an inference variable.
49+
2. Each second-level key is the name of a scoring rule.
50+
3. (If the scoring rule comprises multiple estimators, each third-level key is the name of an estimator.)
51+
52+
Each estimator output (i.e., dictionary value that is not itself a dictionary) is an array
53+
of shape (num_datasets, point_estimate_size, variable_block_size).
4854
"""
4955

5056
conditions = self._prepare_conditions(conditions, **kwargs)
@@ -67,39 +73,43 @@ def sample(
6773
conditions: dict[str, np.ndarray],
6874
split: bool = False,
6975
**kwargs,
70-
) -> dict[str, np.ndarray]:
76+
) -> dict[str, dict[str, np.ndarray]]:
7177
"""
72-
Generate samples from point estimates based on provided conditions. These samples
73-
will generally not correspond to samples from the fully Bayesian posterior, since
74-
they will assume some parametric form (e.g., Gaussian in the case of mean score).
78+
Draws samples from a parametric distribution based on point estimates for given input conditions.
7579
76-
This method draws a specified number of samples according to the given conditions,
77-
applies necessary transformations, and optionally splits the resulting arrays along the last axis.
80+
These samples will generally not correspond to samples from the fully Bayesian posterior, since
81+
they will assume some parametric form (e.g., multivariate normal when using the MultivariateNormalScore).
7882
7983
Parameters
8084
----------
8185
num_samples : int
8286
The number of samples to generate.
8387
conditions : dict[str, np.ndarray]
84-
A dictionary mapping variable names to NumPy arrays representing the conditions
88+
A dictionary mapping variable names to arrays representing the conditions
8589
for the sampling process.
8690
split : bool, optional
8791
If True, the sampled arrays are split along the last axis, by default False.
92+
Currently not supported for `PointApproximator`.
8893
**kwargs
8994
Additional keyword arguments passed to underlying processing functions.
9095
9196
Returns
9297
-------
93-
dict[str, np.ndarray]
94-
A dictionary where keys correspond to variable names and values are NumPy arrays
95-
containing the generated samples.
96-
"""
98+
samples : dict[str, np.ndarray or dict[str, np.ndarray]]
99+
Samples for all inference variables and all parametric scoring rules in a nested dictionary.
100+
101+
1. Each first-level key is the name of an inference variable.
102+
2. (If there are multiple parametric scores, each second-level key is the name of such a score.)
97103
104+
Each output (i.e., dictionary value that is not itself a dictionary) is an array
105+
of shape (num_datasets, num_samples, variable_block_size).
106+
"""
98107
conditions = self._prepare_conditions(conditions, **kwargs)
99108
samples = self._sample(num_samples, **conditions, **kwargs)
100109
samples = self._apply_inverse_adapter_to_samples(samples, **kwargs)
101110
# Optionally split the arrays along the last axis.
102111
if split:
112+
raise NotImplementedError("split=True is currently not supported for `PointApproximator`.")
103113
samples = split_arrays(samples, axis=-1)
104114
# Squeeze samples if there's only one key-value pair.
105115
samples = self._squeeze_samples(samples)

0 commit comments

Comments
 (0)