commit ffec4663fc601750b72de1d0768dcf1db10449fe parent e9bfd1f2edaf55130e7643fa761a25a434ac0bce Author: NunoSempere <nuno.sempere@protonmail.com> Date: Sat, 14 Oct 2023 20:12:42 +0100 start populating samplers Diffstat:
| D | ocaml/a.out | | | 0 | |
| M | ocaml/makefile | | | 6 | +++++- |
| A | ocaml/out/samples | | | 0 | |
| A | ocaml/out/samples.cmi | | | 0 | |
| A | ocaml/out/samples.cmx | | | 0 | |
| A | ocaml/out/samples.o | | | 0 | |
| D | ocaml/samples.cmi | | | 0 | |
| M | ocaml/samples.ml | | | 9 | +++++++++ |
8 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/ocaml/a.out b/ocaml/a.out Binary files differ. diff --git 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 Binary files differ. diff --git a/ocaml/out/samples.cmi b/ocaml/out/samples.cmi Binary files differ. diff --git a/ocaml/out/samples.cmx b/ocaml/out/samples.cmx Binary files differ. diff --git a/ocaml/out/samples.o b/ocaml/out/samples.o Binary files differ. diff --git a/ocaml/samples.cmi b/ocaml/samples.cmi Binary files differ. diff --git 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;