Fixes of multimodals
This commit is contained in:
parent
7ab81249bf
commit
db78bc07f3
|
@ -77,7 +77,7 @@ let make = () => {
|
||||||
~validationStrategy=OnDemand,
|
~validationStrategy=OnDemand,
|
||||||
~schema,
|
~schema,
|
||||||
~onSubmit=({state}) => {None},
|
~onSubmit=({state}) => {None},
|
||||||
~initialState={guesstimatorString: "mm(1 to 1000)"},
|
~initialState={guesstimatorString: "mm(1 to 100, 50 to 200, [.5,.5])"},
|
||||||
(),
|
(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,7 @@ module MathAdtToDistDst = {
|
||||||
fun
|
fun
|
||||||
| Fn({name: "multiply", args: [|Value(f), Symbol(s)|]}) =>
|
| Fn({name: "multiply", args: [|Value(f), Symbol(s)|]}) =>
|
||||||
Value(transformWithSymbol(f, s))
|
Value(transformWithSymbol(f, s))
|
||||||
| Fn({name: "unaryMinus", args: [|Value(f)|]}) =>
|
| Fn({name: "unaryMinus", args: [|Value(f)|]}) => Value((-1.0) *. f)
|
||||||
Value(-1.0 *. f)
|
|
||||||
| Fn({name, args}) => Fn({name, args: args |> E.A.fmap(run)})
|
| Fn({name, args}) => Fn({name, args: args |> E.A.fmap(run)})
|
||||||
| Array(args) => Array(args |> E.A.fmap(run))
|
| Array(args) => Array(args |> E.A.fmap(run))
|
||||||
| Symbol(s) => Symbol(s)
|
| Symbol(s) => Symbol(s)
|
||||||
|
@ -114,7 +113,7 @@ module MathAdtToDistDst = {
|
||||||
Ok(`Simple(SymbolicDist.Lognormal.from90PercentCI(low, high)));
|
Ok(`Simple(SymbolicDist.Lognormal.from90PercentCI(low, high)));
|
||||||
}
|
}
|
||||||
| [|Value(low), _|] when low <= 0.0 => {
|
| [|Value(low), _|] when low <= 0.0 => {
|
||||||
Error("Low value cannot be less than 0.")
|
Error("Low value cannot be less than 0.");
|
||||||
}
|
}
|
||||||
| [|Value(_), Value(_)|] =>
|
| [|Value(_), Value(_)|] =>
|
||||||
Error("Low value must be less than high value.")
|
Error("Low value must be less than high value.")
|
||||||
|
@ -150,21 +149,23 @@ module MathAdtToDistDst = {
|
||||||
let multiModal =
|
let multiModal =
|
||||||
(
|
(
|
||||||
args: array(result(SymbolicDist.bigDist, string)),
|
args: array(result(SymbolicDist.bigDist, string)),
|
||||||
weights: array(float),
|
weights: option(array(float)),
|
||||||
) => {
|
) => {
|
||||||
|
let weights = weights |> E.O.default([||]);
|
||||||
let dists =
|
let dists =
|
||||||
args
|
args
|
||||||
|> E.A.fmap(
|
|> E.A.fmap(
|
||||||
fun
|
fun
|
||||||
| Ok(`Simple(n)) => Ok(n)
|
| Ok(`Simple(n)) => Ok(n)
|
||||||
| Error(e) => Error(e)
|
| Error(e) => Error(e)
|
||||||
| _ => Error("Type not supported"),
|
| Ok(k) => Error(SymbolicDist.toString(k)),
|
||||||
)
|
);
|
||||||
let firstWithError = dists |> Belt.Array.getBy(_, Belt.Result.isError);
|
let firstWithError = dists |> Belt.Array.getBy(_, Belt.Result.isError);
|
||||||
let withoutErrors = dists |> E.A.fmap(E.R.toOption) |> E.A.O.concatSomes;
|
let withoutErrors = dists |> E.A.fmap(E.R.toOption) |> E.A.O.concatSomes;
|
||||||
switch (firstWithError ) {
|
switch (firstWithError) {
|
||||||
| (Some(Error(e))) => Error(e)
|
| Some(Error(e)) => Error(e)
|
||||||
| (None) when (withoutErrors |> E.A.length == 0) => Error("Multimodals need at least one input")
|
| None when withoutErrors |> E.A.length == 0 =>
|
||||||
|
Error("Multimodals need at least one input")
|
||||||
| _ =>
|
| _ =>
|
||||||
withoutErrors
|
withoutErrors
|
||||||
|> E.A.fmapi((index, item) =>
|
|> E.A.fmapi((index, item) =>
|
||||||
|
@ -188,7 +189,6 @@ module MathAdtToDistDst = {
|
||||||
| Fn({name: "triangular", args}) => triangular(args)
|
| Fn({name: "triangular", args}) => triangular(args)
|
||||||
| Value(f) => Ok(`Simple(`Float(f)))
|
| Value(f) => Ok(`Simple(`Float(f)))
|
||||||
| Fn({name: "mm", args}) => {
|
| Fn({name: "mm", args}) => {
|
||||||
let dists = args |> E.A.fmap(functionParser);
|
|
||||||
let weights =
|
let weights =
|
||||||
args
|
args
|
||||||
|> E.A.last
|
|> E.A.last
|
||||||
|
@ -198,18 +198,26 @@ module MathAdtToDistDst = {
|
||||||
| Array(values) => Some(values)
|
| Array(values) => Some(values)
|
||||||
| _ => None,
|
| _ => None,
|
||||||
)
|
)
|
||||||
|> E.A.O.defaultEmpty
|
|> E.O.fmap(o =>
|
||||||
|> E.A.fmap(
|
o
|
||||||
fun
|
|> E.A.fmap(
|
||||||
| Value(r) => Some(r)
|
fun
|
||||||
| _ => None,
|
| Value(r) => Some(r)
|
||||||
)
|
| _ => None,
|
||||||
|> E.A.O.concatSomes;
|
)
|
||||||
Js.log3("Making dists", dists, weights);
|
|> E.A.O.concatSomes
|
||||||
|
);
|
||||||
|
let possibleDists =
|
||||||
|
E.O.isSome(weights)
|
||||||
|
? Belt.Array.slice(args, ~offset=0, ~len=E.A.length(args) - 1)
|
||||||
|
: args;
|
||||||
|
let dists = possibleDists |> E.A.fmap(functionParser);
|
||||||
multiModal(dists, weights);
|
multiModal(dists, weights);
|
||||||
}
|
}
|
||||||
| Fn({name}) => Error(name ++ ": function not supported")
|
| Fn({name}) => Error(name ++ ": function not supported")
|
||||||
| _ => Error("This type not currently supported")
|
| _ => {
|
||||||
|
Error("This type not currently supported");
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let topLevel = (r): result(SymbolicDist.bigDist, string) =>
|
let topLevel = (r): result(SymbolicDist.bigDist, string) =>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user