A discrete distribution, defined by a map dist mapping values
to probabilities. The sum of probabilities must be one.
(with-monad state-m
(defn discrete
"A discrete distribution, defined by a map dist mapping values
to probabilities. The sum of probabilities must be one."
[dist]
(letfn [(pick-at-level [l dist-items]
(let [[[x p] & rest-dist] dist-items]
(if (> p l)
x
(recur (- l p) rest-dist))))]
(m-fmap #(pick-at-level % (seq dist)) stream-next))))
Comments top
No comments for discrete. Log in to add a comment.