Return the distribution of samples of length n from the
distribution dist
(with-monad state-m
(defn sample
"Return the distribution of samples of length n from the
distribution dist"
[n dist]
(m-seq (replicate n dist)))
(defn sample-reduce
"Returns the distribution of the reduction of f over n samples from the
distribution dist."
([f n dist]
(if (zero? n)
(m-result (f))
(let [m-f (m-lift 2 f)
sample (replicate n dist)]
(reduce m-f sample))))
([f val n dist]
(let [m-f (m-lift 2 f)
m-val (m-result val)
sample (replicate n dist)]
(reduce m-f m-val sample))))
(defn sample-sum
"Return the distribution of the sum over n samples from the
distribution dist."
[n dist]
(sample-reduce ga/+ n dist))
(defn sample-mean
"Return the distribution of the mean over n samples from the
distribution dist"
[n dist]
(let [div-by-n (m-lift 1 #(ga/* % (/ n)))]
(div-by-n (sample-sum n dist))))
(defn sample-mean-variance
"Return the distribution of the mean-and-variance (a vector containing
the mean and the variance) over n samples from the distribution dist"
[n dist]
(let [extract (m-lift 1 (fn [mv] [(:mean mv) (:variance mv)]))]
(extract (sample-reduce acc/add acc/empty-mean-variance n dist))))
)
Comments top
No comments for sample. Log in to add a comment.