photomancy 0.0.1__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.
Files changed (30) hide show
  1. photomancy-0.0.1/.gitignore +221 -0
  2. photomancy-0.0.1/.pre-commit-config.yaml +20 -0
  3. photomancy-0.0.1/.python-version +1 -0
  4. photomancy-0.0.1/.readthedocs.yaml +20 -0
  5. photomancy-0.0.1/CHANGELOG.md +17 -0
  6. photomancy-0.0.1/LICENSE +21 -0
  7. photomancy-0.0.1/PKG-INFO +86 -0
  8. photomancy-0.0.1/README.md +18 -0
  9. photomancy-0.0.1/pyproject.toml +74 -0
  10. photomancy-0.0.1/src/photomancy/__init__.py +19 -0
  11. photomancy-0.0.1/src/photomancy/_version.py +24 -0
  12. photomancy-0.0.1/src/photomancy/backends/__init__.py +11 -0
  13. photomancy-0.0.1/src/photomancy/backends/base.py +25 -0
  14. photomancy-0.0.1/src/photomancy/backends/laplace.py +31 -0
  15. photomancy-0.0.1/src/photomancy/core/__init__.py +10 -0
  16. photomancy-0.0.1/src/photomancy/core/model.py +81 -0
  17. photomancy-0.0.1/src/photomancy/orbit/__init__.py +111 -0
  18. photomancy-0.0.1/src/photomancy/orbit/data.py +362 -0
  19. photomancy-0.0.1/src/photomancy/orbit/eig.py +531 -0
  20. photomancy-0.0.1/src/photomancy/orbit/forward.py +175 -0
  21. photomancy-0.0.1/src/photomancy/orbit/grid_search.py +357 -0
  22. photomancy-0.0.1/src/photomancy/orbit/init.py +241 -0
  23. photomancy-0.0.1/src/photomancy/orbit/laplace.py +1030 -0
  24. photomancy-0.0.1/src/photomancy/orbit/likelihoods.py +189 -0
  25. photomancy-0.0.1/src/photomancy/orbit/model.py +311 -0
  26. photomancy-0.0.1/src/photomancy/orbit/ofti.py +302 -0
  27. photomancy-0.0.1/src/photomancy/orbit/priors.py +197 -0
  28. photomancy-0.0.1/src/photomancy/orbit/thiele_innes.py +485 -0
  29. photomancy-0.0.1/src/photomancy/posterior.py +83 -0
  30. photomancy-0.0.1/src/photomancy/py.typed +0 -0
@@ -0,0 +1,221 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
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
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml
219
+
220
+ # hatch-vcs generated version file
221
+ src/photomancy/_version.py
@@ -0,0 +1,20 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: "v6.0.0"
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ - id: name-tests-test
7
+ args: [--pytest-test-first]
8
+ - id: end-of-file-fixer
9
+ - repo: https://github.com/astral-sh/ruff-pre-commit
10
+ rev: v0.15.8
11
+ hooks:
12
+ - id: ruff-check
13
+ args: [--fix]
14
+ - id: ruff-format
15
+ - repo: https://github.com/compilerla/conventional-pre-commit
16
+ rev: v4.4.0
17
+ hooks:
18
+ - id: conventional-pre-commit
19
+ stages: [commit-msg]
20
+ args: []
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,20 @@
1
+ # Required
2
+ version: 2
3
+
4
+ # Set the OS, Python version and other tools you might need
5
+ build:
6
+ os: ubuntu-22.04
7
+ tools:
8
+ python: "3.12"
9
+
10
+ python:
11
+ install:
12
+ - method: pip
13
+ path: .
14
+ extra_requirements:
15
+ # Install with the [docs] flag for sphinx docs specific extensions
16
+ - docs
17
+
18
+ # Build documentation in the "docs/" directory with Sphinx
19
+ sphinx:
20
+ configuration: docs/conf.py
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ ## 0.0.1 (2026-06-18)
4
+
5
+
6
+ ### Features
7
+
8
+ * add Backend/Posterior protocol and Laplace backend ([c18e80c](https://github.com/CoreySpohn/photomancy/commit/c18e80c1104e447dbcd2dcdd61346959db5ec662))
9
+ * **core:** add scene-PyTree logdensity assembly ([77f80ed](https://github.com/CoreySpohn/photomancy/commit/77f80edea1cd82f5dbef604dfa92b5ae37759723))
10
+ * scaffold photomancy and port orbit fitting from orbix ([d3fe243](https://github.com/CoreySpohn/photomancy/commit/d3fe2436403568c8928788ef43f9a14fe7fae130))
11
+
12
+
13
+ ### Miscellaneous Chores
14
+
15
+ * release 0.0.1 ([25be93d](https://github.com/CoreySpohn/photomancy/commit/25be93d29830aab5f51b6482c1c6950acd2eee01))
16
+
17
+ ## Changelog
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Corey Spohn
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,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: photomancy
3
+ Version: 0.0.1
4
+ Summary: Divination from light: Bayesian inference and value-of-information for HWO direct imaging
5
+ Project-URL: Homepage, https://github.com/CoreySpohn/photomancy
6
+ Project-URL: Issues, https://github.com/CoreySpohn/photomancy/issues
7
+ Author-email: Corey Spohn <corey.a.spohn@nasa.gov>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2026 Corey Spohn
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+ License-File: LICENSE
30
+ Classifier: Development Status :: 2 - Pre-Alpha
31
+ Classifier: Intended Audience :: Science/Research
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Topic :: Scientific/Engineering :: Astronomy
35
+ Requires-Python: >=3.11
36
+ Requires-Dist: blackjax>=1.2
37
+ Requires-Dist: equinox
38
+ Requires-Dist: hwoutils
39
+ Requires-Dist: jax>=0.8.1
40
+ Requires-Dist: jaxlib>=0.8.1
41
+ Requires-Dist: jaxtyping
42
+ Requires-Dist: numpy
43
+ Requires-Dist: numpyro>=0.15.0
44
+ Requires-Dist: orbix
45
+ Requires-Dist: skyscapes
46
+ Provides-Extra: dev
47
+ Requires-Dist: pre-commit; extra == 'dev'
48
+ Provides-Extra: docs
49
+ Requires-Dist: matplotlib; extra == 'docs'
50
+ Requires-Dist: myst-nb; extra == 'docs'
51
+ Requires-Dist: sphinx; extra == 'docs'
52
+ Requires-Dist: sphinx-autoapi; extra == 'docs'
53
+ Requires-Dist: sphinx-autodoc-typehints; extra == 'docs'
54
+ Requires-Dist: sphinx-book-theme; extra == 'docs'
55
+ Provides-Extra: imaging
56
+ Requires-Dist: coronalyze; extra == 'imaging'
57
+ Provides-Extra: npe
58
+ Requires-Dist: flowjax; extra == 'npe'
59
+ Provides-Extra: ns
60
+ Requires-Dist: jaxns; extra == 'ns'
61
+ Provides-Extra: test
62
+ Requires-Dist: arviz; extra == 'test'
63
+ Requires-Dist: hypothesis; extra == 'test'
64
+ Requires-Dist: nox; extra == 'test'
65
+ Requires-Dist: pytest; extra == 'test'
66
+ Requires-Dist: pytest-cov; extra == 'test'
67
+ Description-Content-Type: text/markdown
68
+
69
+ # photomancy
70
+
71
+ > Divination from light.
72
+
73
+ A JAX-native Bayesian inference and value-of-information engine for the Habitable
74
+ Worlds Observatory direct-imaging simulation suite. `orbix` builds the geometry,
75
+ `skyscapes` builds the scene, and **photomancy** divines the scene back from the
76
+ data: posteriors, evidence, and the next-best observation, over orbits, disks, and
77
+ (later) atmospheres and images.
78
+
79
+ The engine is forward-model agnostic. A fit is a `logdensity` over a partitioned
80
+ scene PyTree, assembled from three plug-ins -- a forward model, a likelihood, and a
81
+ prior -- and run through a uniform `Backend` (Laplace mixture, NUTS, adaptive
82
+ tempered SMC, MCLMC, Pathfinder) that returns one `Posterior` exposing `.sample`,
83
+ `.log_prob`, and `.evidence`.
84
+
85
+ Status: early development. Orbit fitting is implemented; disk, atmosphere, and
86
+ image-domain fitting are planned.
@@ -0,0 +1,18 @@
1
+ # photomancy
2
+
3
+ > Divination from light.
4
+
5
+ A JAX-native Bayesian inference and value-of-information engine for the Habitable
6
+ Worlds Observatory direct-imaging simulation suite. `orbix` builds the geometry,
7
+ `skyscapes` builds the scene, and **photomancy** divines the scene back from the
8
+ data: posteriors, evidence, and the next-best observation, over orbits, disks, and
9
+ (later) atmospheres and images.
10
+
11
+ The engine is forward-model agnostic. A fit is a `logdensity` over a partitioned
12
+ scene PyTree, assembled from three plug-ins -- a forward model, a likelihood, and a
13
+ prior -- and run through a uniform `Backend` (Laplace mixture, NUTS, adaptive
14
+ tempered SMC, MCLMC, Pathfinder) that returns one `Posterior` exposing `.sample`,
15
+ `.log_prob`, and `.evidence`.
16
+
17
+ Status: early development. Orbit fitting is implemented; disk, atmosphere, and
18
+ image-domain fitting are planned.
@@ -0,0 +1,74 @@
1
+ [build-system]
2
+ requires = ['hatchling', "hatch-fancy-pypi-readme", "hatch-vcs"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "photomancy"
7
+ description = "Divination from light: Bayesian inference and value-of-information for HWO direct imaging"
8
+ authors = [{ name = "Corey Spohn", email = "corey.a.spohn@nasa.gov" }]
9
+ dynamic = ['readme', 'version']
10
+ requires-python = ">=3.11"
11
+ license = { file = "LICENSE" }
12
+ classifiers = [
13
+ "Development Status :: 2 - Pre-Alpha",
14
+ "Intended Audience :: Science/Research",
15
+ "License :: OSI Approved :: MIT License",
16
+ "Programming Language :: Python :: 3",
17
+ "Topic :: Scientific/Engineering :: Astronomy",
18
+ ]
19
+ dependencies = [
20
+ "blackjax>=1.2",
21
+ "equinox",
22
+ "hwoutils",
23
+ "jax>=0.8.1",
24
+ "jaxlib>=0.8.1",
25
+ "jaxtyping",
26
+ "numpy",
27
+ "numpyro>=0.15.0",
28
+ "orbix",
29
+ "skyscapes",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ dev = ["pre-commit"]
34
+ docs = [
35
+ "sphinx",
36
+ "myst-nb",
37
+ "sphinx-book-theme",
38
+ "sphinx-autoapi",
39
+ "sphinx_autodoc_typehints",
40
+ "matplotlib",
41
+ ]
42
+ test = ["nox", "pytest", "hypothesis", "pytest-cov", "arviz"]
43
+ # Deferred extras (declared, not installed in the BlackJAX-only first cut):
44
+ ns = ["jaxns"] # nested-sampling evidence backend
45
+ npe = ["flowjax"] # amortized neural posterior estimation
46
+ imaging = ["coronalyze"] # differentiable detection/extraction likelihood helpers
47
+
48
+ [project.urls]
49
+ Homepage = "https://github.com/CoreySpohn/photomancy"
50
+ Issues = "https://github.com/CoreySpohn/photomancy/issues"
51
+
52
+ [tool.hatch.version]
53
+ source = "vcs"
54
+
55
+ [tool.hatch.build.hooks.vcs]
56
+ version-file = "src/photomancy/_version.py"
57
+
58
+ [tool.hatch.metadata.hooks.fancy-pypi-readme]
59
+ content-type = "text/markdown"
60
+
61
+ [[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
62
+ path = "README.md"
63
+
64
+ [tool.hatch.build.targets.wheel]
65
+ packages = ["src/photomancy"]
66
+
67
+ [tool.hatch.build.targets.sdist]
68
+ exclude = ["/scripts", "/docs", "/tests", "/.github"]
69
+
70
+ [tool.ruff.lint]
71
+ select = ["B", "D", "E", "F", "I", "UP", "RUF"]
72
+
73
+ [tool.ruff.lint.pydocstyle]
74
+ convention = "google"
@@ -0,0 +1,19 @@
1
+ """photomancy: divination from light.
2
+
3
+ A JAX-native Bayesian inference and value-of-information engine for fitting
4
+ astrophysical scenes (orbits, disks, and later atmospheres and images) to
5
+ direct-imaging data. orbix builds the geometry, skyscapes builds the scene, and
6
+ photomancy divines the scene back from the data: posteriors, evidence, and the
7
+ next-best observation.
8
+
9
+ The engine is forward-model agnostic. A fit is a ``logdensity`` over a partitioned
10
+ scene PyTree, assembled from a forward model, a likelihood, and a prior, and run
11
+ through a uniform ``Backend`` that returns one ``Posterior``.
12
+ """
13
+
14
+ try:
15
+ from photomancy._version import __version__
16
+ except ImportError: # pragma: no cover - generated by hatch-vcs at build time
17
+ __version__ = "0.0.0"
18
+
19
+ __all__ = ["__version__"]
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '0.0.1'
22
+ __version_tuple__ = version_tuple = (0, 0, 1)
23
+
24
+ __commit_id__ = commit_id = None
@@ -0,0 +1,11 @@
1
+ """photomancy inference backends.
2
+
3
+ Each backend wraps one inference method (Laplace today; NUTS, adaptive-tempered
4
+ SMC, MCLMC, Pathfinder to come) behind a uniform ``run(logdensity, init, key)``
5
+ that returns a Posterior.
6
+ """
7
+
8
+ from photomancy.backends.base import AbstractBackend
9
+ from photomancy.backends.laplace import LaplaceBackend
10
+
11
+ __all__ = ["AbstractBackend", "LaplaceBackend"]
@@ -0,0 +1,25 @@
1
+ """The Backend protocol: how inference is run on a logdensity."""
2
+
3
+ from abc import abstractmethod
4
+
5
+ import equinox as eqx
6
+
7
+
8
+ class AbstractBackend(eqx.Module):
9
+ """Runs inference on a flat logdensity and returns a Posterior.
10
+
11
+ Backends are ``eqx.Module`` config objects (hyperparameters as fields) with a
12
+ pure ``run``. A backend sees only the flat ``logdensity`` -- never the scene or
13
+ the forward model -- which is what keeps the engine forward-model agnostic.
14
+ """
15
+
16
+ @abstractmethod
17
+ def run(self, logdensity, init, key=None):
18
+ """Run inference on ``logdensity`` from ``init``, returning a Posterior.
19
+
20
+ Args:
21
+ logdensity: ``z -> scalar`` log-density over the flat parameter position.
22
+ init: Initial flat position. Shape ``(d,)``.
23
+ key: PRNG key (unused by deterministic backends such as Laplace).
24
+ """
25
+ raise NotImplementedError
@@ -0,0 +1,31 @@
1
+ """Laplace backend: MAP + Hessian -> GaussianPosterior."""
2
+
3
+ import jax
4
+ import jax.numpy as jnp
5
+ from jax.scipy.optimize import minimize
6
+
7
+ from photomancy.backends.base import AbstractBackend
8
+ from photomancy.posterior import GaussianPosterior
9
+
10
+
11
+ class LaplaceBackend(AbstractBackend):
12
+ """MAP + Laplace approximation: a Gaussian posterior around the mode.
13
+
14
+ Optimizes the logdensity to its MAP, takes the Hessian there for the
15
+ covariance, and returns a ``GaussianPosterior`` carrying the Laplace
16
+ log-evidence. Exact for Gaussian targets.
17
+ """
18
+
19
+ def run(self, logdensity, init, key=None):
20
+ """Fit the Laplace approximation and return a GaussianPosterior."""
21
+
22
+ def neg(z):
23
+ return -logdensity(z)
24
+
25
+ z_map = minimize(neg, init, method="BFGS").x
26
+ hess = jax.hessian(neg)(z_map)
27
+ cov = jnp.linalg.inv(hess)
28
+ d = z_map.shape[0]
29
+ _, logdet_cov = jnp.linalg.slogdet(cov)
30
+ log_z = logdensity(z_map) + 0.5 * d * jnp.log(2.0 * jnp.pi) + 0.5 * logdet_cov
31
+ return GaussianPosterior(mean=z_map, cov=cov, evidence=log_z)
@@ -0,0 +1,10 @@
1
+ """photomancy.core: the domain-agnostic inference engine.
2
+
3
+ Assembles a logdensity over a partitioned scene PyTree from plug-in forward
4
+ models, likelihoods, and priors. The partition / ravel boundary helpers and the
5
+ Backend protocol + unified Posterior build on top of this.
6
+ """
7
+
8
+ from photomancy.core.model import build_logdensity, build_scene_logdensity
9
+
10
+ __all__ = ["build_logdensity", "build_scene_logdensity"]