package owl-base

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file owl_base_stats_dist_gaussian.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
# 1 "src/base/stats/owl_base_stats_dist_gaussian.ml"
(*
 * OWL - OCaml Scientific and Engineering Computing
 * Copyright (c) 2016-2020 Liang Wang <liang.wang@cl.cam.ac.uk>
 *)

let _u1 = ref 0.

let _u2 = ref 0.

let _case = ref false

let _z0 = ref 0.

let _z1 = ref 1.

let std_gaussian_rvs () =
  if !_case
  then (
    _case := false;
    !_z1)
  else (
    _case := true;
    _u1 := Random.float 1.;
    _u2 := Random.float 1.;
    _z0 := sqrt (~-.2. *. log !_u1) *. cos (2. *. Owl_const.pi *. !_u2);
    _z1 := sqrt (~-.2. *. log !_u1) *. sin (2. *. Owl_const.pi *. !_u2);
    !_z0)


(* TODO: use the polar, is more efficient *)
let gaussian_rvs ~mu ~sigma =
  if !_case
  then (
    _case := false;
    mu +. (sigma *. !_z1))
  else (
    _case := true;
    _u1 := Random.float 1.;
    _u2 := Random.float 1.;
    _z0 := sqrt (~-.2. *. log !_u1) *. cos (2. *. Owl_const.pi *. !_u2);
    _z1 := sqrt (~-.2. *. log !_u1) *. sin (2. *. Owl_const.pi *. !_u2);
    mu +. (sigma *. !_z0))
OCaml

Innovation. Community. Security.