From 88358470e3c2e3cadf972b2368fb25d66b1bec93 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Fri, 3 Apr 2020 00:20:58 +0100 Subject: [PATCH] Fixed issue with mixed distributions --- src/Samples.re | 4 ++-- src/symbolic/MathJsParser.re | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Samples.re b/src/Samples.re index 7f7fd61d..8ccd178c 100644 --- a/src/Samples.re +++ b/src/Samples.re @@ -100,9 +100,9 @@ module T = { |> E.FloatFloatMap.toArray |> XYShape.T.fromZippedArray; 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: [||]}; let continuous = pdf |> Distributions.Continuous.make(`Linear); diff --git a/src/symbolic/MathJsParser.re b/src/symbolic/MathJsParser.re index fc86d7d6..f1b75549 100644 --- a/src/symbolic/MathJsParser.re +++ b/src/symbolic/MathJsParser.re @@ -156,14 +156,17 @@ module MathAdtToDistDst = { args |> E.A.fmap( fun - | Ok(`Simple(n)) => Some(n) - | _ => None, + | Ok(`Simple(n)) => Ok(n) + | Error(e) => Error(e) + | _ => Error("Type not supported"), ) - |> E.A.O.concatSomes; - switch (dists |> E.A.length) { - | 0 => Error("Multimodals need at least one input") + let firstWithError = dists |> Belt.Array.getBy(_, Belt.Result.isError); + let withoutErrors = dists |> E.A.fmap(E.R.toOption) |> E.A.O.concatSomes; + 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) => (item, weights |> E.A.get(_, index) |> E.O.default(1.0)) )