aspire-inference 0.1.0a2__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.0a2/.github/workflows/lint.yml +21 -0
- aspire_inference-0.1.0a2/.github/workflows/publish.yml +47 -0
- aspire_inference-0.1.0a2/.github/workflows/tests.yml +38 -0
- aspire_inference-0.1.0a2/.gitignore +165 -0
- aspire_inference-0.1.0a2/.pre-commit-config.yaml +23 -0
- aspire_inference-0.1.0a2/LICENSE +21 -0
- aspire_inference-0.1.0a2/PKG-INFO +48 -0
- aspire_inference-0.1.0a2/README.md +14 -0
- aspire_inference-0.1.0a2/aspire_inference.egg-info/PKG-INFO +48 -0
- aspire_inference-0.1.0a2/aspire_inference.egg-info/SOURCES.txt +42 -0
- aspire_inference-0.1.0a2/aspire_inference.egg-info/dependency_links.txt +1 -0
- aspire_inference-0.1.0a2/aspire_inference.egg-info/requires.txt +27 -0
- aspire_inference-0.1.0a2/aspire_inference.egg-info/top_level.txt +1 -0
- aspire_inference-0.1.0a2/examples/basic_example.py +87 -0
- aspire_inference-0.1.0a2/pyproject.toml +67 -0
- aspire_inference-0.1.0a2/setup.cfg +4 -0
- aspire_inference-0.1.0a2/src/aspire/__init__.py +19 -0
- aspire_inference-0.1.0a2/src/aspire/aspire.py +457 -0
- aspire_inference-0.1.0a2/src/aspire/flows/__init__.py +40 -0
- aspire_inference-0.1.0a2/src/aspire/flows/base.py +37 -0
- aspire_inference-0.1.0a2/src/aspire/flows/jax/__init__.py +3 -0
- aspire_inference-0.1.0a2/src/aspire/flows/jax/flows.py +82 -0
- aspire_inference-0.1.0a2/src/aspire/flows/jax/utils.py +54 -0
- aspire_inference-0.1.0a2/src/aspire/flows/torch/__init__.py +0 -0
- aspire_inference-0.1.0a2/src/aspire/flows/torch/flows.py +276 -0
- aspire_inference-0.1.0a2/src/aspire/history.py +148 -0
- aspire_inference-0.1.0a2/src/aspire/plot.py +50 -0
- aspire_inference-0.1.0a2/src/aspire/samplers/__init__.py +0 -0
- aspire_inference-0.1.0a2/src/aspire/samplers/base.py +92 -0
- aspire_inference-0.1.0a2/src/aspire/samplers/importance.py +18 -0
- aspire_inference-0.1.0a2/src/aspire/samplers/mcmc.py +158 -0
- aspire_inference-0.1.0a2/src/aspire/samplers/smc/__init__.py +0 -0
- aspire_inference-0.1.0a2/src/aspire/samplers/smc/base.py +312 -0
- aspire_inference-0.1.0a2/src/aspire/samplers/smc/blackjax.py +330 -0
- aspire_inference-0.1.0a2/src/aspire/samplers/smc/emcee.py +75 -0
- aspire_inference-0.1.0a2/src/aspire/samplers/smc/minipcn.py +82 -0
- aspire_inference-0.1.0a2/src/aspire/samples.py +476 -0
- aspire_inference-0.1.0a2/src/aspire/transforms.py +491 -0
- aspire_inference-0.1.0a2/src/aspire/utils.py +491 -0
- aspire_inference-0.1.0a2/tests/conftest.py +7 -0
- aspire_inference-0.1.0a2/tests/integration_tests/conftest.py +172 -0
- aspire_inference-0.1.0a2/tests/integration_tests/test_integration.py +69 -0
- aspire_inference-0.1.0a2/tests/test_flows/test_jax_flows/test_flowjax_flows.py +42 -0
- aspire_inference-0.1.0a2/tests/test_flows/test_torch_flows/test_zuko_flows.py +38 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: Lint
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main, release* ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main, release* ]
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
ruff:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: astral-sh/ruff-action@v3
|
|
19
|
+
with:
|
|
20
|
+
version: "0.11.x"
|
|
21
|
+
args: 'format --check'
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: Publish Python distribution to PyPI
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
build:
|
|
8
|
+
name: Build distribution
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- name: Set up Python
|
|
14
|
+
uses: actions/setup-python@v5
|
|
15
|
+
with:
|
|
16
|
+
python-version: "3.x"
|
|
17
|
+
- name: Install pypa/build
|
|
18
|
+
run: >-
|
|
19
|
+
python3 -m
|
|
20
|
+
pip install
|
|
21
|
+
build
|
|
22
|
+
--user
|
|
23
|
+
- name: Build a binary wheel and a source tarball
|
|
24
|
+
run: python3 -m build
|
|
25
|
+
- name: Store the distribution packages
|
|
26
|
+
uses: actions/upload-artifact@v4
|
|
27
|
+
with:
|
|
28
|
+
name: python-package-distributions
|
|
29
|
+
path: dist/
|
|
30
|
+
|
|
31
|
+
pypi-publish:
|
|
32
|
+
name: Upload release to PyPI
|
|
33
|
+
needs:
|
|
34
|
+
- build
|
|
35
|
+
runs-on: ubuntu-latest
|
|
36
|
+
environment: release
|
|
37
|
+
permissions:
|
|
38
|
+
id-token: write
|
|
39
|
+
steps:
|
|
40
|
+
- name: Download all the dists
|
|
41
|
+
uses: actions/download-artifact@v4
|
|
42
|
+
with:
|
|
43
|
+
name: python-package-distributions
|
|
44
|
+
path: dist/
|
|
45
|
+
|
|
46
|
+
- name: Publish package distributions to PyPI
|
|
47
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main, release* ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ main, release* ]
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
tests:
|
|
15
|
+
name: Python ${{ matrix.python-version }} (${{ matrix.os }})
|
|
16
|
+
|
|
17
|
+
strategy:
|
|
18
|
+
fail-fast: false
|
|
19
|
+
matrix:
|
|
20
|
+
os: [Ubuntu]
|
|
21
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
22
|
+
runs-on: ${{ matrix.os }}-latest
|
|
23
|
+
|
|
24
|
+
steps:
|
|
25
|
+
- name: Checkout repository and submodules
|
|
26
|
+
uses: actions/checkout@v4
|
|
27
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
28
|
+
uses: actions/setup-python@v4
|
|
29
|
+
with:
|
|
30
|
+
python-version: ${{ matrix.python-version }}
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: |
|
|
33
|
+
python -m pip install --upgrade pip
|
|
34
|
+
pip install torch --index-url https://download.pytorch.org/whl/cpu
|
|
35
|
+
pip install -e .[test,torch,jax,minipcn,emcee,blackjax]
|
|
36
|
+
- name: Test with pytest
|
|
37
|
+
run: |
|
|
38
|
+
python -m pytest
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# poetry
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
102
|
+
#poetry.lock
|
|
103
|
+
|
|
104
|
+
# pdm
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
106
|
+
#pdm.lock
|
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
108
|
+
# in version control.
|
|
109
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
110
|
+
.pdm.toml
|
|
111
|
+
.pdm-python
|
|
112
|
+
.pdm-build/
|
|
113
|
+
|
|
114
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
115
|
+
__pypackages__/
|
|
116
|
+
|
|
117
|
+
# Celery stuff
|
|
118
|
+
celerybeat-schedule
|
|
119
|
+
celerybeat.pid
|
|
120
|
+
|
|
121
|
+
# SageMath parsed files
|
|
122
|
+
*.sage.py
|
|
123
|
+
|
|
124
|
+
# Environments
|
|
125
|
+
.env
|
|
126
|
+
.venv
|
|
127
|
+
env/
|
|
128
|
+
venv/
|
|
129
|
+
ENV/
|
|
130
|
+
env.bak/
|
|
131
|
+
venv.bak/
|
|
132
|
+
|
|
133
|
+
# Spyder project settings
|
|
134
|
+
.spyderproject
|
|
135
|
+
.spyproject
|
|
136
|
+
|
|
137
|
+
# Rope project settings
|
|
138
|
+
.ropeproject
|
|
139
|
+
|
|
140
|
+
# mkdocs documentation
|
|
141
|
+
/site
|
|
142
|
+
|
|
143
|
+
# mypy
|
|
144
|
+
.mypy_cache/
|
|
145
|
+
.dmypy.json
|
|
146
|
+
dmypy.json
|
|
147
|
+
|
|
148
|
+
# Pyre type checker
|
|
149
|
+
.pyre/
|
|
150
|
+
|
|
151
|
+
# pytype static type analyzer
|
|
152
|
+
.pytype/
|
|
153
|
+
|
|
154
|
+
# Cython debug symbols
|
|
155
|
+
cython_debug/
|
|
156
|
+
|
|
157
|
+
# PyCharm
|
|
158
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
159
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
160
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
161
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
162
|
+
#.idea/
|
|
163
|
+
|
|
164
|
+
# Project-specific
|
|
165
|
+
outdir/
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
+
rev: v2.4.0
|
|
4
|
+
hooks:
|
|
5
|
+
- id: trailing-whitespace
|
|
6
|
+
- id: end-of-file-fixer
|
|
7
|
+
- id: check-yaml
|
|
8
|
+
- id: check-added-large-files
|
|
9
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
10
|
+
# Ruff version.
|
|
11
|
+
rev: v0.11.8
|
|
12
|
+
hooks:
|
|
13
|
+
# Run the linter.
|
|
14
|
+
- id: ruff
|
|
15
|
+
args: [ --fix ]
|
|
16
|
+
# Run the formatter.
|
|
17
|
+
- id: ruff-format
|
|
18
|
+
- repo: https://github.com/codespell-project/codespell
|
|
19
|
+
rev: v2.2.4
|
|
20
|
+
hooks:
|
|
21
|
+
- id: codespell
|
|
22
|
+
additional_dependencies:
|
|
23
|
+
- tomli
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Michael J. Williams
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aspire-inference
|
|
3
|
+
Version: 0.1.0a2
|
|
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
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: matplotlib
|
|
13
|
+
Requires-Dist: numpy
|
|
14
|
+
Requires-Dist: array-api-compat
|
|
15
|
+
Requires-Dist: wrapt
|
|
16
|
+
Requires-Dist: h5py
|
|
17
|
+
Provides-Extra: jax
|
|
18
|
+
Requires-Dist: jax; extra == "jax"
|
|
19
|
+
Requires-Dist: jaxlib; extra == "jax"
|
|
20
|
+
Requires-Dist: flowjax; extra == "jax"
|
|
21
|
+
Provides-Extra: torch
|
|
22
|
+
Requires-Dist: torch; extra == "torch"
|
|
23
|
+
Requires-Dist: zuko; extra == "torch"
|
|
24
|
+
Provides-Extra: minipcn
|
|
25
|
+
Requires-Dist: minipcn; extra == "minipcn"
|
|
26
|
+
Provides-Extra: emcee
|
|
27
|
+
Requires-Dist: emcee; extra == "emcee"
|
|
28
|
+
Provides-Extra: blackjax
|
|
29
|
+
Requires-Dist: blackjax; extra == "blackjax"
|
|
30
|
+
Provides-Extra: test
|
|
31
|
+
Requires-Dist: pytest; extra == "test"
|
|
32
|
+
Requires-Dist: pytest-requires; extra == "test"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# aspire: Accelerated Sequential Posterior Inference via REuse
|
|
36
|
+
|
|
37
|
+
aspire is a framework for reusing existing posterior samples to obtain new results at a reduced code.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
aspire can be installed from PyPI using `pip`
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
pip install aspire-inference
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Important:** the name of `aspire` on PyPI is `aspire-inference` but once installed
|
|
48
|
+
the package can be imported and used as `aspire`.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# aspire: Accelerated Sequential Posterior Inference via REuse
|
|
2
|
+
|
|
3
|
+
aspire is a framework for reusing existing posterior samples to obtain new results at a reduced code.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
aspire can be installed from PyPI using `pip`
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
pip install aspire-inference
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Important:** the name of `aspire` on PyPI is `aspire-inference` but once installed
|
|
14
|
+
the package can be imported and used as `aspire`.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aspire-inference
|
|
3
|
+
Version: 0.1.0a2
|
|
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
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: matplotlib
|
|
13
|
+
Requires-Dist: numpy
|
|
14
|
+
Requires-Dist: array-api-compat
|
|
15
|
+
Requires-Dist: wrapt
|
|
16
|
+
Requires-Dist: h5py
|
|
17
|
+
Provides-Extra: jax
|
|
18
|
+
Requires-Dist: jax; extra == "jax"
|
|
19
|
+
Requires-Dist: jaxlib; extra == "jax"
|
|
20
|
+
Requires-Dist: flowjax; extra == "jax"
|
|
21
|
+
Provides-Extra: torch
|
|
22
|
+
Requires-Dist: torch; extra == "torch"
|
|
23
|
+
Requires-Dist: zuko; extra == "torch"
|
|
24
|
+
Provides-Extra: minipcn
|
|
25
|
+
Requires-Dist: minipcn; extra == "minipcn"
|
|
26
|
+
Provides-Extra: emcee
|
|
27
|
+
Requires-Dist: emcee; extra == "emcee"
|
|
28
|
+
Provides-Extra: blackjax
|
|
29
|
+
Requires-Dist: blackjax; extra == "blackjax"
|
|
30
|
+
Provides-Extra: test
|
|
31
|
+
Requires-Dist: pytest; extra == "test"
|
|
32
|
+
Requires-Dist: pytest-requires; extra == "test"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# aspire: Accelerated Sequential Posterior Inference via REuse
|
|
36
|
+
|
|
37
|
+
aspire is a framework for reusing existing posterior samples to obtain new results at a reduced code.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
aspire can be installed from PyPI using `pip`
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
pip install aspire-inference
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Important:** the name of `aspire` on PyPI is `aspire-inference` but once installed
|
|
48
|
+
the package can be imported and used as `aspire`.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
.gitignore
|
|
2
|
+
.pre-commit-config.yaml
|
|
3
|
+
LICENSE
|
|
4
|
+
README.md
|
|
5
|
+
pyproject.toml
|
|
6
|
+
.github/workflows/lint.yml
|
|
7
|
+
.github/workflows/publish.yml
|
|
8
|
+
.github/workflows/tests.yml
|
|
9
|
+
aspire_inference.egg-info/PKG-INFO
|
|
10
|
+
aspire_inference.egg-info/SOURCES.txt
|
|
11
|
+
aspire_inference.egg-info/dependency_links.txt
|
|
12
|
+
aspire_inference.egg-info/requires.txt
|
|
13
|
+
aspire_inference.egg-info/top_level.txt
|
|
14
|
+
examples/basic_example.py
|
|
15
|
+
src/aspire/__init__.py
|
|
16
|
+
src/aspire/aspire.py
|
|
17
|
+
src/aspire/history.py
|
|
18
|
+
src/aspire/plot.py
|
|
19
|
+
src/aspire/samples.py
|
|
20
|
+
src/aspire/transforms.py
|
|
21
|
+
src/aspire/utils.py
|
|
22
|
+
src/aspire/flows/__init__.py
|
|
23
|
+
src/aspire/flows/base.py
|
|
24
|
+
src/aspire/flows/jax/__init__.py
|
|
25
|
+
src/aspire/flows/jax/flows.py
|
|
26
|
+
src/aspire/flows/jax/utils.py
|
|
27
|
+
src/aspire/flows/torch/__init__.py
|
|
28
|
+
src/aspire/flows/torch/flows.py
|
|
29
|
+
src/aspire/samplers/__init__.py
|
|
30
|
+
src/aspire/samplers/base.py
|
|
31
|
+
src/aspire/samplers/importance.py
|
|
32
|
+
src/aspire/samplers/mcmc.py
|
|
33
|
+
src/aspire/samplers/smc/__init__.py
|
|
34
|
+
src/aspire/samplers/smc/base.py
|
|
35
|
+
src/aspire/samplers/smc/blackjax.py
|
|
36
|
+
src/aspire/samplers/smc/emcee.py
|
|
37
|
+
src/aspire/samplers/smc/minipcn.py
|
|
38
|
+
tests/conftest.py
|
|
39
|
+
tests/integration_tests/conftest.py
|
|
40
|
+
tests/integration_tests/test_integration.py
|
|
41
|
+
tests/test_flows/test_jax_flows/test_flowjax_flows.py
|
|
42
|
+
tests/test_flows/test_torch_flows/test_zuko_flows.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
matplotlib
|
|
2
|
+
numpy
|
|
3
|
+
array-api-compat
|
|
4
|
+
wrapt
|
|
5
|
+
h5py
|
|
6
|
+
|
|
7
|
+
[blackjax]
|
|
8
|
+
blackjax
|
|
9
|
+
|
|
10
|
+
[emcee]
|
|
11
|
+
emcee
|
|
12
|
+
|
|
13
|
+
[jax]
|
|
14
|
+
jax
|
|
15
|
+
jaxlib
|
|
16
|
+
flowjax
|
|
17
|
+
|
|
18
|
+
[minipcn]
|
|
19
|
+
minipcn
|
|
20
|
+
|
|
21
|
+
[test]
|
|
22
|
+
pytest
|
|
23
|
+
pytest-requires
|
|
24
|
+
|
|
25
|
+
[torch]
|
|
26
|
+
torch
|
|
27
|
+
zuko
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aspire
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This examples demonstrates how to use aspire to fit a flow to a simple Gaussian
|
|
3
|
+
likelihood with a uniform prior.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import math
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from aspire import Aspire
|
|
10
|
+
from aspire.plot import plot_comparison
|
|
11
|
+
from aspire.samples import Samples
|
|
12
|
+
from aspire.utils import AspireFile, configure_logger
|
|
13
|
+
from scipy.stats import norm, uniform
|
|
14
|
+
|
|
15
|
+
# Configure the logger
|
|
16
|
+
configure_logger("INFO")
|
|
17
|
+
|
|
18
|
+
outdir = Path("outdir") / "basic_example"
|
|
19
|
+
outdir.mkdir(parents=True, exist_ok=True)
|
|
20
|
+
|
|
21
|
+
# Number of dimensions
|
|
22
|
+
dims = 4
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# Define the log likelihood and log prior
|
|
26
|
+
def log_likelihood(samples: Samples):
|
|
27
|
+
# The log likelihood must accept a Samples object
|
|
28
|
+
# The samples object contains the samples in the attribute samples.x
|
|
29
|
+
return norm(2, 1).logpdf(samples.x).sum(axis=-1)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def log_prior(samples: Samples):
|
|
33
|
+
return uniform(-10, 20).logpdf(samples.x).sum(axis=-1)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# True evidence is analytic for a Gaussian likelihood and uniform prior
|
|
37
|
+
true_log_evidence = -dims * math.log(20)
|
|
38
|
+
|
|
39
|
+
# Generate some initial samples
|
|
40
|
+
# These are slightly biased compared to the true posterior
|
|
41
|
+
initial_samples = Samples(norm(2.5, 1.0).rvs(size=(5000, dims)))
|
|
42
|
+
# Define the parameters and prior bounds
|
|
43
|
+
parameters = [f"x_{i}" for i in range(dims)]
|
|
44
|
+
prior_bounds = {p: [-10, 10] for p in parameters}
|
|
45
|
+
|
|
46
|
+
# Define the aspire object
|
|
47
|
+
aspire = Aspire(
|
|
48
|
+
log_likelihood=log_likelihood,
|
|
49
|
+
log_prior=log_prior,
|
|
50
|
+
dims=dims,
|
|
51
|
+
parameters=parameters,
|
|
52
|
+
prior_bounds=prior_bounds,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# Fit the flow to the initial samples
|
|
56
|
+
history = aspire.fit(
|
|
57
|
+
initial_samples,
|
|
58
|
+
n_epochs=50,
|
|
59
|
+
)
|
|
60
|
+
# Plot the loss
|
|
61
|
+
fig = history.plot_loss()
|
|
62
|
+
fig.savefig(outdir / "loss.png")
|
|
63
|
+
|
|
64
|
+
# Produce samples from the posterior
|
|
65
|
+
samples = aspire.sample_posterior(5000)
|
|
66
|
+
|
|
67
|
+
# Save the the results to a file
|
|
68
|
+
# The AspireFile is a small wrapper around h5py.File that automatically
|
|
69
|
+
# includes additional metadata
|
|
70
|
+
with AspireFile(outdir / "aspire_result.h5", "w") as f:
|
|
71
|
+
aspire.save_config(f, "aspire_config")
|
|
72
|
+
samples.save(f, "posterior_samples")
|
|
73
|
+
history.save(f, "flow_history")
|
|
74
|
+
|
|
75
|
+
fig = plot_comparison(
|
|
76
|
+
initial_samples,
|
|
77
|
+
samples,
|
|
78
|
+
samples,
|
|
79
|
+
per_samples_kwargs=[
|
|
80
|
+
dict(include_weights=True, color="C0"),
|
|
81
|
+
dict(include_weights=False, color="lightgrey"),
|
|
82
|
+
dict(include_weights=True, color="C1"),
|
|
83
|
+
],
|
|
84
|
+
labels=["Training samples", "Samples (w/o weights)", "Posterior samples"],
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
fig.savefig(outdir / "comparison.png")
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=45", "setuptools-scm[toml]>=6.2"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "aspire-inference"
|
|
7
|
+
authors = [
|
|
8
|
+
{name = "Michael J. Williams", email = "michaeljw1@googlemail.com"},
|
|
9
|
+
]
|
|
10
|
+
description = "Accelerate Sequential Posterior Inference via REuse"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
license = {text = "MIT"}
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
]
|
|
17
|
+
dependencies = [
|
|
18
|
+
"matplotlib",
|
|
19
|
+
"numpy",
|
|
20
|
+
"array-api-compat",
|
|
21
|
+
"wrapt",
|
|
22
|
+
"h5py",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
dynamic = ["version"]
|
|
26
|
+
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
jax = [
|
|
29
|
+
"jax",
|
|
30
|
+
"jaxlib",
|
|
31
|
+
"flowjax"
|
|
32
|
+
]
|
|
33
|
+
torch = [
|
|
34
|
+
"torch",
|
|
35
|
+
"zuko",
|
|
36
|
+
]
|
|
37
|
+
minipcn = [
|
|
38
|
+
"minipcn",
|
|
39
|
+
]
|
|
40
|
+
emcee = [
|
|
41
|
+
"emcee",
|
|
42
|
+
]
|
|
43
|
+
blackjax = [
|
|
44
|
+
"blackjax",
|
|
45
|
+
]
|
|
46
|
+
test = [
|
|
47
|
+
"pytest",
|
|
48
|
+
"pytest-requires",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
[project.urls]
|
|
52
|
+
Homepage = "https://github.com/mj-will/aspire"
|
|
53
|
+
|
|
54
|
+
[tool.setuptools_scm]
|
|
55
|
+
|
|
56
|
+
[tool.setuptools.package-dir]
|
|
57
|
+
aspire = "src/aspire"
|
|
58
|
+
|
|
59
|
+
[tool.ruff]
|
|
60
|
+
line-length = 79
|
|
61
|
+
indent-width = 4
|
|
62
|
+
target-version = "py39"
|
|
63
|
+
|
|
64
|
+
[tool.ruff.lint]
|
|
65
|
+
# Allow fix for all enabled rules (when `--fix`) is provided.
|
|
66
|
+
fixable = ["ALL"]
|
|
67
|
+
extend-select = ["I"]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""
|
|
2
|
+
aspire: Accelerated Sequential Posterior Inference via REuse
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
7
|
+
|
|
8
|
+
from .aspire import Aspire
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
__version__ = version("aspire")
|
|
12
|
+
except PackageNotFoundError:
|
|
13
|
+
__version__ = "unknown"
|
|
14
|
+
|
|
15
|
+
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"Aspire",
|
|
19
|
+
]
|