Reference · The Applied Higher-Order Functions catalogue
rainbow.algorithms.proofs.ahof.direct-sampling
AHoF D5 Direct Sampling: draw a sample from a Bayesian network by ancestral sampling, drawing each variable from its conditional distribution given already sampled parents. A single categorical draw uses inverse-transform sampling: given a uniform draw u in [0,1) and the running cumulative probability, the category is selected once the cumulative reaches u: selects? cumulative u = decide (u <= cumulative) over the exact-rational cumulative probability. Defined: the selection test. Proved native and axiom-free, as worked instances: cumulative 7 with draw 5 selects, cumulative 3 with draw 5 skips, and the worked certificate 5 <= 7 (native nnrat/at-most). That inverse-transform sampling is a valid draw from the distribution is classical and not proved here. The topological order, the CDF construction, and the RNG are executable concerns. Requires nnrat/at-most, audit/decide-nnrat-at-most, nnrat/decide-at-most-true-sound (all in the D63 checkpoint). Scope (measured by the kernel): this module has 3 worked instances (statements about specific values). None of its theorems is a guarantee about the algorithm for all inputs; `lein verify rainbow.algorithms.proofs.ahof.direct-sampling` prints this classification.
direct-sampling/selects?
direct-sampling/selects? : (x₁ x₂ : ℚ≥0) → data/Bool
ℚ≥0 = nnrat/NonnegativeRational
direct-sampling/selects-category
direct-sampling/selects-category : → bo/is-safe 7 5 = data/true
= = equality/Eq
direct-sampling/selection-is-valid
direct-sampling/selection-is-valid : → 5 ≤ 7
≤ = nnrat/at-most
direct-sampling/skips-below-draw
direct-sampling/skips-below-draw : → bo/is-safe 3 5 = data/false
= = equality/Eq