pub fn sample_in_two<const N: usize>(
peak: &[f64; N],
covariance: &[[f64; N]; N],
outer: &[bool; N],
pilot: usize,
draws: usize,
seed: u64,
inner_middle: impl FnMut(&[f64; N]) -> Option<[f64; N]>,
log_target: impl FnMut(&[f64; N]) -> Option<f64>,
) -> Option<Posterior<N>>Expand description
sample in two blocks, adapted on a pilot: for a posterior whose other unknowns follow some
of them along a ridge the Laplace approximation can’t bend to, and which may reach further than
its curvature says.
The blocks. The unknowns outer marks are drawn first, from a Student-t about their share
of peak; then the others, from a Student-t about inner_middle of the point drawn so far, the
others still at peak. inner_middle gives a point whose unknowns not marked outer are where
the others are taken to center given the marked ones, as a step of Gauss–Newton’s from peak
gives them; its marked unknowns aren’t read. It must give the same answer for the same point:
the proposal’s density is then known, so the draws weigh to the posterior whatever middle it
gives, a poor one costing effective draws only. None from it, or one not finite, makes a
failed draw.
The pilot. First pilot draws, the marked block’s scale its share of covariance and the
others’ their covariance given it (the Schur complement). Their weighted spread about the
proposal’s center, Ĉ = Σ ωᵢ eᵢ eᵢᵀ, is set against each block’s scale S: where, along an
eigenvector of S^(-1/2) Ĉ S^(-T/2), the posterior reaches further than S says, that block’s
scale is widened to it, up to MAX_WIDENING in variance; it is never narrowed. Then draws
more on the widened scales, and only those are read, so that given the pilot the answer is
plain importance sampling (adaptive importance sampling: M.-S. Oh and J. O. Berger, “Adaptive
importance sampling in Monte Carlo integration”, J. Statist. Comput. Simul. 41, 1992,
pp. 143–168, who adapt a Student-t to a pilot’s weighted moments). Posterior::draws and
Posterior::failed count both stages’ draws; Posterior::effective_draws the read ones’.
Each draw’s proposal is the product of two Student-t densities of ν = DEGREES_OF_FREEDOM,
up to a constant ln q = −(ν + K)/2 · ln(1 + δ₁²/ν) − (ν + N − K)/2 · ln(1 + δ₂²/ν) for K
marked unknowns, each δ² its block’s as in sample: a marginal times a conditional, not one
joint Student-t. Otherwise as sample, whose Nones it shares, and also None if a block’s
scale isn’t positive definite. With nothing marked it draws one Student-t about
inner_middle(peak).