circuits-inference
Safe HaskellNone
LanguageGHC2024

Circuit.Inference.Sampler

Description

Effectful samplers as Prob (K IO) morphisms.

Synopsis

Primitive samplers

bernoulli :: Double -> Prob (K IO) Double () Bool Source #

Bernoulli trial with success probability p.

Output True with probability p, False with probability 1-p.

uniformDiscrete :: [a] -> Prob (K IO) Double () a Source #

Discrete uniform distribution over a finite list.

Recursive trace samplers

geometric :: Double -> Prob (K IO) Int () Int Source #

Geometric distribution counting failures before the first success.

Implemented as a terminating traceEK over an effectful Bernoulli body. Each recursive iteration performs an IO sample, so the trace is productive and returns a value with probability 1 (for 0 < p <= 1).

geometricBody :: Double -> Prob (K IO) Int (Either () Int) (Either Int Int) Source #

Body of the geometric sampler.

Input: Left () on first call, Right n on recursive calls where n is the current failure count. Output: Right k terminates with final count k; Left k continues with count k.

sample :: Prob (K IO) b () b -> IO b Source #

Extract a single sample from a sampler by using the output itself as the dualizing object.