Skip to main content

MorphZ

Python versions PyPI version CI Docs GitHub Repo arXiv Published paper

MorphZ logo

MorphZ estimates the Bayesian marginal likelihood, or evidence, from posterior samples. It is a post-processing tool: it does not run its own sampler, and it places no requirements on which sampler produced the posterior draws. The same workflow can be used with nested sampling, parallel-tempered MCMC, HMC, NUTS, or any other sampler that provides posterior samples.

Given posterior samples, the prior, and the likelihood, MorphZ returns the log-evidence estimate together with a bridge-sampling relative-error diagnostic. The target integral is

z(X \mid \mathcal{M}) = \int_{\Theta}
  L(X \mid \boldsymbol{\theta}, \mathcal{M})
  \pi(\boldsymbol{\theta} \mid \mathcal{M})
  d\boldsymbol{\theta}.

How It Works

MorphZ has two main components.

Morph Approximation

MorphZ first builds a tractable approximation to the posterior, called the Morph approximation, by factorising the full posterior into a product of low-dimensional joint factors over disjoint blocks of parameters, plus marginals over leftover singleton parameters:

\mathcal{M}_{B_L}(\boldsymbol{\theta}) =
  \prod_{b \in B_L} P_b(\boldsymbol{\theta}_b)
  \prod_{s \in S(B_L)} P_s(\theta_s).

Block membership is chosen by maximising the sum of block total correlations, an information-theoretic measure of joint dependence inside each block. This selects the product-of-blocks approximation that is closest to the posterior at the chosen order. The optimisation is solved with Seeded Greedy Maximisation (SGM), and block and singleton densities are fit with multivariate Gaussian-kernel KDEs.

Optimal Bridge Sampling

MorphZ then uses the Morph approximation as the proposal distribution inside an optimal bridge-sampling estimator. To avoid reuse bias, it splits the supplied posterior samples into one batch for fitting the Morph approximation and a separate batch for bridge sampling.

For each call, MorphZ produces:

  • logz, the log-evidence estimate.
  • A bridge-sampling relative mean-squared error diagnostic, computed from the same posterior and proposal samples.

Features

  • Morph approximation object.
  • Total correlation computation for higher-order correlations.
  • Multiprocessing support for non-vectorized likelihoods.
  • Mutual information plot.

Installation

Python 3.10+ is recommended.

pip install morphz

From source (editable):

pip install -e .

Core Usage

To estimate log_z, provide posterior samples and a log-posterior function. If you already have log-posterior values for those same samples, pass them as log_posterior_values to avoid recomputing them.

import morphZ

log_z= morphZ.evidence(
    samples,
    log_posterior_function=lp_fn,
    log_posterior_values=log_prob,
    n_resamples=5000,
    n_estimations=1,
    morph_type="2_group",
    output_path="./example/",
)

Run The Examples

Interactive notebooks live in examples/:

  • examples/eggbox.ipynb — eggbox likelihood (dynesty nested sampling)
  • examples/gaussian shell.ipynb — Gaussian shell (dynesty nested sampling)
  • examples/peak_sampling.ipynb — sharply peaked posterior
  • examples/numpyro_gaussian_shell.ipynb — Gaussian shell with NUTS via NumPyro
  • examples/jaxns_gaussian_shell.ipynb — Gaussian shell with nested sampling via JAXNS
  • examples/numpyro_morphz_lnz.ipynb — log-evidence comparison across morph types (NumPyro/NUTS)

Citation

If you use MorphZ, please cite:

@article{1554-y6ns,
  title   = {Enhancing evidence estimation through informed probability density approximation},
  author  = {Zahraoui, El Mehdi and Maturana-Russel, Patricio and Vajpeyi, Avi
             and van Straten, Willem and Meyer, Renate and Gulyaev, Sergei},
  journal = {Phys. Rev. D},
  volume  = {113},
  issue   = {8},
  pages   = {083014},
  year    = {2026},
  month   = {Apr},
  publisher = {American Physical Society},
  doi     = {10.1103/1554-y6ns},
  url     = {https://link.aps.org/doi/10.1103/1554-y6ns}
}

API Highlights

  • Morphs: Morph_Indep, Morph_Pairwise, Morph_Group, Morph_Tree.
  • Bandwidths: select_bandwidth, compute_and_save_bandwidths.
  • Evidence: evidence, bridge_sampling_ln (lower‑level), compute_bridge_rmse.
  • Total correlation: Nth_TC.compute_and_save_tc.

Notes:

  • If you pass a numeric kde_bw (e.g., 0.9) the library skips bandwidth JSONs.
  • pair/group proposals will compute and cache MI.json/params_*_TC.json on first use.

Dependencies

  • Core: numpy, scipy, matplotlib, corner, networkx, emcee, statsmodels, scikit-learn
  • Optional: pandas (CSV labels), pygraphviz (nicer tree layout), scikit-sparse (optional exception type)

Development

  • Build wheels/sdist: python -m build
  • Check metadata: twine check dist/*
  • Tests live in tests/

Versioning & Release

Versioning is derived from git tags via setuptools_scm.

  • Tag a release: git tag vX.Y.Z && git push --tags
  • CI: publishes to TestPyPI on pushes to main/master; to PyPI on v* tags.
  • Uses PyPI/TestPyPI Trusted Publishing (OIDC). You can also use API tokens if preferred.

License

BSD-3-Clause. See LICENSE for details.

Metadata

Release files for morphZ 0.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for morphZ 0.4.4
File Size Uploaded
morphz-0.4.4.tar.gz 4.6 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for morphZ 0.4.4
File Interpreter ABI Platform
morphz-0.4.4-py3-none-any.whl Python 3 none any Details

Total release size: 4.7 MB

Release files / morphz-0.4.4.tar.gz

Download URL morphz-0.4.4.tar.gz
Size 4.6 MB
Tags Source
SHA-256 checksum
How to use checksums
a309bc0a4d4c5d118b7c32cd01aef93c09d916fc39c41d5f697f1ccdb2240440
BLAKE2b-256 checksum
How to use checksums
de8619a3c55a1789b0a450791bcdc6914eecb7629404c081d801028c03a6fcec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 19, 2026.

Transparency log

Release files / morphz-0.4.4-py3-none-any.whl

Download URL morphz-0.4.4-py3-none-any.whl
Size 55.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc6cb63229f470e365a43461fe198e2883f57ce4f2d804a4c4aebf985d77853c
BLAKE2b-256 checksum
How to use checksums
d380a13f3ad391d05c245d4b194e2e33c413040b3519771abc9addbbe0774b2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 19, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.4 This release

2 release files

0.4.3

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.2

2 release files

0.2

2 release files

0.1.8

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page