-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_logistic.ml
59 lines (47 loc) · 1.48 KB
/
test_logistic.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
open Logistic
let bench () =
let n = 1_000_000 in
let y = Array.init n (fun _ -> if Random.bool () then 1.0 else -1.0) in
let p = create y in
let set = [| (* TODO *) |] in
let best_split = update p set in
let gamma = Array.init n (fun _ -> (Random.float 2.0) -. 1.0) in
let result = boost p gamma in
if result = `NaN then
failwith "result is NaN";
let rec run ~set_density ~feature_density =
let feature_d =
let b = Utils.rand_bools feature_density n in
BV7.decoded_of_bools b in
let feature = BV7.encode feature_d in
let _, t_bs = Utils.time (fun () -> best_split feature) in
Printf.printf " % .5f % .5f % .5f %1.6f\n%!"
set_density
feature_density
(BV7.density feature_d)
t_bs;
t_bs
in
let num_trials = 10 in
let rec n_run ~set_density ~feature_density i sum_time =
if i = num_trials then
sum_time /. (float num_trials)
else
let t = run ~set_density ~feature_density in
let sum_time = t +. sum_time in
n_run ~set_density ~feature_density (i+1) sum_time
in
let n_run ~set_density ~feature_density =
n_run ~set_density ~feature_density 0 0.0
in
let densities = [0.5; 0.1; 0.02; 0.004; 0.0008] in
List.iter (
fun set_density ->
List.iter (
fun feature_density ->
let t = n_run ~set_density ~feature_density in
Printf.printf ">> % .5f % .5f %1.6f \n" set_density feature_density t
) densities
) densities
let _ =
bench ()