package oranger

  1. Overview
  2. Docs
OCaml wrapper for the ranger (C++) random forests implementation

Install

Dune Dependency

Authors

Maintainers

Sources

v2.0.1.tar.gz
sha256=fb2904afad279709a8baa1a2037e8f2f8c572a159acaacae00d79887c84401ff
md5=c3b3d20f9adf1a6a784a041282c9fe33

doc/src/oranger/utls.ml.html

Source file utls.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

module L = BatList

let with_in_file fn f =
  let input = open_in_bin fn in
  let res = f input in
  close_in input;
  res

let with_out_file fn f =
  let output = open_out_bin fn in
  let res = f output in
  close_out output;
  res

(* population standard deviation *)
let stddev (l: float list) =
  let n, sx, sx2 =
    List.fold_left (fun (n, sx, sx2) x ->
        (n +. 1., sx +. x, sx2 +. (x *.x))
      ) (0., 0., 0.) l
  in
  sqrt ((sx2 -. (sx *. sx) /. n) /. n)
(* stddev [2.; 4.; 4.; 4.; 5.; 5.; 7.; 9.] = 2.0 *)

let lines_of_file fn =
  with_in_file fn (fun input ->
      let res, exn = L.unfold_exc (fun () -> input_line input) in
      if exn <> End_of_file then
        raise exn
      else res
    )

let filter_lines_of_file fn p =
  L.filter p (lines_of_file fn)
OCaml

Innovation. Community. Security.