start populating samplers

This commit is contained in:
NunoSempere 2023-10-14 20:12:42 +01:00
parent e9bfd1f2ed
commit ffec4663fc
8 changed files with 14 additions and 1 deletions

Binary file not shown.

View File

@ -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

BIN
ocaml/out/samples Executable file

Binary file not shown.

BIN
ocaml/out/samples.cmi Normal file

Binary file not shown.

BIN
ocaml/out/samples.cmx Normal file

Binary file not shown.

BIN
ocaml/out/samples.o Normal file

Binary file not shown.

Binary file not shown.

View File

@ -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;