From 3226e20fffaacd836e05d044bebb913c572f8b8a Mon Sep 17 00:00:00 2001 From: Leonid Rozenberg Date: Wed, 2 Mar 2016 11:57:56 -0500 Subject: [PATCH] Fix the tests --- src/lib/stats/distributions_t.ml | 24 ++++++++++-------------- src/lib/stats/hypothesis_test_t.ml | 4 ++-- src/lib/unc/functions_t.ml | 3 ++- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/lib/stats/distributions_t.ml b/src/lib/stats/distributions_t.ml index b12ca7b..a8f2569 100644 --- a/src/lib/stats/distributions_t.ml +++ b/src/lib/stats/distributions_t.ml @@ -18,6 +18,7 @@ open Test_utils open Util open Statistics.Distributions +module P = Probability let () = let add_random_test @@ -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]); @@ -67,7 +61,7 @@ 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 @@ -75,8 +69,8 @@ let () = ~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 ]); @@ -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 ]); diff --git a/src/lib/stats/hypothesis_test_t.ml b/src/lib/stats/hypothesis_test_t.ml index f60a762..c631ce2 100644 --- a/src/lib/stats/hypothesis_test_t.ml +++ b/src/lib/stats/hypothesis_test_t.ml @@ -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 @@ -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 diff --git a/src/lib/unc/functions_t.ml b/src/lib/unc/functions_t.ml index 5ebb521..d470f85 100644 --- a/src/lib/unc/functions_t.ml +++ b/src/lib/unc/functions_t.ml @@ -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 = @@ -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