Verify distribution uniformity/Naive: Difference between revisions

Content added Content deleted
(added Haskell)
m (Fixed lang tags.)
Line 110: Line 110:
=={{header|C++}}==
=={{header|C++}}==


<lang cpp>
<lang cpp>#include <map>
#include <map>
#include <iostream>
#include <iostream>
#include <cmath>
#include <cmath>
Line 141: Line 140:


return good;
return good;
}</lang>
}
</lang>


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
Line 196: Line 194:


The ''delta'' is given as an optional left argument (<code>x</code>), defaulting to 5%. The right argument (<code>y</code>) is any valid argument to the distribution generating verb.
The ''delta'' is given as an optional left argument (<code>x</code>), defaulting to 5%. The right argument (<code>y</code>) is any valid argument to the distribution generating verb.
<lang j>
<lang j>checkUniform=: adverb define
checkUniform=: adverb define
0.05 u checkUniform y
0.05 u checkUniform y
:
:
Line 208: Line 205:
errmsg assert (delta * expected) > | expected - {:"1 freqtable
errmsg assert (delta * expected) > | expected - {:"1 freqtable
freqtable
freqtable
)</lang>
)
</lang>


It is possible to use tacit expressions within an explicit definition enabling a more functional and concise style:
It is possible to use tacit expressions within an explicit definition enabling a more functional and concise style:
<lang j>checkUniformT=: adverb define
<lang j>
checkUniformT=: adverb define
0.05 u checkUniformT y
0.05 u checkUniformT y
:
:
Line 220: Line 215:
errmsg assert ((n % #) (x&*@[ > |@:-) {:"1) freqtable
errmsg assert ((n % #) (x&*@[ > |@:-) {:"1) freqtable
freqtable
freqtable
)</lang>
)
</lang>


Show usage using <code>rollD7t</code> given in [[Seven-dice from Five-dice#J|Seven-dice from Five-dice]]:
Show usage using <code>rollD7t</code> given in [[Seven-dice from Five-dice#J|Seven-dice from Five-dice]]:


<lang j> 0.05 rollD7t checkUniform 1e5
<lang j>
0.05 rollD7t checkUniform 1e5
1 14082
1 14082
2 14337
2 14337
Line 236: Line 229:
0.05 rollD7t checkUniform 1e2
0.05 rollD7t checkUniform 1e2
|Distribution is potentially skewed: assert
|Distribution is potentially skewed: assert
| errmsg assert(delta*expected)>|expected-{:"1 freqtable
| errmsg assert(delta*expected)>|expected-{:"1 freqtable</lang>
</lang>


=={{header|OCaml}}==
=={{header|OCaml}}==
Line 290: Line 282:


=={{header|R}}==
=={{header|R}}==
<lang r>distcheck <- function(fn, repetitions=1e4, delta=3)
<lang r>
distcheck <- function(fn, repetitions=1e4, delta=3)
{
{
if(is.character(fn))
if(is.character(fn))
Line 310: Line 301:
data.frame(value=names(counts), counts=as.vector(counts), status=status)
data.frame(value=names(counts), counts=as.vector(counts), status=status)
}
}
distcheck(dice7.vec)
distcheck(dice7.vec)</lang>
</lang>


=={{header|Ruby}}==
=={{header|Ruby}}==