Fixed issue with mixed distributions

This commit is contained in:
Ozzie Gooen 2020-04-03 00:20:58 +01:00
parent 0ef6d106ea
commit 88358470e3
2 changed files with 11 additions and 8 deletions

View File

@ -100,9 +100,9 @@ module T = {
|> E.FloatFloatMap.toArray |> E.FloatFloatMap.toArray
|> XYShape.T.fromZippedArray; |> XYShape.T.fromZippedArray;
let pdf: DistTypes.xyShape = let pdf: DistTypes.xyShape =
continuousPart |> E.A.length > 20 continuousPart |> E.A.length > 5
? { ? {
samples |> KDE.normalSampling(_, outputXYPoints, kernelWidth); continuousPart |> KDE.normalSampling(_, outputXYPoints, kernelWidth);
} }
: {xs: [||], ys: [||]}; : {xs: [||], ys: [||]};
let continuous = pdf |> Distributions.Continuous.make(`Linear); let continuous = pdf |> Distributions.Continuous.make(`Linear);

View File

@ -156,14 +156,17 @@ module MathAdtToDistDst = {
args args
|> E.A.fmap( |> E.A.fmap(
fun fun
| Ok(`Simple(n)) => Some(n) | Ok(`Simple(n)) => Ok(n)
| _ => None, | Error(e) => Error(e)
| _ => Error("Type not supported"),
) )
|> E.A.O.concatSomes; let firstWithError = dists |> Belt.Array.getBy(_, Belt.Result.isError);
switch (dists |> E.A.length) { let withoutErrors = dists |> E.A.fmap(E.R.toOption) |> E.A.O.concatSomes;
| 0 => Error("Multimodals need at least one input") switch (firstWithError ) {
| (Some(Error(e))) => Error(e)
| (None) when (withoutErrors |> E.A.length == 0) => Error("Multimodals need at least one input")
| _ => | _ =>
dists withoutErrors
|> E.A.fmapi((index, item) => |> E.A.fmapi((index, item) =>
(item, weights |> E.A.get(_, index) |> E.O.default(1.0)) (item, weights |> E.A.get(_, index) |> E.O.default(1.0))
) )