From: Dan Stark <interlock.public@gmail.com>
To: OCaml Mailing List <caml-list@inria.fr>
Subject: [Caml-list] How does OCaml std test Random
Date: Sun, 29 Jun 2014 12:11:48 +0100 [thread overview]
Message-ID: <CANQp=sT3a+1LynnsGfOhP0kF7K6B2-PN9A4YMqTci13j6G=fpg@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1366 bytes --]
Hi all
I am looking at the source of Random module
https://github.com/ocaml/ocaml/blob/master/stdlib/random.ml
I found that it is tested via chi-square test, here is the test code inside:
(* Return the sum of the squares of v[i0,i1[ *)
let rec sumsq v i0 i1 =
if i0 >= i1 then 0.0
else if i1 = i0 + 1 then Pervasives.float v.(i0) *. Pervasives.float v.(i0)
else sumsq v i0 ((i0+i1)/2) +. sumsq v ((i0+i1)/2) i1
;;
let chisquare g n r =
if n <= 10 * r then invalid_arg "chisquare";
let f = Array.make r 0 in
for i = 1 to n do
let t = g r in
f.(t) <- f.(t) + 1
done;
let t = sumsq f 0 r
and r = Pervasives.float r
and n = Pervasives.float n in
let sr = 2.0 *. sqrt r in
(r -. sr, (r *. t /. n) -. n, r +. sr)
;;
I understand how the chi-square is calculated there.
What I don't understand is this comment:
(* Test functions. Not included in the library.
The [chisquare] function should be called with n > 10r.
It returns a triple (low, actual, high).
If low <= actual <= high, the [g] function passed the test,
otherwise it failed.
*)
From my knowledge, if I get a chi-square value, I should check it against a
table with the degree of freedom and then decide whether the null
hypothesis fails or not.
Why (r -. sr, (r *. t /. n) -. n, r +. sr) can be used to check? What's the
theory behind?
thanks
Dan
[-- Attachment #2: Type: text/html, Size: 6472 bytes --]
next reply other threads:[~2014-06-29 11:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-29 11:11 Dan Stark [this message]
2014-07-02 19:42 ` Damien Doligez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CANQp=sT3a+1LynnsGfOhP0kF7K6B2-PN9A4YMqTci13j6G=fpg@mail.gmail.com' \
--to=interlock.public@gmail.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox