Skip to content

Commit

Permalink
random: adding f-random
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Jul 9, 2024
1 parent 2f4f364 commit 26de528
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion basis/random/random.factor
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ M: cauchy-distribution random*
[ [ median>> ] [ scale>> ] bi ] dip cauchy-random* ;

:: chi-square-random* ( dof rnd -- n )
0.5 dof 2 * rnd gamma-random* ;
dof 2.0 / 2.0 rnd gamma-random* ;

: chi-square-random ( dof -- n )
random-generator get chi-square-random* ;
Expand Down Expand Up @@ -607,6 +607,18 @@ C: <logseries-distribution> logseries-distribution
M: logseries-distribution random*
[ p>> ] dip logseries-random* ;

:: f-random* ( dof-num dof-den rnd -- n )
dof-num rnd chi-square-random* dof-den *
dof-den rnd chi-square-random* dof-num * / ;

: f-random ( df-num df-den -- n )
random-generator get f-random* ;

TUPLE: f-distribution dof-num dof-den ;
C: <f-distribution> f-distribution
M: f-distribution random*
[ [ dof-num>> ] [ dof-den>> ] bi ] dip f-random* ;

{
{ [ os windows? ] [ "random.windows" require ] }
{ [ os unix? ] [ "random.unix" require ] }
Expand Down

0 comments on commit 26de528

Please sign in to comment.