kinextract.bayesian.build_numpyro_model
- kinextract.bayesian.build_numpyro_model(st: FitState, v_center: float)[source]
Build the NumPyro model function for one LOSVD/template/continuum- offset posterior, at fixed regularization strength
st.xlam.b(the LOSVD histogram) andw(template weights) are both, physically, compositional/simplex-like quantities – a normalized histogram and a set of mixture weights, respectively (the forward model only ever useswthrough the scale-invariant ratio(t @ w) / sum(w), so its absolute magnitude is unidentified by the likelihood, andbmust satisfysum(b) == 1). Each is sampled as an unconstrained latent Gaussian pushed through a softmax:z_b/z_w ~ Normal(0, 1),b = softmax(z_b),w = softmax(z_w). This exactly enforces non-negativity andsum() == 1by construction, giving NUTS a naturally-scaled space to explore rather than a curved, box-constrained one – a bounded-Uniformparameterization with an ad hoc normalization penalty produces pathological NUTS trajectories (hundreds to thousands of leapfrog steps per transition, saturating the tree-depth ceiling regardless oftarget_accept_probtuning), the classic signature of poorly-scaled, artificially box-constrained geometry.b/ware registered asnumpyro.deterministicsites (not just local variables), somcmc.get_samples()returns them directly under the"b"/"w"keys as their physical (non-negative, sum-to-1) values – every downstream consumer (_posterior_mean_vector(),kinextract.plotting.plot_losvd_posterior(), etc.) reads them exactly as it would any other named site.The forward-model math (template mixture, LOSVD interpolation via the precomputed
losvd_j0/j1/wtables, pixel-scatter convolution viaip_map/ip_mask, continuum multiplication, and thecontinuum_poly_modeadditive/multiplicative correction) is reframed as a log-joint-density: the negative log-posterior (up to an additive constant) is0.5*chi2 + 0.5*smooth– the0.5on both terms is what makeschi2a genuine Gaussian log-likelihood andsmooth(the already-quadratic wing-tapered second-difference roughness penalty, recentered per_wing_taper_lam_vec()) a genuine log-prior at the same relative strength that a givenxlammeans for the MAP-basedxlamselection (kinextract.fitting._auto_select_xlam()) that picks it – omitting the0.5onsmoothalone would leave the prior twice as strong, relative to the likelihood, than that selection intends. There is no separate normalization-penalty term:sum(b) == 1already holds exactly by construction via the softmax parameterization above.The continuum multiplier is a runtime argument of the returned model (
model(cont)), not a value baked into the closure – passing it as an argument (with a fixed array shape) lets JAX/NumPyro reuse one compiled trace across calls instead of recompiling from scratch each time. In practicecontis always all-ones here (only pre-normalized-mode fits,cfg.fit_continuum=False, are supported byfit_state_bayesian()), but the model still accepts it as an explicit argument for the (unsupported) continuum-cofit case.- Parameters:
- Returns:
A NumPyro model function of one argument,
model(cont), suitable fornumpyro.infer.NUTS.- Return type:
callable