Transform a sequence of uniform random numbers in the interval [0, 1)
into a sequence of exponential random numbers with parameter lambda.
(with-monad state-m
(defn exponential
"Transform a sequence of uniform random numbers in the interval [0, 1)
into a sequence of exponential random numbers with parameter lambda."
[lambda]
(when (<= lambda 0)
(throw (IllegalArgumentException.
"exponential distribution requires a positive argument")))
(let [neg-inv-lambda (- (/ lambda))
; remove very small numbers to prevent log from returning -Infinity
not-too-small (reject #(< % 1e-323) stream-next)]
(m-fmap #(* (. Math log %) neg-inv-lambda) not-too-small))))
Comments top
No comments for exponential. Log in to add a comment.