• (normal-box-muller mu sigma)
Transform a sequence of uniform random numbers in the interval [0, 1)
into a sequence of normal random numbers with mean mu and standard
deviation sigma.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/probabilities/monte_carlo.clj:163 top

(defn normal-box-muller
  "Transform a sequence of uniform random numbers in the interval [0, 1)
   into a sequence of normal random numbers with mean mu and standard
   deviation sigma."
  [mu sigma]
  (fn [rs]
    (let [[u1 rs] (stream-next rs)
	  [u2 rs] (stream-next rs)
	   v1 (- (* 2.0 u1) 1.0)
	   v2 (- (* 2.0 u2) 1.0)
	   s  (+ (* v1 v1) (* v2 v2))
	   ls (. Math sqrt (/ (* -2.0 (. Math log s)) s))
	   x1 (* v1 ls)
	   x2 (* v2 ls)]
	  (if (or (>= s 1) (= s 0))
	    (recur rs)
	    [x1 rs]))))
Vars in clojure.contrib.probabilities.monte-carlo/normal-box-muller: = >= defn fn let or
Used in 0 other vars

Comments top

No comments for normal-box-muller. Log in to add a comment.