random: adding laplace, cauchy, chi-square, student's t, and inverse gamma distributions.

db4
John Benediktsson 2012-04-14 21:00:19 -07:00
parent e9ffd2da37
commit ee499cd63d
1 changed files with 17 additions and 0 deletions
basis/random

View File

@ -225,6 +225,23 @@ ERROR: too-many-samples seq n ;
: triangular-random-float ( low high -- n )
2dup + 2 /f (triangular-random-float) ;
: laplace-random-float ( mean scale -- n )
random-unit dup 0.5 <
[ 2 * log ] [ 1 swap - 2 * log neg ] if * + ;
: cauchy-random-float ( median scale -- n )
random-unit 0.5 - pi * tan * + ;
: chi-square-random-float ( dof -- n )
[ 0.5 ] dip 2 * gamma-random-float ;
: student-t-random-float ( dof -- n )
[ 0 1 normal-random-float ] dip
[ chi-square-random-float ] [ / ] bi sqrt / ;
: inv-gamma-random-float ( shape scale -- n )
recip gamma-random-float recip ;
{
{ [ os windows? ] [ "random.windows" require ] }
{ [ os unix? ] [ "random.unix" require ] }