Skip to main content

Tensor-train Bayesian inference: compile a black-box posterior into a tensor train

Project description

ttbayes

Tensor-train Bayesian inference — compile a black-box Bayesian posterior into a tensor-train (TT) representation, with gravitational-wave parameter estimation as the first application.

Status: name placeholder. 0.0.1 reserves the name on PyPI. None of the API below is implemented yet — do not install this expecting a working library. Development follows the checkpoint plan in plan.md.

What it will do

Given a black-box batched log-likelihood and a separable prior over continuous bounded parameters, approximate the square root of the unnormalized posterior with a tensor train:

$$\sqrt{\pi(\theta)} \approx \Psi_{\mathrm{TT}}(\theta), \qquad \widehat{\pi}{\mathrm{TT}}(\theta) = \Psi{\mathrm{TT}}(\theta)^2$$

Squaring keeps the approximate posterior nonnegative by construction. Building the TT with tempered TT-cross in physically informed (Fisher-whitened) coordinates is intended to reduce both the TT ranks and the number of expensive likelihood evaluations needed to reconstruct the posterior.

Once compiled, the TT posterior supports evaluation, log-evidence estimation, 1-D and 2-D marginals, moments, and approximate sampling — with an optional independence Metropolis–Hastings correction that restores the exact target.

Intended usage

import ttbayes as ttb

model = ttb.BlackBoxModel(
    parameter_names=("chirp_mass", "mass_ratio", "luminosity_distance", "cos_inclination"),
    log_likelihood=log_likelihood,
    log_prior=log_prior,
)

posterior = ttb.compile(
    model=model,
    domain={
        "chirp_mass": (28.0, 32.0, 64),
        "mass_ratio": (0.4, 1.0, 64),
        "luminosity_distance": (100.0, 1000.0, 64),
        "cos_inclination": (-1.0, 1.0, 64),
    },
    transform="fisher",
    positivity="square_root",
    tempering=[0.1, 0.25, 0.5, 0.75, 1.0],
    tolerance=1e-4,
    max_rank=32,
)

print(posterior.log_evidence())
samples = posterior.sample_corrected(model=model, n=10_000, method="independence_mh")

Installation

pip install ttbayes                # core: numpy, torch, tntorch
pip install "ttbayes[bilby]"       # + bilby, dynesty for the GW adapter
pip install -e ".[dev]"            # development

Requires Python 3.11+.

Scope

The first prototype is deliberately limited to continuous bounded parameters, tensor-product grids, black-box batched log-likelihoods, separable priors, and a tntorch TT-cross backend. Bilby is an optional adapter; Dynesty through Bilby is the reference sampler.

The public API is kept independent of tntorchtntorch.Tensor is not exposed.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ttbayes-0.0.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ttbayes-0.0.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file ttbayes-0.0.1.tar.gz.

File metadata

  • Download URL: ttbayes-0.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for ttbayes-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7f5d84786e74e76a0a8c97a21148d85d61fcc78ab774b726f94245627d0a197c
MD5 354aa406927834ac7459f521cc4e5c6d
BLAKE2b-256 8ceeb094cf41c0ed83c0e497b0956b1783c65e38108411d0305d295baf1c8181

See more details on using hashes here.

File details

Details for the file ttbayes-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: ttbayes-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for ttbayes-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a91367c748775d636ffa01f648ada72ec27315eb875304f3750dd256c0c90f6a
MD5 5ed8a2e62ac27374e3c257f270643486
BLAKE2b-256 93ac138fca28f6b978a77ea7b52e665b74ec9e5aaf5da45a5308a350533ca4e9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page