Skip to content

Exponential default for the precision diagonal; gamma-shape corrections for the Z-ratio and Gibbs paths#168

Merged
MaartenMarsman merged 5 commits into
developfrom
feat/gamma-diagonal-zratio
Jul 10, 2026
Merged

Exponential default for the precision diagonal; gamma-shape corrections for the Z-ratio and Gibbs paths#168
MaartenMarsman merged 5 commits into
developfrom
feat/gamma-diagonal-zratio

Conversation

@MaartenMarsman

Copy link
Copy Markdown
Collaborator

Summary

  • The default precision_scale_prior for continuous models is now the named exponential_prior(eta = 1). Numerics are bit-identical to the previous gamma_prior(shape = 1, eta = 1) (both resolve to GammaScalePrior(1, rate)); a seeded-fit identity test pins the equivalence. The conjugate_slab gate in extract_prior_inclusion_probabilities() now admits both family strings instead of keying on "gamma", which would have demoted prior-only chains from the Gibbs path under the new default.
  • The hierarchical graph-prior specification accepts gamma_prior() diagonals of any shape. The Z-ratio constants generalize from the exponential to a Gamma(shape, rate) diagonal with the prior weight on the raw diagonals: generalized Gauss-Laguerre pair and bridge axes, a shape-shifted node channel (delta + shape), a vectorized generalized-Laguerre spike integral (exact Gamma(nu)^2 beta^(-2 nu) limit at c = 0, nu = delta + shape), and an independence-Metropolis correction (K_ii_new/K_ii_old)^(shape - 1) in the clique-2 sweep and the calibration-oracle Gibbs. The constants cell and session cache extend to (delta, eta, shape, slab), and scale_shape flows from the spec through run_sampler()/sample_ggm_prior() into the C++ engine.
  • The main-chain row-block Gibbs already carried the shape correction; it is now certified by a cross-sampler agreement test against adaptive Metropolis at shape 2 and a slow-gated SBC block (Gibbs, Gamma(2, 1) diagonal, p = 3).
  • At shape 1 every code path keeps the existing expressions and RNG streams bit-exactly; the engine reference fixtures pass unchanged.

Verification

  • Per-channel Monte-Carlo references at shape 0.5 and 2, Normal and Cauchy slabs (test-zratio-gamma-shape.R); generalized-Laguerre moment identities; spike integral against stats::integrate.
  • Hierarchical graph-law identity at shape 0.5 and 2 on both update methods (Bernoulli(0.3) marginal within 0.02 at q = 6); standardized-cell invariance at fixed (delta, eta, shape) across frames.
  • Calibrated-engine vs long-run block-oracle consistency at shape 2.
  • Gibbs vs adaptive-Metropolis diagonal-law agreement at shape 2 (mean ratio within 5%, per-column KS on thinned draws).
  • Full test suite green; R CMD check --as-cran 0 errors / 0 warnings.

…ision diagonal

The default precision_scale_prior becomes exponential_prior(eta = 1),
the same GammaScalePrior(1, rate) as the previous
gamma_prior(shape = 1, eta = 1) at the C++ level; a seeded-fit identity
test pins the equivalence. The conjugate_slab gate in
extract_prior_inclusion_probabilities() now admits both family strings,
keeping the prior-only chain on the Gibbs path under the new default.
…) diagonal

The channel builders carry the diagonal prior K_ii ~ Gamma(alpha, beta)
with the prior weight on the raw diagonals. The spike integral gains a
(s1 s2)^(alpha-1) factor, evaluated by a vectorized generalized
Gauss-Laguerre rule on the shifted product form with the exponentially
scaled Bessel; the slab pair and bridge integrals move their diagonal
axes to generalized Gauss-Laguerre (weight S^(alpha-1) e^(-beta S)); the
node channel folds the weight into the tilt exponent (delta + alpha);
and the clique-2 sweep corrects the alpha = 1 conjugate proposal by an
independence-Metropolis ratio (K_ii_new/K_ii_old)^(alpha-1). The
constants cell and session cache key extend to (delta, eta, alpha,
slab); zratio_cell_constants() accepts scale_shape. At alpha = 1 every
path keeps the existing expressions and RNG stream bit-exactly.

Each generalized channel is checked against a direct Monte Carlo of the
same moment ratio at alpha in {0.5, 2} (normal and Cauchy slabs), the
generalized Laguerre rule against gamma moments, and the spike integral
against stats::integrate; the alpha = 1 engine fixtures are unchanged.
ZRatioEngine gains an alpha parameter (default 1) on set_oracle_params()
and enable_calibration(). The block-Gibbs sweep keeps the alpha = 1
conjugate row proposal and accepts with the independence-Metropolis
ratio (K_ii_new/K_ii_old)^(alpha-1); the neighborless diagonal draws
rgamma(delta + alpha, beta) and the block seed draws rgamma(alpha, beta)
at alpha != 1. sample_ggm/sample_mixed read an optional zratio alpha
field, and the test interfaces expose it. At alpha = 1 every path draws
the identical RNG sequence; the engine reference fixtures are unchanged.

An alpha = 2 consistency gate checks the additive tables and the
calibrated estimator against the long-run block oracle.
Remove the shape-1 stops in bgm_spec and sample_ggm_prior, pass
scale_shape into zratio_cell_constants() on the GGM, mixed, and
prior-sampler paths, and forward the cell's alpha to the C++ engine.

The graph-law identity gate now runs at shape 0.5 and 2 on both update
methods (Bernoulli(0.3) marginal within 0.02 at q = 6), the
standardized-cell invariance check covers the gamma cell, and the
hierarchical bgm() eligibility test replaces the shape-2 error pin with
a shape-2 fit.
The row-block Gibbs at shape != 1 (independence-MH accept
(K_ii_new/K_ii_old)^(shape-1) on the joint row proposal) gets two gates:
a cross-sampler agreement test against adaptive Metropolis on the same
joint-spec prior at shape 2 (mean and per-column KS on thinned
diagonals), and a slow-gated SBC block (Gibbs, Gamma(2, 1) diagonal,
p = 3, no edge selection) reusing the existing harness via a shape
parameter on draw_prior_K.

Docs and NEWS drop the shape-1 requirement from the hierarchical spec
and describe the generalized constants.
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.42105% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.97%. Comparing base (733f529) to head (834d830).

Files with missing lines Patch % Lines
R/zratio_tables.R 83.58% 11 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #168      +/-   ##
===========================================
- Coverage    91.08%   90.97%   -0.11%     
===========================================
  Files          104      104              
  Lines        14952    14996      +44     
===========================================
+ Hits         13619    13643      +24     
- Misses        1333     1353      +20     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MaartenMarsman MaartenMarsman merged commit 5d0a212 into develop Jul 10, 2026
7 of 9 checks passed
@MaartenMarsman MaartenMarsman deleted the feat/gamma-diagonal-zratio branch July 10, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant