photomancy#

Divination from light.

photomancy is a JAX-native engine for Bayesian inference and value of information over astrophysical scenes observed by direct imaging. orbix builds the geometry and skyscapes builds the scene, and photomancy divines the scene back from the data: posteriors over the scene parameters, the Bayesian evidence for model comparison, and the expected information gain of a candidate next observation.

The engine is forward-model agnostic. A fit is a normalized log density over the free entries of a model: the model holds every quantity, a dictionary names the free entries and their priors, and data terms score the measurements. run(fit, backend, key) turns a fit into a Posterior, a cloud of weighted draws with the evidence and its standard error, whichever backend produced it. Fits and posteriors builds one fit step by step on a problem with a known answer, and the glossary collects the Bayesian inference and JAX vocabulary.

Ecosystem position#

        flowchart LR
    orbix["orbix<br/>geometry"]
    skyscapes["skyscapes<br/>scene + SEDs"]
    photomancy["<b>photomancy</b><br/>fit -> backend -> posterior -> EIG"]
    out["posteriors + evidence<br/>+ next observation"]

    orbix --> photomancy
    skyscapes --> photomancy
    photomancy --> out
    

Quick start#

A fit names a model, its free entries with their priors, and the data terms, and run turns it into a posterior. For one planet’s orbit from relative astrometry, with an orbix System as the model:

This sketch requires a user-supplied orbix System and AstrometryData.

from orbix.system import OrbitLaw, ThieleInnesBlock
from priorities import LogUniform, Uniform
from skyscapes.population import kipping_eccentricity

from photomancy.infer import Fit, run
from photomancy.measurements import RelativeAstrometryTerm
from photomancy.orbit import any_epoch, classical_elements

law = OrbitLaw(
    period_d=LogUniform(50.0, 5000.0), eccentricity=kipping_eccentricity(0.9)
)
block = ThieleInnesBlock(law, Uniform(0.9, 1.1), rows=(0,), system="")
fit = Fit(system, {"orbits": block}, (RelativeAstrometryTerm(data),))

posterior = run(fit, any_epoch(), key)
log_evidence = posterior.log_evidence  # NaN when the backend refuses its estimate
elements = classical_elements(posterior, key, 1000, orbit_path="orbits")

The orbit fitting example runs this on synthetic data and folds in new epochs one at a time.

For nested-model comparisons, convert the natural-log evidence difference to the bound-based, two-sided Gaussian significance used by Benneke and Seager (2013):

This comparison requires posteriors from two user-supplied model fits.

from photomancy.infer import sigma_from_log_bayes_factor

log_bayes_factor = posterior_with.log_evidence - posterior_without.log_evidence
sigma = sigma_from_log_bayes_factor(log_bayes_factor)

sigma_from_log_bayes_factor() inverts the Sellke, Bayarri and Berger (2001) bound in log space and accepts scalars or arrays under JAX transformations. Negative log Bayes factors return NaN; zero returns the finite branch endpoint at p = 1/e. Bayes factors below about 2.5 (about 2 sigma) are weak evidence. The function applies no floor or display cap, and its calibration does not measure a frequentist false-alarm probability. See the function’s API reference for the equations and paper citations.

Installation#

pip install photomancy

The importance, Laplace, quadrature and staged MAP backends work from the base install. The sampler backends are optional extras: photomancy[blackjax] for NUTS, MCLMC and Pathfinder, photomancy[jaxns] for nested sampling, or photomancy[samplers] for both.

pip install "photomancy[samplers]"

photomancy is in early development, and the API may still change.

Status#

Orbit fitting is implemented across radial-velocity, astrometry, photometry and detection-report data, and the pixel likelihood fits coronagraph images through the coronagraphoto forward model. Disk fitting and atmospheric retrieval are in progress. See the architecture overview for the design and the roadmap.