Commit 9aaf878a authored by Philippe Veber's avatar Philippe Veber
Browse files

prc: added visual checks

parent dd0615ff
...@@ -70,7 +70,9 @@ let%expect_test "performance curve 1" = ...@@ -70,7 +70,9 @@ let%expect_test "performance curve 1" =
(0 ((tp 2) (tn 0) (fp 3) (fn 0))))"] (0 ((tp 2) (tn 0) (fp 3) (fn 0))))"]
let recall ~tp ~fn = float tp /. float (tp + fn) let recall ~tp ~fn = float tp /. float (tp + fn)
let precision ~tp ~fp = float tp /. float (tp + fp) let precision ~tp ~fp =
if tp + fp = 0 then 1.
else float tp /. float (tp + fp)
module Precision_recall = struct module Precision_recall = struct
let operating_points d = let operating_points d =
...@@ -259,3 +261,56 @@ module Plot = struct ...@@ -259,3 +261,56 @@ module Plot = struct
~xlim:(0., 1.) ~ylim:(0., 1.) ~x:[||] ~y:[||] () ; ~xlim:(0., 1.) ~ylim:(0., 1.) ~x:[||] ~y:[||] () ;
List.(iter (rev curves)) ~f:plot_curve List.(iter (rev curves)) ~f:plot_curve
end end
module Check = struct
let binormal_simulation ?(sigma = 1.) ?(alpha = 0.1) ?(sample_size = 30) () =
let open OCamlR_base in
let rng = Rng.(make (default ())) in
let p = Binormal_model.make ~sigma_pos:sigma ~sigma_neg:sigma alpha in
let samples = List.init 1_000 ~f:(fun _ -> Binormal_model.simulation ~n:sample_size rng p) in
let compute f =
List.map samples ~f
|> Numeric.of_list
|> Numeric.to_sexp
in
let trapezoidal_lt = compute Precision_recall.auc_trapezoidal_lt in
let average_precision = compute Precision_recall.auc_average_precision in
let binormal = compute (fun sample -> Binormal_model.auc (Binormal_model.estimate sample)) in
let l = List_.create [
Some "binormal", binormal ;
Some "trapezoidal", trapezoidal_lt ;
Some "average_precision", average_precision ;
]
in
OCamlR_graphics.list_boxplot l
let discrete_simulation ?(sample_size = 30) ?support:(d = 10) ?(alpha = 0.1) () =
let open OCamlR_base in
let rng = Rng.(make (default ())) in
let xs = Array.init d ~f:(fun _ -> Randist.flat rng ~a:0. ~b:1.) in
let simulate () =
Dataset (
List.init sample_size ~f:(fun _ ->
let k = Rng.uniform_int rng d in
let b = Float.(Randist.flat rng ~a:0. ~b:1. < xs.(k) *. alpha /. 2.) in
xs.(k), b
)
)
in
let samples = List.init 1_000 ~f:(fun _ -> simulate ()) in
let compute f =
List.map samples ~f
|> Numeric.of_list
|> Numeric.to_sexp
in
let trapezoidal_lt = compute Precision_recall.auc_trapezoidal_lt in
let average_precision = compute Precision_recall.auc_average_precision in
let binormal = compute (fun sample -> Binormal_model.auc (Binormal_model.estimate sample)) in
let l = List_.create [
Some "binormal", binormal ;
Some "trapezoidal", trapezoidal_lt ;
Some "average_precision", average_precision ;
]
in
OCamlR_graphics.list_boxplot l
end
...@@ -110,3 +110,19 @@ module Plot : sig ...@@ -110,3 +110,19 @@ module Plot : sig
t list -> t list ->
unit unit
end end
module Check : sig
val binormal_simulation :
?sigma:float ->
?alpha:float ->
?sample_size:int ->
unit ->
unit
val discrete_simulation :
?sample_size:int ->
?support:int ->
?alpha:float ->
unit ->
unit
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment