Verify distribution uniformity/Naive: Difference between revisions

Content added Content deleted
(Added Elixir)
m (→‎{{header|REXX}}: changed/added whitespace and comments, centered the result.)
Line 1,202: Line 1,202:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX pgm simulates a # of trials of a random digit, show it's skew %. */
<lang rexx>/*REXX pgm simulates a number of trials of a random digit and show it's skew %*/
parse arg f t d s . /*obtain arguments (options). */
parse arg f t d s . /*obtain arguments (options) from C.L. */
if f=='' | f==',' then f='RANDOM' /* func ¬specified? Use default.*/
if f=='' | f==',' then f='RANDOM' /*function not specified? Use default.*/
if t=='' | t==',' then t=1000000 /*times " " " */
if t=='' | t==',' then t=1000000 /*times " " " " */
if d=='' | d==',' then d=1/2 /*delta% " " " */
if d=='' | d==',' then d=1/2 /*delta% " " " " */
if s\=='' then call random ,,s /*use some seed for repeatibility*/
if s\=='' then call random ,,s /*use some RAND seed for repeatability.*/
highDig=9 /*use this for the highest digit.*/
highDig=9 /*use this var for the highest digit. */
!.=0 /*zero all possible random trials*/
!.=0 /*initialize all possible random trials*/
do j=1 for t /* [↓] perform a lot of trials. */
do j=1 for t /* [↓] perform a bunch of trials. */
if f=='RANDOM' then ?=random(0,highDig) /*random func.*/
if f=='RANDOM' then ?=random(0,highDig) /*random function.*/
else interpret '?='f"(0,"highDig')' /* user func.*/
else interpret '?='f"(0,"highDig')' /* user function.*/
!.?=!.?+1 /*bump counter*/
!.?=!.?+1 /*bump the counter*/
end /*j*/ /* [↑] trials ───► pigeonholes. */
end /*j*/ /* [↑] store trials ───► pigeonholes. */
/* [↓] compute the dig skewness.*/
/* [↓] compute the digit's skewness. */
g=t/(1+highDig) /*calculate # of each digit throw*/
g=t/(1+highDig) /*calculate number of each digit throw.*/
OK?='OK skewed' /*words to show skewed or if OK. */
OK?='OK skewed' /*words to show "skewed" or if "OK".*/
w=max(8,length(t)) /*maximum length of # of trials. */
w=max(8,length(t)) /*maximum length of number of trials.*/
pad=left('',9) /*this is used for indentation. */
pad=left('',9) /*this is used for output indentation. */
say pad 'digit' center("hits",w) ' skew ' "skew%" 'result' /*hdr. */
say pad 'digit' center("hits",w) ' skew ' "skew%" 'result' /*header. */
say pad '─────' center('',w,'─') '──────' "─────" '──────' /*sep. */
say pad '─────' center('',w,'─') '──────' "─────" '──────' /*separator.*/
/** [↑] show header & separator.*/
/** [↑] show header and the separator.*/
do k=0 to highDig /*process each of the possible #.*/
do k=0 to highDig /*process each of the possible digits. */
skew=g-!.k /*calculate the skew for the dig.*/
skew=g-!.k /*calculate the skew for the digit. */
skewPC=(1-(g-abs(skew))/g)*100 /* " " " percentage. */
skewPC=(1-(g-abs(skew))/g)*100 /* " " " percentage for dig*/
ok=right(word(ok?,1+(skewPC>d)),6) /*it's gotta be one or the other.*/
ok=center(word(ok?,1+(skewPC>d)),6) /*it's gotta be one of skewed or xx%*/
say pad center(k,5) right(!.k,w) right(skew,6) format(skewPC,,3) ok
say pad center(k,5) right(!.k,w) right(skew,6) format(skewPC,,3) ok
end /*k*/
end /*k*/


say pad '─────' center('',w,'─') '──────' "─────" '──────' /*sep. */
say pad '─────' center('',w,'─') '──────' "─────" '──────' /*separator. */
y=5+1+w+1+6+1+6+1+6 /*width*/
y=5+1+w+1+6+1+6+1+6 /*the width. */
say pad center(" (with " t ' trials)',y) /*info.*/
say pad center(" (with " t ' trials)',y) /*# trials. */
say pad center(" (skewed when exceeds " d'%)',y) /*info.*/
say pad center(" (skewed when exceeds " d'%)',y) /*skewed note*/
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're all done. */</lang>
Execution note: &nbsp; quite a few runs were needed and the skew% lowered before a skewed result was obtained.
Execution note: &nbsp; quite a few runs were needed and the skew% lowered before a skewed result was obtained.
<br><br>
<br><br>
'''output''' using the default inputs:
'''output''' when using the default inputs:
<pre>
<pre>
digit hits skew skew% result
digit hits skew skew% result
───── ──────── ────── ───── ──────
───── ──────── ────── ───── ──────
0 99790 210 0.210 OK
0 99757 243 0.243 OK
1 99564 436 0.436 OK
1 100226 -226 0.226 OK
2 100061 -61 0.061 OK
2 100605 -605 0.605 skewed
3 99797 203 0.203 OK
3 100005 -5 0.005 OK
4 99877 123 0.123 OK
4 99670 330 0.330 OK
5 99578 422 0.422 OK
5 100011 -11 0.011 OK
6 99889 111 0.111 OK
6 100100 -100 0.100 OK
7 100619 -619 0.619 skewed
7 99513 487 0.487 OK
8 100414 -414 0.414 OK
8 99884 116 0.116 OK
9 100411 -411 0.411 OK
9 100229 -229 0.229 OK
───── ──────── ────── ───── ──────
───── ──────── ────── ───── ──────
(with 1000000 trials)
(with 1000000 trials)