Skip to main content

bayesjax

Bayesjax is the JAX/BlackJAX NUTS backend for Bayeswire models. It binds concrete data, compiles transformed log densities, runs NUTS, reports essential diagnostics, and provides supported prior-predictive simulation.

The declaration language, IR, distributions and constraints metadata, specs, and conformance corpus belong to Bayeswire. Workflow orchestration and durable run directories belong to Bayescycle.

Sample a model

import jax.numpy as jnp

from bayeswire import Data, Observed, Param, model
from bayeswire.constraints import Positive
from bayeswire.distributions import Normal, Truncated
from bayesjax import bind_model
from bayesjax.diagnostics import ess, rhat
from bayesjax.inference import sample


@model
class LinearRegression:
    alpha = Param(Normal(0.0, 1.0))
    beta = Param(Normal(0.0, 1.0))
    sigma = Param(
        Truncated(Normal(0.0, 1.0), lower=0.0),
        constraint=Positive(),
    )

    x = Data.vector()
    y = Observed(Normal(alpha + beta * x, sigma))


x = jnp.linspace(-3.0, 3.0, 50)
y = 2.0 + 0.5 * x
bound = bind_model(LinearRegression, {"x": x, "y": y})
result = sample(
    bound,
    seed=42,
    num_chains=4,
    num_warmup=200,
    num_samples=500,
)

print(rhat(result.samples))
print(ess(result.samples))

result.samples maps parameter names to constrained arrays shaped (num_chains, num_samples, *param_shape). Warmup and retained-draw NUTS statistics are separate in result.diagnostics; divergences are available at result.diagnostics.sampling.is_divergent.

Backend semantics

  • NUTS is the only inference algorithm; BlackJAX is internal.
  • bind_model(...) is the explicit transition from Bayeswire metadata to a validated BoundModel.
  • Constraints define transforms and Jacobians. A prior needing truncation normalization must use explicit Truncated(...) with matching bounds.
  • Discrete distributions are valid observed likelihoods and prior-predictive outcomes, but discrete latent parameters are unsupported by NUTS.
  • OrderedLogistic observed labels are zero-based.
  • Partially observed continuous vectors use an explicit observed/missing index partition; discrete missing latents are unsupported.
  • Additional density factors are evaluated by the log-density compiler but are rejected by prior-predictive simulation when no ancestral sampling semantics exist.

Complete backend invariants are in docs/invariants.md.

InferenceData-compatible schema

Bayesjax does not depend on ArviZ, xarray, NetCDF, or Zarr. Downstream exporters can consume its typed adapter:

from bayesjax.interop.inferencedata import inferencedata_groups

schema = inferencedata_groups(bound, result)

The schema contains posterior draws, post-warmup sample statistics, observed and constant data, and declared dimension metadata without constructing an ArviZ object.

Conformance and references

Bayesjax consumes every installed Bayeswire corpus fixture and is the float64 oracle used to generate its expected log-density and gradient values. Optional Stan fixtures and validation commands are documented in reference/stan/README.md.

Development

uv run ruff format --check .
uv run ruff check .
uv run ty check
uv run pytest

See AGENTS.md for numerical and architecture rules.

Download files

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

Source Distribution

bayesjax-0.7.0.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

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

bayesjax-0.7.0-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file bayesjax-0.7.0.tar.gz.

File metadata

  • Download URL: bayesjax-0.7.0.tar.gz
  • Upload date:
  • Size: 35.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for bayesjax-0.7.0.tar.gz
Algorithm Hash digest
SHA256 d24934ce01319b4f45ec1c53d064c972793c8a28688d23c7588fb86ae3cf531f
MD5 1e0f01794753642e25af8bda24ab710a
BLAKE2b-256 990060d9cea5927ac52d7ff78990af0c049fb65c409c6618515c81cfad3fdd66

See more details on using hashes here.

File details

Details for the file bayesjax-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: bayesjax-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 44.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for bayesjax-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bbd0e0d44c3f21b9757c324b19468683ee0c9f1444aa98c32853c5674b4bd9e
MD5 053055e65713f01271f3efc5dbbba69d
BLAKE2b-256 cedebbf291006d59e6cb58a2dc4b2ea65a26e9c47e437ca9133ad7c344da5db0

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 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