Fixed a bug in Gamma random number generator.
This commit is contained in:
Родитель
4fea42533b
Коммит
ca34a7cb6f
|
@ -1,6 +1,11 @@
|
|||
### 0.1.4
|
||||
### 0.1.5
|
||||
|
||||
* Fixed a bug in Gamma random number generator.
|
||||
|
||||
### 0.1.4 - 2016-04-20
|
||||
|
||||
* Sampler state can be serialized to continue unfinished computation.
|
||||
* Fixed Mersenne twister copy constructor
|
||||
|
||||
### 0.1.3 - 2016-04-12
|
||||
|
||||
|
|
|
@ -553,10 +553,11 @@ let rec draw (gen:MT19937) d = // random number generator
|
|||
elif a=1.0 then
|
||||
rng_exp(1.0)/b
|
||||
elif a<20.0 && floor a = a then
|
||||
// _Alpha is small integer, compute directly
|
||||
let rec iter c y =
|
||||
if c=0 then y else iter (c-1) y*rand_positive()
|
||||
-log(iter (int a) (rand_positive()))/b
|
||||
// _Alpha is small integer, compute directly:
|
||||
// -∑_(k=1)^n▒ln〖U_k 〗 ~Γ(n,1)
|
||||
// Where U is uniformly distributed on (0, 1] (https://en.wikipedia.org/wiki/Gamma_distribution)
|
||||
let product = seq { for _ in 1..int a -> rand_positive()} |> Seq.reduce (*)
|
||||
-log(product)/b
|
||||
else
|
||||
// no shortcuts
|
||||
let rec iter () =
|
||||
|
|
Загрузка…
Ссылка в новой задаче