Exact fair-bit block-rejection sampling and capped trials #
A block-rejection sampler (Cslib.Probability.BlockRejectionSpec) reads fair bits in independent
blocks of length width and applies a single-block decoder attempt : List Bool → Option α. On
some a the sampler accepts and halts with a; on none it rejects the block and repeats on the
remaining bits.
Running at most trials blocks gives the capped law BlockRejectionSpec.runTrials (realized by
decodeTrials on trials * width fair bits), whose failure probability is rejectProb ^ trials
and whose fallback completion runCapped lies within statistical distance
(rejectProb ^ trials).toReal of the target distribution. Reading arbitrarily many blocks defines a
computable discrete distribution generating tree BlockRejectionSpec.toDDGTree satisfying
toDDGTree.run n = runTrials (n / width) for every bit budget n, generating the target law
whenever 0 < width and acceptProb ≠ 0, and reading width / acceptProb fair bits in
expectation (expectedFlips_toDDGTree).
Instantiating BlockRejectionSpec with binary decoding yields:
uniformFinRejectionSpecanduniformFinTreeforFin n([NeZero n]), generatingPMF.uniformOfFintype (Fin n)with expected flips at most2 * Nat.clog 2 n(attainingkat powers of two2 ^ k) andt-trial failure probability at most(1 / 2) ^ t;dyadicFinRejectionSpecusingUniformNat.dyadicSize n(Nat.log 2 n + 1bits per trial), givingt-trial failure probability at most(1 / 2) ^ tfor alln ≥ 1;subsetDyadicSpecfor exact uniform sampling on a nonempty subsetS : Finset αinside an indexed rangeFin m → α.
Main definitions #
Cslib.Probability.BlockRejectionSpec: block width and single-block acceptance decoder.Cslib.Probability.BlockRejectionSpec.decodeTrials,runTrials,runCapped: cappedt-trial decoder, optional law, and fallback completion.Cslib.Probability.BlockRejectionSpec.toDDGTree: exact unboundedDDGTreeof a block sampler.Cslib.Probability.finCutoffSpec,uniformFinRejectionSpec,uniformFinTree,dyadicFinRejectionSpec,subsetDyadicSpec: exact bounded-integer and subset fair-bit rejection samplers.
Main results #
Cslib.Probability.BlockRejectionSpec.acceptProb_eq_tsum_some,Cslib.Probability.BlockRejectionSpec.runTrials_none,Cslib.Probability.BlockRejectionSpec.runTrials_some_of_singleLaw: exact single-trial andt-trial laws.Cslib.Probability.BlockRejectionSpec.dist_runCapped_le,Cslib.Probability.BlockRejectionSpec.closeTo_runCapped: statistical distance of the capped fallback sampler from the target law (with and without[Fintype α]).Cslib.Probability.BlockRejectionSpec.run_toDDGTree,Cslib.Probability.BlockRejectionSpec.toDDGTree_generates,Cslib.Probability.BlockRejectionSpec.expectedFlips_toDDGTree: exactDDGTreegeneration and closed-form expected fair-bit costwidth / acceptProb.Cslib.Probability.uniformFinTree_generates,Cslib.Probability.expectedFlips_uniformFinTree_two_pow,Cslib.Probability.expectedFlips_uniformFinTree_le,Cslib.Probability.runTrials_dyadicFinRejectionSpec_none_le: bounded-integer exactness, expected flip bounds, and exponential trial-failure decay.Cslib.Probability.subsetDyadicSpec_generates,Cslib.Probability.expectedFlips_subsetDyadicSpec: exact subset generation and expected flips.
References #
Law of a single width-bit rejection trial.
Rejection probability of a single width-bit trial.
Acceptance probability 1 - rejectProb of a single width-bit trial.
The rejection probability is finite, as a finiteness rule.
Acceptance probability of a single block equals ∑' a, spec.singleLaw (some a).
Decode at most trials consecutive width-bit blocks from bits, returning the first
accepted value or none.
Post-composing a single-block decoder with Option.map f commutes with decodeTrials.
Distribution of running at most trials independent width-bit blocks.
Failure probability after t trials is rejectProb ^ t.
Accepted outcome mass after t trials.
When a single trial outputs some a with probability acceptProb * target a, t trials
output some a with probability (1 - rejectProb ^ t) * target a.
Capped t-trial sampler substituting fallback if all t blocks reject.
Statistical distance between the capped fallback sampler and the target distribution is
(rejectProb ^ t).toReal * (1 - (target fallback).toReal), hence at most
(rejectProb ^ t).toReal.
Without any Fintype assumption, spec.runCapped fallback t lies within CloseTo statistical
distance spec.rejectProb ^ t of target.
Unbounded DDGTree realization #
Exact discrete distribution generating tree executing spec on consecutive width-bit
blocks.
If 0 < width, acceptProb ≠ 0, and accepted trials follow target, toDDGTree generates
target exactly.
Closed-form expected fair-bit cost of toDDGTree: (width : ℝ≥0∞) / acceptProb whenever
0 < width (including ⊤ when acceptProb = 0).
When 0 < width and 1 / 2 ≤ acceptProb, toDDGTree reads at most 2 * width fair bits in
expectation.
Block-rejection specification for Fin n reading k bits per trial and keeping binary values
strictly below n.
After t trials of uniformFinRejectionSpec n (n ≥ 1), rejection probability is at most
(1 / 2) ^ t.
At any power of two 2 ^ k, uniformFinTree (2 ^ k) reads k fair bits in expectation,
attaining the Knuth–Yao entropy lower bound.
For every n ≥ 1, uniformFinTree n reads at most 2 * Nat.clog 2 n fair bits in
expectation.
Subset rejection sampling #
Exact dyadic block-rejection sampler for a subset S : Finset α inside an indexed range
enum : Fin m → α.