diff options
author | Konrad Hinsen <konrad.hinsen@laposte.net> | 2009-05-11 17:08:16 +0000 |
---|---|---|
committer | Konrad Hinsen <konrad.hinsen@laposte.net> | 2009-05-11 17:08:16 +0000 |
commit | ce884883d8829276da9416a7d32d09a5b79456f2 (patch) | |
tree | a3f0271e84ed908c040e42994c6b45788bc5ad65 | |
parent | 5b826a3e8315cbb7fbcb5c6b1d83c74cf6dc66d1 (diff) |
finite-distributions: more distribution generation facilities
-rw-r--r-- | src/clojure/contrib/probabilities/finite_distributions.clj | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/clojure/contrib/probabilities/finite_distributions.clj b/src/clojure/contrib/probabilities/finite_distributions.clj index 6daea371..861cdc65 100644 --- a/src/clojure/contrib/probabilities/finite_distributions.clj +++ b/src/clojure/contrib/probabilities/finite_distributions.clj @@ -110,11 +110,6 @@ "Returns the Bernoulli distribution for probability p." (choose p 1 :else 0)) -(defn rademacher - [] - "Returns the Rademacher distribution." - (choose (/ 1 2) -1 :else 1)) - (defn- bc [n] "Returns the binomial coefficients for a given n." @@ -138,13 +133,17 @@ f (bc n)] (into {} (map vector k (map * f pk ql))))) +(defn make-distribution + "Returns the distribution in which each element x of the collection + has a probability proportional to (f x)" + [coll f] + (normalize (into {} (for [k coll] [k (f k)])))) + (defn zipf "Returns the Zipf distribution in which the numbers k=1..n have probabilities proportional to 1/k^s." [s n] - (normalize - (into {} (for [k (range 1 (inc n))] [k (/ (java.lang.Math/pow k s))])))) - + (make-distribution (range 1 (inc n)) #(/ (java.lang.Math/pow % s)))) (defn certainly "Returns a distribution in which the single value v has probability 1." |