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
|> 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);

View File

@ -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))
)