diff --git a/ocaml/a.out b/ocaml/a.out deleted file mode 100755 index f7e94012..00000000 Binary files a/ocaml/a.out and /dev/null differ diff --git a/ocaml/makefile b/ocaml/makefile index 2aa5e20d..5ec1ec86 100644 --- a/ocaml/makefile +++ b/ocaml/makefile @@ -7,4 +7,8 @@ CC=ocamlopt SRC=samples.ml build: $(SRC) - $(CC) $(SRC) + $(CC) $(SRC) -o out/samples + mv samples.cmi samples.cmx samples.o ./out/ + +run: + ./out/samples diff --git a/ocaml/out/samples b/ocaml/out/samples new file mode 100755 index 00000000..9c2fc6a0 Binary files /dev/null and b/ocaml/out/samples differ diff --git a/ocaml/out/samples.cmi b/ocaml/out/samples.cmi new file mode 100644 index 00000000..272d172e Binary files /dev/null and b/ocaml/out/samples.cmi differ diff --git a/ocaml/out/samples.cmx b/ocaml/out/samples.cmx new file mode 100644 index 00000000..87479b26 Binary files /dev/null and b/ocaml/out/samples.cmx differ diff --git a/ocaml/out/samples.o b/ocaml/out/samples.o new file mode 100644 index 00000000..238d2f54 Binary files /dev/null and b/ocaml/out/samples.o differ diff --git a/ocaml/samples.cmi b/ocaml/samples.cmi deleted file mode 100644 index 3d9846c6..00000000 Binary files a/ocaml/samples.cmi and /dev/null differ diff --git a/ocaml/samples.ml b/ocaml/samples.ml index 2c432d3b..d326646d 100644 --- a/ocaml/samples.ml +++ b/ocaml/samples.ml @@ -1,5 +1,6 @@ (* Constants *) let pi = acos (-1.) +let normal_95_ci_length = 1.6448536269514722 (* Basic samplers *) let sampleZeroToOne () : float = Random.float 1.0 @@ -8,6 +9,14 @@ let sampleStandardNormal (): float = let u2 = sampleZeroToOne () in let z = sqrt(-2.0 *. log(u1)) *. sin(2.0 *. pi *. u2) in z +let sampleNormal mean std = mean +. std *. (sampleStandardNormal ()) +let sampleLognormal logmean logstd = exp(sampleNormal logmean logstd) +let sampleTo low high = + let loglow = log(low) in + let loghigh = log(high) in + let logmean = (loglow +. loghigh) /. 2.0 in + let logstd = (loghigh -. loglow) /. (2.0 -. normal_95_ci_length ) in + sampleLognormal logmean logstd let () = Random.init 1;