From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 81D757F988 for ; Sun, 29 Jun 2014 13:11:50 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of interlock.public@gmail.com) identity=pra; client-ip=209.85.220.195; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="interlock.public@gmail.com"; x-sender="interlock.public@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of interlock.public@gmail.com designates 209.85.220.195 as permitted sender) identity=mailfrom; client-ip=209.85.220.195; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="interlock.public@gmail.com"; x-sender="interlock.public@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-vc0-f195.google.com) identity=helo; client-ip=209.85.220.195; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="interlock.public@gmail.com"; x-sender="postmaster@mail-vc0-f195.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkQIACXzr1PRVdzDlGdsb2JhbABagkaBGVqCboEcpwMBBpJ1AYZsU4EBCBYPAQEBAQcLCwkSKoQcER0BGx4DEhA3AiQBEQEFASI1iAsBAxENmgaDEmqLJ4FygxCQLAoZJw1khW4RAQEEDYVXiR+CQQ8yEoE6BZpekgwYKYRzPA X-IPAS-Result: AkQIACXzr1PRVdzDlGdsb2JhbABagkaBGVqCboEcpwMBBpJ1AYZsU4EBCBYPAQEBAQcLCwkSKoQcER0BGx4DEhA3AiQBEQEFASI1iAsBAxENmgaDEmqLJ4FygxCQLAoZJw1khW4RAQEEDYVXiR+CQQ8yEoE6BZpekgwYKYRzPA X-IronPort-AV: E=Sophos;i="5.01,570,1400018400"; d="scan'208";a="69439672" Received: from mail-vc0-f195.google.com ([209.85.220.195]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 29 Jun 2014 13:11:49 +0200 Received: by mail-vc0-f195.google.com with SMTP id id10so1731418vcb.10 for ; Sun, 29 Jun 2014 04:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=n7mIGFr6WcbS9Q36eVYzB3EZy+Yib14TBQfHfBBC3N8=; b=cEBOq60MtKplz3JSjIYg8eRNdgOxHqWFbqVXammmNO9LTgT2vJebml2UlmgNLaWd7z 6gmdRYAOwo8G3Zl9Ed2vPOuky+AfbBWcOCv7IML+dZkmUhMjlD6ENydJIueOr3lZCC9D nmDgZtZOIk6OFVSePYy42w6xkhpxD5auUV08EcmDppl7q0setOO0AoqpOtFTwKsk/VgD FLrWoQVCOWoKZgTEssSQp0zAXze+KWvWSJVjKBV1f+bvFv+AmTYlpDMu2xwoX0IDM1iZ FLXfqvGZxeFYPWu8Vm1MDdg2alQG09180MwQzuCpKZibHaUdlVFz6uXB64BDUXDfiM9X LSlg== MIME-Version: 1.0 X-Received: by 10.52.69.172 with SMTP id f12mr26856663vdu.26.1404040308060; Sun, 29 Jun 2014 04:11:48 -0700 (PDT) Received: by 10.221.45.130 with HTTP; Sun, 29 Jun 2014 04:11:48 -0700 (PDT) Date: Sun, 29 Jun 2014 12:11:48 +0100 Message-ID: From: Dan Stark To: OCaml Mailing List Content-Type: multipart/alternative; boundary=20cf307cffd6cff7b804fcf79b44 Subject: [Caml-list] How does OCaml std test Random --20cf307cffd6cff7b804fcf79b44 Content-Type: text/plain; charset=UTF-8 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 --20cf307cffd6cff7b804fcf79b44 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi all

I am looking at the source of Ra= ndom module=C2=A0


I found that it is tested via chi-square test, he= re is the test code inside:


(* Return th= e sum of the squares of v[i0,i1[ *)
let re= c sumsq v i0 i1 =3D
if i0 >=3D i1 then 0.0
else if i1= =3D i0 + 1 then Pervasives.float v.(i0) *. Pervasives.float v.(i0)<= /span>
else sumsq= v i0 ((i0+i1)/2) +. sumsq v ((i0+i1)/2) i1
;;

let ch= isquare g n r =3D
if n <=3D 10 * r then invalid_arg "chisq= uare";
let f =3D = Array.make r 0 in
for = i =3D 1 to n do
<= font color=3D"#444444"> let t =3D g r in
f.(t) &l= t;- f.(t) + 1
done= ;
let t =3D sumsq f 0 r
and r =3D = Pervasives.float r
and = n =3D Pervasives.float n in
let sr =3D 2.0 *. sqrt r in
(r -. sr, = (r *. t /. n) -. n, r +. sr)
;;

I understand how the chi-sq= uare is calculated there.

What I don't underst= and is this comment:

(* Test= functions. Not included in the library.
The [chisqu= are] function should be called with n > 10r.
It return= s a triple (low, actual, high).
If low &l= t;=3D actual <=3D high, the [g] function passed the test,<= /div>
oth= erwise it failed.
*)

From my knowledge, if I get a chi-square va= lue, I should check it against a table with the degree of freedom and then = decide whether the null hypothesis fails or not.

Why=C2=A0(r -. sr, (r *. t /. n) -. n, r +. sr)<= /span>=C2=A0can be used to check? What's the theory behind?=C2=A0

thanks

Dan

--20cf307cffd6cff7b804fcf79b44--