aspire-inference 0.1.0a7__tar.gz → 0.1.0a9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aspire_inference-0.1.0a9/PKG-INFO +111 -0
- aspire_inference-0.1.0a9/README.md +72 -0
- aspire_inference-0.1.0a9/aspire_inference.egg-info/PKG-INFO +111 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/aspire_inference.egg-info/SOURCES.txt +13 -0
- aspire_inference-0.1.0a9/docs/Makefile +20 -0
- aspire_inference-0.1.0a9/docs/conf.py +71 -0
- aspire_inference-0.1.0a9/docs/entry_points.rst +29 -0
- aspire_inference-0.1.0a9/docs/examples.rst +28 -0
- aspire_inference-0.1.0a9/docs/index.rst +63 -0
- aspire_inference-0.1.0a9/docs/installation.rst +73 -0
- aspire_inference-0.1.0a9/docs/multiprocessing.rst +70 -0
- aspire_inference-0.1.0a9/docs/recipes.rst +70 -0
- aspire_inference-0.1.0a9/docs/requirements.txt +3 -0
- aspire_inference-0.1.0a9/docs/user_guide.rst +172 -0
- aspire_inference-0.1.0a9/examples/blackjax_smc_example.py +158 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/pyproject.toml +1 -0
- aspire_inference-0.1.0a9/readthedocs.yml +15 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/__init__.py +2 -0
- aspire_inference-0.1.0a9/src/aspire/flows/__init__.py +68 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/samplers/smc/blackjax.py +17 -5
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/transforms.py +3 -2
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/tests/integration_tests/conftest.py +17 -4
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/tests/integration_tests/test_integration.py +2 -2
- aspire_inference-0.1.0a9/tests/test_flows/test_flows_core.py +47 -0
- aspire_inference-0.1.0a7/PKG-INFO +0 -52
- aspire_inference-0.1.0a7/README.md +0 -14
- aspire_inference-0.1.0a7/aspire_inference.egg-info/PKG-INFO +0 -52
- aspire_inference-0.1.0a7/src/aspire/flows/__init__.py +0 -40
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/.github/workflows/lint.yml +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/.github/workflows/publish.yml +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/.github/workflows/tests.yml +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/.gitignore +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/.pre-commit-config.yaml +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/LICENSE +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/aspire_inference.egg-info/dependency_links.txt +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/aspire_inference.egg-info/requires.txt +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/aspire_inference.egg-info/top_level.txt +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/examples/basic_example.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/examples/smc_example.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/setup.cfg +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/aspire.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/flows/base.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/flows/jax/__init__.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/flows/jax/flows.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/flows/jax/utils.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/flows/torch/__init__.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/flows/torch/flows.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/history.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/plot.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/samplers/__init__.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/samplers/base.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/samplers/importance.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/samplers/mcmc.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/samplers/smc/__init__.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/samplers/smc/base.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/samplers/smc/emcee.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/samplers/smc/minipcn.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/samples.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/src/aspire/utils.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/tests/conftest.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/tests/test_flows/test_jax_flows/test_flowjax_flows.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/tests/test_flows/test_torch_flows/test_zuko_flows.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/tests/test_samples.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/tests/test_transforms.py +0 -0
- {aspire_inference-0.1.0a7 → aspire_inference-0.1.0a9}/tests/test_utils.py +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aspire-inference
|
|
3
|
+
Version: 0.1.0a9
|
|
4
|
+
Summary: Accelerate Sequential Posterior Inference via REuse
|
|
5
|
+
Author-email: "Michael J. Williams" <michaeljw1@googlemail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mj-will/aspire
|
|
8
|
+
Project-URL: Documentation, https://aspire.readthedocs.io/
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: matplotlib
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Requires-Dist: array-api-compat
|
|
16
|
+
Requires-Dist: wrapt
|
|
17
|
+
Requires-Dist: h5py
|
|
18
|
+
Provides-Extra: scipy
|
|
19
|
+
Requires-Dist: scipy; extra == "scipy"
|
|
20
|
+
Provides-Extra: jax
|
|
21
|
+
Requires-Dist: jax; extra == "jax"
|
|
22
|
+
Requires-Dist: jaxlib; extra == "jax"
|
|
23
|
+
Requires-Dist: flowjax; extra == "jax"
|
|
24
|
+
Provides-Extra: torch
|
|
25
|
+
Requires-Dist: torch; extra == "torch"
|
|
26
|
+
Requires-Dist: zuko; extra == "torch"
|
|
27
|
+
Requires-Dist: tqdm; extra == "torch"
|
|
28
|
+
Provides-Extra: minipcn
|
|
29
|
+
Requires-Dist: minipcn; extra == "minipcn"
|
|
30
|
+
Provides-Extra: emcee
|
|
31
|
+
Requires-Dist: emcee; extra == "emcee"
|
|
32
|
+
Provides-Extra: blackjax
|
|
33
|
+
Requires-Dist: blackjax; extra == "blackjax"
|
|
34
|
+
Provides-Extra: test
|
|
35
|
+
Requires-Dist: pytest; extra == "test"
|
|
36
|
+
Requires-Dist: pytest-requires; extra == "test"
|
|
37
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
# aspire: Accelerated Sequential Posterior Inference via REuse
|
|
41
|
+
|
|
42
|
+
[](https://doi.org/10.5281/zenodo.15658747)
|
|
43
|
+
[](https://pypi.org/project/aspire-inference/)
|
|
44
|
+
[](https://aspire.readthedocs.io/en/latest/?badge=latest)
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
aspire is a framework for reusing existing posterior samples to obtain new results at a reduced cost.
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
aspire can be installed from PyPI using `pip`
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
pip install aspire-inference
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Important:** the name of `aspire` on PyPI is `aspire-inference` but once installed
|
|
59
|
+
the package can be imported and used as `aspire`.
|
|
60
|
+
|
|
61
|
+
## Quickstart
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import numpy as np
|
|
65
|
+
from aspire import Aspire, Samples
|
|
66
|
+
|
|
67
|
+
# Define a log-likelihood and log-prior
|
|
68
|
+
def log_likelihood(samples):
|
|
69
|
+
x = samples.x
|
|
70
|
+
return -0.5 * np.sum(x**2, axis=-1)
|
|
71
|
+
|
|
72
|
+
def log_prior(samples):
|
|
73
|
+
return -0.5 * np.sum(samples.x**2, axis=-1)
|
|
74
|
+
|
|
75
|
+
# Create the initial samples
|
|
76
|
+
init = Samples(np.random.normal(size=(2_000, 4)))
|
|
77
|
+
|
|
78
|
+
# Define the aspire object
|
|
79
|
+
aspire = Aspire(
|
|
80
|
+
log_likelihood=log_likelihood,
|
|
81
|
+
log_prior=log_prior,
|
|
82
|
+
dims=4,
|
|
83
|
+
parameters=[f"x{i}" for i in range(4)],
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# Fit the normalizing flow
|
|
87
|
+
aspire.fit(init, n_epochs=20)
|
|
88
|
+
|
|
89
|
+
# Sample the posterior
|
|
90
|
+
posterior = aspire.sample_posterior(
|
|
91
|
+
sampler="smc",
|
|
92
|
+
n_samples=500,
|
|
93
|
+
sampler_kwargs=dict(n_steps=100),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# Plot the posterior distribution
|
|
97
|
+
posterior.plot_corner()
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Documentation
|
|
101
|
+
|
|
102
|
+
See the [documentation on ReadTheDocs][docs].
|
|
103
|
+
|
|
104
|
+
## Citation
|
|
105
|
+
|
|
106
|
+
If you use `aspire` in your work please cite the [DOI][DOI] and [paper][paper].
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
[docs]: https://aspire.readthedocs.io/
|
|
110
|
+
[DOI]: https://doi.org/10.5281/zenodo.15658747
|
|
111
|
+
[paper]: https://arxiv.org/abs/2511.04218
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# aspire: Accelerated Sequential Posterior Inference via REuse
|
|
2
|
+
|
|
3
|
+
[](https://doi.org/10.5281/zenodo.15658747)
|
|
4
|
+
[](https://pypi.org/project/aspire-inference/)
|
|
5
|
+
[](https://aspire.readthedocs.io/en/latest/?badge=latest)
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
aspire is a framework for reusing existing posterior samples to obtain new results at a reduced cost.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
aspire can be installed from PyPI using `pip`
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
pip install aspire-inference
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Important:** the name of `aspire` on PyPI is `aspire-inference` but once installed
|
|
20
|
+
the package can be imported and used as `aspire`.
|
|
21
|
+
|
|
22
|
+
## Quickstart
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
import numpy as np
|
|
26
|
+
from aspire import Aspire, Samples
|
|
27
|
+
|
|
28
|
+
# Define a log-likelihood and log-prior
|
|
29
|
+
def log_likelihood(samples):
|
|
30
|
+
x = samples.x
|
|
31
|
+
return -0.5 * np.sum(x**2, axis=-1)
|
|
32
|
+
|
|
33
|
+
def log_prior(samples):
|
|
34
|
+
return -0.5 * np.sum(samples.x**2, axis=-1)
|
|
35
|
+
|
|
36
|
+
# Create the initial samples
|
|
37
|
+
init = Samples(np.random.normal(size=(2_000, 4)))
|
|
38
|
+
|
|
39
|
+
# Define the aspire object
|
|
40
|
+
aspire = Aspire(
|
|
41
|
+
log_likelihood=log_likelihood,
|
|
42
|
+
log_prior=log_prior,
|
|
43
|
+
dims=4,
|
|
44
|
+
parameters=[f"x{i}" for i in range(4)],
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# Fit the normalizing flow
|
|
48
|
+
aspire.fit(init, n_epochs=20)
|
|
49
|
+
|
|
50
|
+
# Sample the posterior
|
|
51
|
+
posterior = aspire.sample_posterior(
|
|
52
|
+
sampler="smc",
|
|
53
|
+
n_samples=500,
|
|
54
|
+
sampler_kwargs=dict(n_steps=100),
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
# Plot the posterior distribution
|
|
58
|
+
posterior.plot_corner()
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Documentation
|
|
62
|
+
|
|
63
|
+
See the [documentation on ReadTheDocs][docs].
|
|
64
|
+
|
|
65
|
+
## Citation
|
|
66
|
+
|
|
67
|
+
If you use `aspire` in your work please cite the [DOI][DOI] and [paper][paper].
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
[docs]: https://aspire.readthedocs.io/
|
|
71
|
+
[DOI]: https://doi.org/10.5281/zenodo.15658747
|
|
72
|
+
[paper]: https://arxiv.org/abs/2511.04218
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aspire-inference
|
|
3
|
+
Version: 0.1.0a9
|
|
4
|
+
Summary: Accelerate Sequential Posterior Inference via REuse
|
|
5
|
+
Author-email: "Michael J. Williams" <michaeljw1@googlemail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mj-will/aspire
|
|
8
|
+
Project-URL: Documentation, https://aspire.readthedocs.io/
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: matplotlib
|
|
14
|
+
Requires-Dist: numpy
|
|
15
|
+
Requires-Dist: array-api-compat
|
|
16
|
+
Requires-Dist: wrapt
|
|
17
|
+
Requires-Dist: h5py
|
|
18
|
+
Provides-Extra: scipy
|
|
19
|
+
Requires-Dist: scipy; extra == "scipy"
|
|
20
|
+
Provides-Extra: jax
|
|
21
|
+
Requires-Dist: jax; extra == "jax"
|
|
22
|
+
Requires-Dist: jaxlib; extra == "jax"
|
|
23
|
+
Requires-Dist: flowjax; extra == "jax"
|
|
24
|
+
Provides-Extra: torch
|
|
25
|
+
Requires-Dist: torch; extra == "torch"
|
|
26
|
+
Requires-Dist: zuko; extra == "torch"
|
|
27
|
+
Requires-Dist: tqdm; extra == "torch"
|
|
28
|
+
Provides-Extra: minipcn
|
|
29
|
+
Requires-Dist: minipcn; extra == "minipcn"
|
|
30
|
+
Provides-Extra: emcee
|
|
31
|
+
Requires-Dist: emcee; extra == "emcee"
|
|
32
|
+
Provides-Extra: blackjax
|
|
33
|
+
Requires-Dist: blackjax; extra == "blackjax"
|
|
34
|
+
Provides-Extra: test
|
|
35
|
+
Requires-Dist: pytest; extra == "test"
|
|
36
|
+
Requires-Dist: pytest-requires; extra == "test"
|
|
37
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
# aspire: Accelerated Sequential Posterior Inference via REuse
|
|
41
|
+
|
|
42
|
+
[](https://doi.org/10.5281/zenodo.15658747)
|
|
43
|
+
[](https://pypi.org/project/aspire-inference/)
|
|
44
|
+
[](https://aspire.readthedocs.io/en/latest/?badge=latest)
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
aspire is a framework for reusing existing posterior samples to obtain new results at a reduced cost.
|
|
49
|
+
|
|
50
|
+
## Installation
|
|
51
|
+
|
|
52
|
+
aspire can be installed from PyPI using `pip`
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
pip install aspire-inference
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Important:** the name of `aspire` on PyPI is `aspire-inference` but once installed
|
|
59
|
+
the package can be imported and used as `aspire`.
|
|
60
|
+
|
|
61
|
+
## Quickstart
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import numpy as np
|
|
65
|
+
from aspire import Aspire, Samples
|
|
66
|
+
|
|
67
|
+
# Define a log-likelihood and log-prior
|
|
68
|
+
def log_likelihood(samples):
|
|
69
|
+
x = samples.x
|
|
70
|
+
return -0.5 * np.sum(x**2, axis=-1)
|
|
71
|
+
|
|
72
|
+
def log_prior(samples):
|
|
73
|
+
return -0.5 * np.sum(samples.x**2, axis=-1)
|
|
74
|
+
|
|
75
|
+
# Create the initial samples
|
|
76
|
+
init = Samples(np.random.normal(size=(2_000, 4)))
|
|
77
|
+
|
|
78
|
+
# Define the aspire object
|
|
79
|
+
aspire = Aspire(
|
|
80
|
+
log_likelihood=log_likelihood,
|
|
81
|
+
log_prior=log_prior,
|
|
82
|
+
dims=4,
|
|
83
|
+
parameters=[f"x{i}" for i in range(4)],
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# Fit the normalizing flow
|
|
87
|
+
aspire.fit(init, n_epochs=20)
|
|
88
|
+
|
|
89
|
+
# Sample the posterior
|
|
90
|
+
posterior = aspire.sample_posterior(
|
|
91
|
+
sampler="smc",
|
|
92
|
+
n_samples=500,
|
|
93
|
+
sampler_kwargs=dict(n_steps=100),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# Plot the posterior distribution
|
|
97
|
+
posterior.plot_corner()
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Documentation
|
|
101
|
+
|
|
102
|
+
See the [documentation on ReadTheDocs][docs].
|
|
103
|
+
|
|
104
|
+
## Citation
|
|
105
|
+
|
|
106
|
+
If you use `aspire` in your work please cite the [DOI][DOI] and [paper][paper].
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
[docs]: https://aspire.readthedocs.io/
|
|
110
|
+
[DOI]: https://doi.org/10.5281/zenodo.15658747
|
|
111
|
+
[paper]: https://arxiv.org/abs/2511.04218
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
LICENSE
|
|
4
4
|
README.md
|
|
5
5
|
pyproject.toml
|
|
6
|
+
readthedocs.yml
|
|
6
7
|
.github/workflows/lint.yml
|
|
7
8
|
.github/workflows/publish.yml
|
|
8
9
|
.github/workflows/tests.yml
|
|
@@ -11,7 +12,18 @@ aspire_inference.egg-info/SOURCES.txt
|
|
|
11
12
|
aspire_inference.egg-info/dependency_links.txt
|
|
12
13
|
aspire_inference.egg-info/requires.txt
|
|
13
14
|
aspire_inference.egg-info/top_level.txt
|
|
15
|
+
docs/Makefile
|
|
16
|
+
docs/conf.py
|
|
17
|
+
docs/entry_points.rst
|
|
18
|
+
docs/examples.rst
|
|
19
|
+
docs/index.rst
|
|
20
|
+
docs/installation.rst
|
|
21
|
+
docs/multiprocessing.rst
|
|
22
|
+
docs/recipes.rst
|
|
23
|
+
docs/requirements.txt
|
|
24
|
+
docs/user_guide.rst
|
|
14
25
|
examples/basic_example.py
|
|
26
|
+
examples/blackjax_smc_example.py
|
|
15
27
|
examples/smc_example.py
|
|
16
28
|
src/aspire/__init__.py
|
|
17
29
|
src/aspire/aspire.py
|
|
@@ -42,5 +54,6 @@ tests/test_transforms.py
|
|
|
42
54
|
tests/test_utils.py
|
|
43
55
|
tests/integration_tests/conftest.py
|
|
44
56
|
tests/integration_tests/test_integration.py
|
|
57
|
+
tests/test_flows/test_flows_core.py
|
|
45
58
|
tests/test_flows/test_jax_flows/test_flowjax_flows.py
|
|
46
59
|
tests/test_flows/test_torch_flows/test_zuko_flows.py
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Minimal makefile for Sphinx documentation
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
# You can set these variables from the command line, and also
|
|
5
|
+
# from the environment for the first two.
|
|
6
|
+
SPHINXOPTS ?=
|
|
7
|
+
SPHINXBUILD ?= sphinx-build
|
|
8
|
+
SOURCEDIR = .
|
|
9
|
+
BUILDDIR = _build
|
|
10
|
+
|
|
11
|
+
# Put it first so that "make" without argument is like "make help".
|
|
12
|
+
help:
|
|
13
|
+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
14
|
+
|
|
15
|
+
.PHONY: help Makefile
|
|
16
|
+
|
|
17
|
+
# Catch-all target: route all unknown targets to Sphinx using the new
|
|
18
|
+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
|
19
|
+
%: Makefile
|
|
20
|
+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Sphinx configuration for the aspire documentation."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
# Ensure the package can be imported when building the docs locally
|
|
9
|
+
ROOT = os.path.abspath("..")
|
|
10
|
+
if ROOT not in sys.path:
|
|
11
|
+
sys.path.insert(0, ROOT)
|
|
12
|
+
|
|
13
|
+
import aspire # noqa: E402
|
|
14
|
+
|
|
15
|
+
# -- Project information -----------------------------------------------------
|
|
16
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
|
17
|
+
|
|
18
|
+
project = "aspire"
|
|
19
|
+
copyright = "2025, Michael J. Williams"
|
|
20
|
+
author = "Michael J. Williams"
|
|
21
|
+
version = aspire.__version__
|
|
22
|
+
release = aspire.__version__
|
|
23
|
+
|
|
24
|
+
# -- General configuration ---------------------------------------------------
|
|
25
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
26
|
+
|
|
27
|
+
extensions = [
|
|
28
|
+
"sphinx.ext.autodoc",
|
|
29
|
+
"sphinx.ext.autosummary",
|
|
30
|
+
"sphinx.ext.napoleon",
|
|
31
|
+
"sphinx.ext.viewcode",
|
|
32
|
+
"autoapi.extension",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
autodoc_typehints = "description"
|
|
36
|
+
autodoc_member_order = "bysource"
|
|
37
|
+
autosummary_generate = True
|
|
38
|
+
napoleon_google_docstring = False
|
|
39
|
+
napoleon_numpy_docstring = True
|
|
40
|
+
napoleon_preprocess_types = True
|
|
41
|
+
|
|
42
|
+
templates_path = ["_templates"]
|
|
43
|
+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
|
|
44
|
+
|
|
45
|
+
# -- Configure autoapi -------------------------------------------------------
|
|
46
|
+
|
|
47
|
+
autoapi_type = "python"
|
|
48
|
+
autoapi_dirs = ["../src/aspire/"]
|
|
49
|
+
autoapi_add_toctree_entry = True
|
|
50
|
+
autoapi_options = [
|
|
51
|
+
"members",
|
|
52
|
+
"imported-members",
|
|
53
|
+
"show-inheritance",
|
|
54
|
+
"show-module-summary",
|
|
55
|
+
"undoc-members",
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
# -- Options for HTML output -------------------------------------------------
|
|
59
|
+
|
|
60
|
+
html_theme = "sphinx_book_theme"
|
|
61
|
+
html_static_path = ["_static"]
|
|
62
|
+
html_title = "aspire"
|
|
63
|
+
html_theme_options = {
|
|
64
|
+
"path_to_docs": "docs",
|
|
65
|
+
"repository_url": "https://github.com/mj-will/aspire",
|
|
66
|
+
"repository_branch": "main",
|
|
67
|
+
"use_edit_page_button": True,
|
|
68
|
+
"use_issues_button": True,
|
|
69
|
+
"use_repository_button": True,
|
|
70
|
+
"use_download_button": True,
|
|
71
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Entry Points
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
Aspire uses Python's entry point system to allow for extensibility and
|
|
5
|
+
integration with external libraries. This mechanism enables users to register
|
|
6
|
+
custom components that can be seamlessly integrated into the Aspire framework.
|
|
7
|
+
|
|
8
|
+
.. _custom_flows:
|
|
9
|
+
|
|
10
|
+
Custom Flows
|
|
11
|
+
------------
|
|
12
|
+
|
|
13
|
+
Aspire supports custom flow implementations via the
|
|
14
|
+
``aspire.flows`` entry point group. To register a new flow backend, define an
|
|
15
|
+
entry point in your ``pyproject.toml`` like so:
|
|
16
|
+
|
|
17
|
+
.. code-block:: toml
|
|
18
|
+
|
|
19
|
+
[project.entry-points."aspire.flows"]
|
|
20
|
+
myflow = "my_module:MyFlowClass"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
The specified class must inherit from :class:`aspire.flows.base.Flow` (or one
|
|
24
|
+
of the existing flow wrappers), implement the required methods and define the
|
|
25
|
+
``xp`` attribute which specifies the array namespace.
|
|
26
|
+
You can then select your custom flow by setting
|
|
27
|
+
``flow_backend="myflow"`` when initializing Aspire.
|
|
28
|
+
|
|
29
|
+
For an example see ``GWFlow`` in ``aspire-gw`` (https://github.com/mj-will/aspire-gw).
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Examples
|
|
2
|
+
========
|
|
3
|
+
|
|
4
|
+
The repository ships with runnable scripts that demonstrate typical Aspire
|
|
5
|
+
workflows. Execute them from the examples directory after installing the relevant
|
|
6
|
+
extras.
|
|
7
|
+
|
|
8
|
+
Sequential Monte Carlo (MiniPCN)
|
|
9
|
+
--------------------------------
|
|
10
|
+
|
|
11
|
+
.. literalinclude:: ../examples/smc_example.py
|
|
12
|
+
:language: python
|
|
13
|
+
:linenos:
|
|
14
|
+
:lines: 1-80
|
|
15
|
+
:caption: ``examples/smc_example.py`` (excerpt)
|
|
16
|
+
|
|
17
|
+
Run the full example:
|
|
18
|
+
|
|
19
|
+
.. code-block:: console
|
|
20
|
+
|
|
21
|
+
$ python smc_example.py
|
|
22
|
+
|
|
23
|
+
The script demonstrates how to:
|
|
24
|
+
|
|
25
|
+
- Build contrived mixtures of Gaussians for testing,
|
|
26
|
+
- Fit a Neural Spline Flow to biased initial samples,
|
|
27
|
+
- Run adaptive MiniPCN-SMC via :meth:`aspire.Aspire.sample_posterior`,
|
|
28
|
+
- Plot diagnostics (loss curves, beta schedule, corner plots).
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
aspire: Accelerated Sequential Posterior Inference via REuse
|
|
2
|
+
============================================================
|
|
3
|
+
|
|
4
|
+
``aspire`` is a lightweight framework for reusing existing posterior samples
|
|
5
|
+
and normalizing flows to accelerate Bayesian inference. It focuses on
|
|
6
|
+
practical workflows: fit a flow, adaptively run Sequential Monte Carlo (SMC),
|
|
7
|
+
MCMC or importance samplers, and visualise or export the resulting samples.
|
|
8
|
+
|
|
9
|
+
Key capabilities
|
|
10
|
+
----------------
|
|
11
|
+
|
|
12
|
+
- Fit flow-based proposals (PyTorch or JAX backends) with automatic handling of
|
|
13
|
+
bounded and periodic parameters.
|
|
14
|
+
- Run adaptive SMC (MiniPCN or BlackJAX kernels) and importance sampling with
|
|
15
|
+
detailed diagnostic histories.
|
|
16
|
+
- Inspect results via convenience helpers for evidence estimates, corner plots,
|
|
17
|
+
and HDF5/JSON export.
|
|
18
|
+
|
|
19
|
+
Quick start
|
|
20
|
+
-----------
|
|
21
|
+
|
|
22
|
+
.. code-block:: python
|
|
23
|
+
|
|
24
|
+
import numpy as np
|
|
25
|
+
from aspire import Aspire, Samples
|
|
26
|
+
|
|
27
|
+
def log_likelihood(samples):
|
|
28
|
+
x = samples.x
|
|
29
|
+
return -0.5 * np.sum(x**2, axis=-1)
|
|
30
|
+
|
|
31
|
+
def log_prior(samples):
|
|
32
|
+
return -0.5 * np.sum(samples.x**2, axis=-1)
|
|
33
|
+
|
|
34
|
+
init = Samples(np.random.normal(size=(2_000, 4)))
|
|
35
|
+
|
|
36
|
+
aspire = Aspire(
|
|
37
|
+
log_likelihood=log_likelihood,
|
|
38
|
+
log_prior=log_prior,
|
|
39
|
+
dims=4,
|
|
40
|
+
parameters=[f"x{i}" for i in range(4)],
|
|
41
|
+
)
|
|
42
|
+
aspire.fit(init, n_epochs=20)
|
|
43
|
+
posterior = aspire.sample_posterior(
|
|
44
|
+
sampler="smc",
|
|
45
|
+
n_samples=500,
|
|
46
|
+
sampler_kwargs=dict(n_steps=100),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
posterior.plot_corner()
|
|
50
|
+
|
|
51
|
+
Use the sections below for environment setup, conceptual guidance, runnable
|
|
52
|
+
examples, and the complete API reference.
|
|
53
|
+
|
|
54
|
+
.. toctree::
|
|
55
|
+
:maxdepth: 2
|
|
56
|
+
:caption: Contents
|
|
57
|
+
|
|
58
|
+
installation
|
|
59
|
+
user_guide
|
|
60
|
+
recipes
|
|
61
|
+
multiprocessing
|
|
62
|
+
examples
|
|
63
|
+
entry_points
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Installation
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
``aspire`` targets Python 3.10+ and relies on ``numpy``, ``matplotlib``,
|
|
5
|
+
``array-api-compat`` and ``h5py`` for core functionality. Optional extras
|
|
6
|
+
provide tighter integration with popular samplers and flow backends.
|
|
7
|
+
|
|
8
|
+
Basic setup
|
|
9
|
+
-----------
|
|
10
|
+
|
|
11
|
+
Install the library from PyPI (note the published name):
|
|
12
|
+
|
|
13
|
+
.. code-block:: console
|
|
14
|
+
|
|
15
|
+
$ python -m pip install aspire-inference
|
|
16
|
+
|
|
17
|
+
The installed distribution exposes the ``aspire`` import namespace.
|
|
18
|
+
|
|
19
|
+
Optional extras
|
|
20
|
+
---------------
|
|
21
|
+
|
|
22
|
+
Additional features can be enabled by installing the relevant extras:
|
|
23
|
+
|
|
24
|
+
.. list-table::
|
|
25
|
+
:header-rows: 1
|
|
26
|
+
:widths: 20 70
|
|
27
|
+
|
|
28
|
+
* - Extra
|
|
29
|
+
- Purpose
|
|
30
|
+
* - ``scipy``
|
|
31
|
+
- Access to SciPy utilities used by certain transforms.
|
|
32
|
+
* - ``jax``
|
|
33
|
+
- JAX + ``flowjax`` backend for training normalizing flows.
|
|
34
|
+
* - ``torch``
|
|
35
|
+
- PyTorch + ``zuko`` backend (default) for normalizing flows and flow matching.
|
|
36
|
+
* - ``minipcn``
|
|
37
|
+
- Enables the MiniPCN SMC kernel.
|
|
38
|
+
* - ``emcee``
|
|
39
|
+
- Enables the ``emcee`` ensemble sampler integration.
|
|
40
|
+
* - ``blackjax``
|
|
41
|
+
- Enables the BlackJAX SMC kernel.
|
|
42
|
+
* - ``test``
|
|
43
|
+
- Installs ``pytest`` and coverage helpers for local testing.
|
|
44
|
+
|
|
45
|
+
Install extras via:
|
|
46
|
+
|
|
47
|
+
.. code-block:: console
|
|
48
|
+
|
|
49
|
+
$ python -m pip install "aspire-inference[torch,minipcn]"
|
|
50
|
+
|
|
51
|
+
From source
|
|
52
|
+
-----------
|
|
53
|
+
|
|
54
|
+
Clone the repository and install in editable mode:
|
|
55
|
+
|
|
56
|
+
.. code-block:: console
|
|
57
|
+
|
|
58
|
+
$ git clone https://github.com/mj-will/aspire.git
|
|
59
|
+
$ cd aspire
|
|
60
|
+
# (optional) create/activate a virtual environment
|
|
61
|
+
$ python -m pip install -e ".[torch,minipcn]"
|
|
62
|
+
|
|
63
|
+
After installation, run the unit test suite to confirm everything is wired up:
|
|
64
|
+
|
|
65
|
+
.. code-block:: console
|
|
66
|
+
|
|
67
|
+
$ python -m pytest
|
|
68
|
+
|
|
69
|
+
Building the docs locally requires ``sphinx`` and (optionally) the
|
|
70
|
+
``sphinx-``. These are installed automatically when you run
|
|
71
|
+
``python -m pip install -r docs/requirements.txt`` if such a file exists, or
|
|
72
|
+
you can install ``sphinx`` manually before invoking ``make html`` inside the
|
|
73
|
+
``docs`` directory.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Multiprocessing
|
|
2
|
+
===============
|
|
3
|
+
|
|
4
|
+
Use :meth:`aspire.Aspire.enable_pool` to run your likelihood (and optionally
|
|
5
|
+
prior) in parallel across a :class:`multiprocessing.Pool`. The helper swaps the
|
|
6
|
+
``map_fn`` argument expected by your log-likelihood / log-prior for
|
|
7
|
+
``pool.map`` while the context is active, then restores the original methods.
|
|
8
|
+
|
|
9
|
+
Prepare a map-aware likelihood
|
|
10
|
+
------------------------------
|
|
11
|
+
|
|
12
|
+
Your likelihood must accept ``map_fn``. A minimal
|
|
13
|
+
pattern:
|
|
14
|
+
|
|
15
|
+
.. code-block:: python
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _global_log_likelihood(x):
|
|
21
|
+
# Expensive likelihood computation for a single sample `x`
|
|
22
|
+
return -np.sum(x**2) # Example likelihood
|
|
23
|
+
|
|
24
|
+
def log_likelihood(samples, map_fn=map):
|
|
25
|
+
logl = -np.inf * np.ones(len(samples.x))
|
|
26
|
+
if samples.log_prior is None:
|
|
27
|
+
raise RuntimeError("log-prior has not been evaluated!")
|
|
28
|
+
mask = np.isfinite(samples.log_prior, dtype=bool)
|
|
29
|
+
x = np.asarray(samples.x[mask, :], dtype=float)
|
|
30
|
+
logl[mask] = np.fromiter(
|
|
31
|
+
map_fn(_global_log_likelihood, x),
|
|
32
|
+
dtype=float,
|
|
33
|
+
)
|
|
34
|
+
return logl
|
|
35
|
+
|
|
36
|
+
Swap in a multiprocessing pool
|
|
37
|
+
------------------------------
|
|
38
|
+
|
|
39
|
+
Wrap your sampling call inside ``enable_pool`` to parallelize the map step:
|
|
40
|
+
|
|
41
|
+
.. code-block:: python
|
|
42
|
+
|
|
43
|
+
import multiprocessing as mp
|
|
44
|
+
from aspire import Aspire
|
|
45
|
+
|
|
46
|
+
aspire = Aspire(
|
|
47
|
+
log_likelihood=log_likelihood,
|
|
48
|
+
log_prior=log_prior, # must also accept map_fn if parallelize_prior=True
|
|
49
|
+
dims=4,
|
|
50
|
+
parameters=["a", "b", "c", "d"],
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
with mp.Pool() as pool, aspire.enable_pool(pool):
|
|
54
|
+
samples, history = aspire.sample_posterior(
|
|
55
|
+
sampler="smc",
|
|
56
|
+
n_samples=1_000,
|
|
57
|
+
return_history=True,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
Notes
|
|
61
|
+
-----
|
|
62
|
+
|
|
63
|
+
- By default only the likelihood is parallelized; set
|
|
64
|
+
``aspire.enable_pool(pool, parallelize_prior=True)`` if your prior also
|
|
65
|
+
accepts ``map_fn``.
|
|
66
|
+
- ``enable_pool`` closes the pool on exit unless you pass ``close_pool=False``.
|
|
67
|
+
- The context manager itself is implemented by
|
|
68
|
+
:class:`aspire.utils.PoolHandler`; if you need finer control (for example,
|
|
69
|
+
reusing the same pool across multiple ``Aspire`` instances) you can
|
|
70
|
+
instantiate it directly.
|