How to resolve the algorithm Verify distribution uniformity/Naive step by step in the Forth programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Verify distribution uniformity/Naive step by step in the Forth programming language
Table of Contents
Problem Statement
This task is an adjunct to Seven-sided dice from five-sided dice.
Create a function to check that the random integers returned from a small-integer generator function have uniform distribution.
The function should take as arguments:
The function should produce:
Show the distribution checker working when the produced distribution is flat enough and when it is not. (Use a generator from Seven-sided dice from five-sided dice).
See also:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Verify distribution uniformity/Naive step by step in the Forth programming language
Source code in the forth programming language
: .bounds ( u1 u2 -- ) ." lower bound = " . ." upper bound = " 1- . cr ;
: init-bins ( n -- addr )
cells dup allocate throw tuck swap erase ;
: expected ( u1 cnt -- u2 ) over 2/ + swap / ;
: calc-limits ( n cnt pct -- low high )
>r expected r> over 100 */ 2dup + 1+ >r - r> ;
: make-histogram ( bins xt cnt -- )
0 ?do 2dup execute 1- cells + 1 swap +! loop 2drop ;
: valid-bin? ( addr n low high -- f )
2>r cells + @ dup . 2r> within ;
: check-distribution {: xt cnt n pct -- f :}
\ assumes xt generates numbers from 1 to n
n init-bins {: bins :}
n cnt pct calc-limits {: low high :}
high low .bounds
bins xt cnt make-histogram
true \ result flag
n 0 ?do
i 1+ . ." : " bins i low high valid-bin?
dup 0= if ." not " then ." ok" cr
and
loop
bins free throw ;
You may also check:How to resolve the algorithm Look-and-say sequence step by step in the Scala programming language
You may also check:How to resolve the algorithm Accumulator factory step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm 15 puzzle game step by step in the Red programming language
You may also check:How to resolve the algorithm Median filter step by step in the J programming language
You may also check:How to resolve the algorithm Mertens function step by step in the CLU programming language