Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
VEBER Philippe
codepi
Commits
9aaf878a
Commit
9aaf878a
authored
Dec 02, 2020
by
Philippe Veber
Browse files
prc: added visual checks
parent
dd0615ff
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
1 deletion
+72
-1
lib/prc/prc.ml
lib/prc/prc.ml
+56
-1
lib/prc/prc.mli
lib/prc/prc.mli
+16
-0
No files found.
lib/prc/prc.ml
View file @
9aaf878a
...
...
@@ -70,7 +70,9 @@ let%expect_test "performance curve 1" =
(0 ((tp 2) (tn 0) (fp 3) (fn 0))))"
]
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
let
operating_points
d
=
...
...
@@ -259,3 +261,56 @@ module Plot = struct
~
xlim
:
(
0
.,
1
.
)
~
ylim
:
(
0
.,
1
.
)
~
x
:
[
||
]
~
y
:
[
||
]
()
;
List
.(
iter
(
rev
curves
))
~
f
:
plot_curve
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
lib/prc/prc.mli
View file @
9aaf878a
...
...
@@ -110,3 +110,19 @@ module Plot : sig
t
list
->
unit
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment