commit 4983699308398ab9cad624e2cb12b0bb57e821d3 parent ce119253b7af4003ca9dc5f634bbfd9e8da06fe6 Author: NunoSempere <nuno.sempere@protonmail.com> Date: Sun, 15 Oct 2023 00:01:05 +0100 tweak: delete higher level match in mixture function Diffstat:
| M | ocaml/out/samples | | | 0 | |
| M | ocaml/out/samples.cmi | | | 0 | |
| M | ocaml/out/samples.cmx | | | 0 | |
| M | ocaml/out/samples.o | | | 0 | |
| M | ocaml/samples.ml | | | 25 | ++++++++++++------------- |
5 files changed, 12 insertions(+), 13 deletions(-)
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.ml b/ocaml/samples.ml @@ -41,20 +41,19 @@ let sampleTo low high = let logstd = (loghigh -. loglow) /. (2.0 -. normal_95_ci_length ) in sampleLognormal logmean logstd -let (|>) x f = f x let mixture (samplers: (unit -> float) array) (weights: float array): float option = - 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 p = sampleZeroToOne () in - let chosenSamplerIndex = findIndex cumsummed_normalized_weights (fun x -> x < p) in - let sample = match chosenSamplerIndex with - | None -> None - | Some(i) -> Some(samplers.(i) ()) - in - sample + if (Array.length samplers == Array.length weights) + then None + else + let normalized_weights = normalizeXs weights in + let cumsummed_normalized_weights = cumsumXs normalized_weights in + let p = sampleZeroToOne () in + let chosenSamplerIndex = findIndex cumsummed_normalized_weights (fun x -> x < p) in + let sample = match chosenSamplerIndex with + | None -> None + | Some(i) -> Some (samplers.(i) ()) + in + sample let () = Random.init 1;