random: adding rayleigh, gumbel, logistic, and power random floats.

db4
John Benediktsson 2012-04-18 14:37:27 -07:00
parent 8e0df4df9c
commit 9e9d830ec0
2 changed files with 27 additions and 2 deletions

View File

@ -1,5 +1,5 @@
USING: random sequences tools.test kernel math math.functions
sets grouping random.private math.statistics ;
USING: random sequences tools.test kernel math math.constants
math.functions sets grouping random.private math.statistics ;
IN: random.tests
[ 4 ] [ 4 random-bytes length ] unit-test
@ -76,3 +76,16 @@ IN: random.tests
50000 [ 2 3 laplace-random-float ] replicate
[ mean 2 .2 ~ ] [ std 2 sqrt 3 * .2 ~ ] bi
] unit-test
{ t t }
[
50000 [ 12 rayleigh-random-float ] replicate
[ mean pi 2 / sqrt 12 * .2 ~ ]
[ std 2 pi 2 / - sqrt 12 * .2 ~ ] bi
] unit-test
{ t t }
[
50000 [ 3 4 logistic-random-float ] replicate
[ mean 3 .2 ~ ] [ std pi 4 * 3 sqrt / .2 ~ ] bi
] unit-test

View File

@ -242,6 +242,18 @@ ERROR: too-many-samples seq n ;
: inv-gamma-random-float ( shape scale -- n )
recip gamma-random-float recip ;
: rayleigh-random-float ( mode -- n )
random-unit log -2 * sqrt * ;
: gumbel-random-float ( loc scale -- n )
random-unit log neg log * - ;
: logistic-random-float ( loc scale -- n )
random-unit dup 1 swap - / log * + ;
: power-random-float ( alpha -- n )
[ random-unit log exp 1 swap - ] dip recip ^ ;
{
{ [ os windows? ] [ "random.windows" require ] }
{ [ os unix? ] [ "random.unix" require ] }