diff --git a/ocaml/out/samples b/ocaml/out/samples index 8894eb80..68868270 100755 Binary files a/ocaml/out/samples and b/ocaml/out/samples differ diff --git a/ocaml/out/samples.cmi b/ocaml/out/samples.cmi index 206bf915..484674c5 100644 Binary files a/ocaml/out/samples.cmi and b/ocaml/out/samples.cmi differ diff --git a/ocaml/out/samples.cmx b/ocaml/out/samples.cmx index ac1d98bb..afdc5d87 100644 Binary files a/ocaml/out/samples.cmx and b/ocaml/out/samples.cmx differ diff --git a/ocaml/out/samples.o b/ocaml/out/samples.o index e25be8e9..61a5f516 100644 Binary files a/ocaml/out/samples.o and b/ocaml/out/samples.o differ diff --git a/ocaml/samples.ml b/ocaml/samples.ml index 11939124..15eef8ee 100644 --- a/ocaml/samples.ml +++ b/ocaml/samples.ml @@ -3,12 +3,12 @@ let pi = acos (-1.) let normal_95_ci_length = 1.6448536269514722 (* Array manipulation helpers *) -let sumFloats xs = List.fold_left(fun acc x -> acc +. x) 0.0 xs +let sumFloats xs = Array.fold_left(fun acc x -> acc +. x) 0.0 xs let normalizeXs xs = let sum_xs = sumFloats xs in - List.map(fun x -> x /. sum_xs) xs + Array.map(fun x -> x /. sum_xs) xs let cumsumXs xs = - let _, cum_sum = List.fold_left(fun (sum, ys) x -> + let _, cum_sum = Array.fold_left(fun (sum, ys) x -> let new_sum = sum +. x in new_sum, ys @ [new_sum] ) (0.0, []) xs in @@ -16,27 +16,32 @@ let cumsumXs xs = (* Basic samplers *) let sampleZeroToOne () : float = Random.float 1.0 + let sampleStandardNormal (): float = let u1 = sampleZeroToOne () in 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 mixture (samplers: (unit -> float) list) (weights: float list) = - match (List.length samplers == List.length weights) with + +let mixture (samplers: (unit -> float) array) (weights: float array) = + match (Array.length samplers == Array.length weights) with | false -> None | true -> let normalized_weights = normalizeXs weights in let cumsummed_normalized_weights = cumsumXs normalized_weights in + let answer = 1.1 in Some(1.0) - let () = Random.init 1;