start populating samplers
This commit is contained in:
parent
e9bfd1f2ed
commit
ffec4663fc
BIN
ocaml/a.out
BIN
ocaml/a.out
Binary file not shown.
|
@ -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
BIN
ocaml/out/samples
Executable file
Binary file not shown.
BIN
ocaml/out/samples.cmi
Normal file
BIN
ocaml/out/samples.cmi
Normal file
Binary file not shown.
BIN
ocaml/out/samples.cmx
Normal file
BIN
ocaml/out/samples.cmx
Normal file
Binary file not shown.
BIN
ocaml/out/samples.o
Normal file
BIN
ocaml/out/samples.o
Normal file
Binary file not shown.
Binary file not shown.
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user