3 Primitive Stochastic Functions
sample —
draw a sample from a distribution mem —
apply memoization to a (stochastic) function fail —
represents a predicate observation failure; abort the current program execution observe-sample —
represents a point observation; weights the current program evaluation by the likelihood of drawing the given value from the given distribution
See also Sampling Convenience Functions.
procedure
(mem f) → procedure?
f : procedure?
In general, a memoized function must not be called outside of the dynamic extent of the sampler/solver context in which it was created.
Examples: | |||||||||||
|
For example, the following function models two coin flips where at least one of them is known to be heads (#t):
(define (flip-two-coins/one-heads) (define A (flip)) (define B (flip)) (unless (or A B) (fail)) (list A B))
procedure
(observe-sample dist value) → void?
dist : dist? value : any/c