Anonymous user
Verify distribution uniformity/Naive: Difference between revisions
Verify distribution uniformity/Naive (view source)
Revision as of 00:57, 22 November 2009
, 14 years agoFixed lang tags.
(added Haskell) |
m (Fixed lang tags.) |
||
Line 110:
=={{header|C++}}==
<lang cpp>#include <map>
#include <iostream>
#include <cmath>
Line 141 ⟶ 140:
return good;
}</lang>▼
▲</lang>
=={{header|Common Lisp}}==
Line 196 ⟶ 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.
<lang j>checkUniform=: adverb define
0.05 u checkUniform y
:
Line 208 ⟶ 205:
errmsg assert (delta * expected) > | expected - {:"1 freqtable
freqtable
)</lang>▼
▲</lang>
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
:
Line 220 ⟶ 215:
errmsg assert ((n % #) (x&*@[ > |@:-) {:"1) freqtable
freqtable
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▼
▲ 0.05 rollD7t checkUniform 1e5
1 14082
2 14337
Line 236 ⟶ 229:
0.05 rollD7t checkUniform 1e2
|Distribution is potentially skewed: assert
| errmsg assert(delta*expected)>|expected-{:"1 freqtable</lang>
=={{header|OCaml}}==
Line 290 ⟶ 282:
=={{header|R}}==
<lang r>distcheck <- function(fn, repetitions=1e4, delta=3)▼
▲distcheck <- function(fn, repetitions=1e4, delta=3)
{
if(is.character(fn))
Line 310 ⟶ 301:
data.frame(value=names(counts), counts=as.vector(counts), status=status)
}
distcheck(dice7.vec)</lang>
=={{header|Ruby}}==
|