Building blocks

Blocks.

AI4BayesCode builds every sampler by composing pre-validated built-in blocks. A block is the unit of sampling.

AI4BayesCode never asks the AI to write a sampler from scratch. Every sampler is composed from pre-validated built-in blocks, so the AI only decomposes the described model into modular units and picks a built-in block for each unit.

The three tiers separate the model from the math. The wrapper decomposes the parsed model into modular units (a parameter or a small group of them) and assembles the result into runnable code. The block tier maps each unit to a built-in block and is the unit of sampling. The kernel tier provides the generic, reusable algorithms the blocks call. Because the AI only works at the block tier, the generated code stays reliable.

Parsed model Joint posterior distribution Tier A · Wrapper Decomposes the parsed model into modular blocks and assembles the sampler into runnable C++, R, and Python code. Tier B · Block Pre-validated built-in sampling blocks: NUTS, Gibbs, RJMCMC, BART, and more. The unit of sampling. Tier C · Kernel Numerical engines with existing implementations, such as NUTS built on mcmclib, shared across blocks. Examples Reference examples composed of built-in blocks. assign blocks assemble blocks call numerical algorithms update parameters refer to compose of
The three-tier architecture. Tier B, the block tier, is the unit of sampling.

An example

Spike-and-slab regression with a Laplace slab.

A model that is awkward for a single gradient-based sampler. The Dirac spike forces exact zeros through discrete indicators, and the Laplace slab resists marginalization. AI4BayesCode splits it across built-in blocks.

Model

\[ \begin{aligned} y_i \mid \beta, \sigma &\sim \mathcal{N}(X_i^\top \beta,\ \sigma^2) \\ \gamma_j \mid \pi &\sim \mathrm{Bernoulli}(\pi) \\ \beta_j &= 0 \quad \text{if } \gamma_j = 0 \\ \beta_j &\sim \mathrm{Laplace}(0,\ b\,\sigma) \quad \text{if } \gamma_j = 1 \\ b &\sim \mathrm{Gamma}(\alpha_b, \beta_b) \\ \pi &\sim \mathrm{Beta}(1, 1) \\ \sigma &\propto 1/\sigma \end{aligned} \]

Block assignment

# each unit maps to a built-in block
(β, γ)  ->  rjmcmc_block      # coupled, trans-dim
(σ, b)  ->  joint_nuts_block  # the scales, via NUTS
π       ->  beta_gibbs_block  # conjugate Beta

Each block calls a kernel-tier engine. The joint_nuts_block runs NUTS built on kernels vendored from mcmclib, a C++ MCMC library.