Skip to content

Commit

Permalink
Fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rleonid committed Apr 14, 2016
1 parent 09593d7 commit 3226e20
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
24 changes: 10 additions & 14 deletions src/lib/stats/distributions_t.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
open Test_utils
open Util
open Statistics.Distributions
module P = Probability

let () =
let add_random_test
Expand All @@ -43,21 +44,14 @@ let () =
~title:"Normal_cdf is between 0 and 1."
Gen.(zip3 mean_o std_o (make_float (-1e1) (1e1)))
(fun (mean,std,x) ->
within (Closed 0.0, Closed 1.0) (normal_cdf ?mean ?std x))
Spec.([just_postcond_pred is_true]);

add_random_test
~title:"Normal_df is also bounded."
Gen.(zip3 mean_o std_o (bfloat max_float))
(fun (mean,std,x) ->
within (Closed 0.0, Closed 1.0) (normal_pdf ?mean ?std x))
within (Closed 0.0, Closed 1.0) (normal_cdf ?mean ?std x :> float))
Spec.([just_postcond_pred is_true]);

add_random_test
~title:"Normal_quantile works."
Gen.(zip3 mean_o std_o (make_float 0.0 1.0))
(fun (mean,std,p) ->
let _ = normal_quantile ?mean ?std p in
let _ = normal_quantile ?mean ?std (P.restrict p) in
true (* TODO *))
Spec.([just_postcond_pred is_true]);

Expand All @@ -67,16 +61,16 @@ let () =
Gen.(make_float 0. 1.)
(fun weight ->
let result = beta_cdf weight in
not (significantly_different_from weight result))
not (significantly_different_from weight (result :> float)))
Spec.([just_postcond_pred is_true]);

let prob f = Spec.(zip3 f always always) in
add_partial_random_test
~title:"Normal_cdf and normal_quantile are inverses."
Gen.(zip3 (make_float (-0.5) 1.5) (make_float (-100.) 100.) (make_float (-100.) 100.))
(fun (p, mean, std) ->
let pp = normal_cdf ~mean ~std (normal_quantile ~mean ~std p) in
equal_floats ~d:1e-9 pp p)
let pp = normal_cdf ~mean ~std (normal_quantile ~mean ~std (P.restrict p)) in
equal_floats ~d:1e-9 (pp :> float) p)
Spec.([ prob (fun p -> p < 0.0 || p > 1.0) ==> is_exception is_invalid_arg
; prob (fun p -> p >= 0.0 && p <= 1.0) ==> is_result is_true
]);
Expand All @@ -86,8 +80,10 @@ let () =
~title:"Student_cdf and student_quantile are inverses."
Gen.(zip2 (make_float (-0.5) 1.5) (make_int 1 1000))
(fun (p, degrees_of_freedom) ->
let pp = student_cdf ~degrees_of_freedom (student_quantile ~degrees_of_freedom p) in
equal_floats ~d:1e-6 pp p)
let pp = student_cdf ~degrees_of_freedom
(student_quantile ~degrees_of_freedom (P.restrict p))
in
equal_floats ~d:1e-6 (pp :> float) p)
Spec.([ prob (fun p -> p < 0.0 || p > 1.0) ==> is_exception is_invalid_arg
; prob (fun p -> p >= 0.0 && p <= 1.0) ==> is_result is_true
]);
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stats/hypothesis_test_t.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let () =
let t = chi obs exp in
equalf 3.0 t.degrees_of_freedom;
equalf 0.470023980815 t.statistic;
equalf 0.925425895104 t.prob_by_chance);
equalf 0.925425895104 (t.prob_by_chance :> float));

let data =
[| 102.319612; 89.168824; 102.688238; 92.326973; 104.518277; 98.503768
Expand All @@ -46,7 +46,7 @@ let () =
equalf tst.degrees_of_freedom df;
equalf tst.statistic st;
equalf tst.standard_error se;
equalf tst.prob_by_chance pc;
equalf (tst.prob_by_chance :> float) pc;
in
(* Tested against http://vassarstats.net/ *)
add_simple_test
Expand Down
3 changes: 2 additions & 1 deletion src/lib/unc/functions_t.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ open Test_utils
open Printf
open Util
open Uncategorized.Functions
module P = Probability

let fac i =
let rec loop a i =
Expand Down Expand Up @@ -124,7 +125,7 @@ let () =
~title:"Softmax obeys bounds"
Gen.(zip2 temp_opt (array (make_int 0 100) (bfloat max_float)))
(fun (temperature, weights) ->
let _ = softmax ?temperature weights in
let _ = P.softmax ?temperature weights in
true)
Spec.([ bad_spec ==> is_exception is_invalid_arg
; not bad_spec ==> is_result is_true
Expand Down

0 comments on commit 3226e20

Please sign in to comment.