start adding mixture function
This commit is contained in:
parent
ffec4663fc
commit
2cddf557bf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -2,6 +2,17 @@
|
|||
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 normalizeXs xs = let sum_xs = sumFloats xs in
|
||||
List.map(fun x -> x /. sum_xs) xs
|
||||
let cumsumXs xs =
|
||||
let _, cum_sum = List.fold_left(fun (sum, ys) x ->
|
||||
let new_sum = sum +. x in
|
||||
new_sum, ys @ [new_sum]
|
||||
) (0.0, []) xs in
|
||||
cum_sum
|
||||
|
||||
(* Basic samplers *)
|
||||
let sampleZeroToOne () : float = Random.float 1.0
|
||||
let sampleStandardNormal (): float =
|
||||
|
@ -17,6 +28,11 @@ let sampleTo low high =
|
|||
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
|
||||
| false -> None
|
||||
| true -> let normalized_weights = cumsumXs (normalizeXs weights) in Some(1.0)
|
||||
|
||||
|
||||
let () =
|
||||
Random.init 1;
|
||||
|
|
Loading…
Reference in New Issue
Block a user