Skip to main content

speculative_accept

Function speculative_accept 

Source
pub fn speculative_accept(
    proposal: &DraftProposal,
    verify: &VerifyResult,
    rng: &mut Philox4x32,
) -> AcceptDecision
Expand description

Pure speculative-acceptance algorithm. Given the draft’s proposal and the target’s verification, runs the per-position accept/reject test and returns the final decision. No model state, no I/O — easy to unit-test against hand-built distributions.

Algorithm (Leviathan et al. 2022, Algorithm 1): for i in 0..n: r ~ Uniform(0,1) if r < min(1, q_target(x_i) / p_draft(x_i)): accept x_i else: sample x’ from norm(max(0, q - p)) return (accepted[..i], Some(x’)) return (all n accepted, None)