NumPyのガンマ分布を使用して、正のサポートと既知の平均と分散を持つサンプルの生成に関する質問に答えました。Incanterで同じことを試してみようと思いました。しかし、NumPyで得た結果とは異なり、サンプルの平均と分散を分布の平均と分散に近づけることができませんでした。
(defproject incanter-repl "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[incanter "1.5.4"]])
(require '[incanter
[core]
[distributions :refer [gamma-distribution mean variance draw]]
[stats :as stats]])
(def dist
(let [mean 0.71
variance 2.89
theta (/ variance mean)
k (/ mean theta) ]
(gamma-distribution k theta)))
Incanter は分布の平均と分散を計算します
(mean dist) ;=> 0.71
(variance dist) ;=> 2.89
その分布からの引き出しに基づいて、サンプルの平均と分散を計算します
(def samples (repeatedly 10000 #(draw dist)))
(stats/mean samples) ;=> 0.04595208774029654
(stats/variance samples) ;=> 0.01223348345651905
サンプルで計算されたこれらの統計は、分布の平均と分散にはるかに近いと予想しました。私は何が欠けていますか?
答え
Incanter には、Parallel Colt から継承されたバグがありました。パラメータの処理は、Parallel Colt のメソッド間で一貫していません。問題レポートhttps://github.com/incanter/incanter/issues/245を参照してください。