savepoint while wrangling types

This commit is contained in:
NunoSempere 2023-10-14 23:48:11 +01:00
parent 23bd623b66
commit fb21e4baa6
5 changed files with 14 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,6 +13,13 @@ let cumsumXs xs =
new_sum, ys @ [new_sum] new_sum, ys @ [new_sum]
) (0.0, []) xs in ) (0.0, []) xs in
cum_sum cum_sum
let findIndex xs test =
let rec recursiveHelper ys i =
match ys with
| [] -> None
| z :: zs -> if test z then Some i else recursiveHelper zs (i+1)
in
recursiveHelper xs 0
(* Basic samplers *) (* Basic samplers *)
let sampleZeroToOne () : float = Random.float 1.0 let sampleZeroToOne () : float = Random.float 1.0
@ -40,8 +47,13 @@ let mixture (samplers: (unit -> float) array) (weights: float array) =
| true -> | true ->
let normalized_weights = normalizeXs weights in let normalized_weights = normalizeXs weights in
let cumsummed_normalized_weights = cumsumXs normalized_weights in let cumsummed_normalized_weights = cumsumXs normalized_weights in
let answer = 1.1 in let p = sampleZeroToOne () in
Some(1.0) let chosenSamplerIndex = findIndex cumsummed_normalized_weights (fun x -> x < p) in
let sample = match chosenSamplerIndex with
| None -> None
| Some(i) -> Some(1.0) (* (samplers.(i) ()) |> Some *)
in
sample
let () = let () =
Random.init 1; Random.init 1;