]> gitweb.factorcode.org Git - factor.git/commitdiff
random: Add a k parameter for pareto. Add some unit tests.
authorDoug Coleman <doug.coleman@gmail.com>
Sat, 31 Mar 2012 02:52:47 +0000 (19:52 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 3 Apr 2012 23:27:04 +0000 (16:27 -0700)
basis/random/random-tests.factor
basis/random/random.factor

index 3fc4ff80eb90de72293f5e513ee9f167235362bb..fc545a92471ded0b08e06a6c4c6fe45b98d8aeba 100644 (file)
@@ -1,5 +1,5 @@
 USING: random sequences tools.test kernel math math.functions
-sets grouping random.private ;
+sets grouping random.private math.statistics ;
 IN: random.tests
 
 [ 4 ] [ 4 random-bytes length ] unit-test
@@ -33,3 +33,15 @@ IN: random.tests
 
 [ ]
 [ [ 100 random-bytes ] with-system-random drop ] unit-test
+
+{ t }
+[ 50000 [ .15 exponential-random-float ] replicate [ mean ] [ std ] bi .2 ~ ] unit-test
+
+{ t }
+[ 50000 [ 1 exponential-random-float ] replicate [ mean ] [ std ] bi .2 ~ ] unit-test
+
+{ t t }
+[
+    50000 [ 1 3 pareto-random-float ] replicate [ mean ] [ std ] bi
+    [ 1.5 .3 ~ ] [ 3 sqrt 2 / .3 ~ ] bi*
+] unit-test
index 4c6943724442a38fa5e2f1af98e2f30fe390d446..107c090afd16c7b2bf151a1e74358011417ec96b 100644 (file)
@@ -127,8 +127,8 @@ ERROR: too-many-samples seq n ;
         1. swap / ^
     ] dip * ;
 
-: pareto-random-float ( alpha -- n )
-    [ random-unit ] dip [ 1. swap / ] bi@ ^ ;
+: pareto-random-float ( alpha -- n )
+    [ random-unit ] dip recip ^ /f ;
 
 :: (gamma-random-float>1) ( alpha beta -- n )
     ! Uses R.C.H. Cheng, "The generation of Gamma