Simple multimodal functionality in Fns.re
This commit is contained in:
parent
8d55bba2ca
commit
b71d037180
|
@ -233,7 +233,7 @@ let make = () => {
|
||||||
~onSubmit=({state}) => {None},
|
~onSubmit=({state}) => {None},
|
||||||
~initialState={
|
~initialState={
|
||||||
//guesstimatorString: "mm(normal(-10, 2), uniform(18, 25), lognormal({mean: 10, stdev: 8}), triangular(31,40,50))",
|
//guesstimatorString: "mm(normal(-10, 2), uniform(18, 25), lognormal({mean: 10, stdev: 8}), triangular(31,40,50))",
|
||||||
guesstimatorString: "mm(normal(5,2))",
|
guesstimatorString: "mm(3)",
|
||||||
domainType: "Complete",
|
domainType: "Complete",
|
||||||
xPoint: "50.0",
|
xPoint: "50.0",
|
||||||
xPoint2: "60.0",
|
xPoint2: "60.0",
|
||||||
|
|
|
@ -193,22 +193,78 @@ let functions = [|
|
||||||
switch (r) {
|
switch (r) {
|
||||||
| `SamplingDist(`SymbolicDist(c)) => Ok(`SymbolicDist(c))
|
| `SamplingDist(`SymbolicDist(c)) => Ok(`SymbolicDist(c))
|
||||||
| `SamplingDist(`RenderedDist(c)) => Ok(`RenderedDist(c))
|
| `SamplingDist(`RenderedDist(c)) => Ok(`RenderedDist(c))
|
||||||
|
| `Float(x) =>
|
||||||
|
Ok(`RenderedDist(SymbolicDist.T.toShape(1000, `Float(x))))
|
||||||
| _ => Error("")
|
| _ => Error("")
|
||||||
};
|
};
|
||||||
|
let weight = (r: TypeSystem.typedValue) =>
|
||||||
|
switch (r) {
|
||||||
|
| `Float(x) => Ok(x)
|
||||||
|
| _ => Error("Wrong Type")
|
||||||
|
};
|
||||||
|
let dists =
|
||||||
switch (ExpressionTypes.ExpressionTree.Hash.getByName(r, "dists")) {
|
switch (ExpressionTypes.ExpressionTree.Hash.getByName(r, "dists")) {
|
||||||
|
| Some(`Array(r)) => r |> E.A.fmap(foo) |> E.A.R.firstErrorOrOpen
|
||||||
|
| _ => Error("")
|
||||||
|
};
|
||||||
|
let weights =
|
||||||
|
(
|
||||||
|
switch (
|
||||||
|
ExpressionTypes.ExpressionTree.Hash.getByName(r, "weights")
|
||||||
|
) {
|
||||||
| Some(`Array(r)) =>
|
| Some(`Array(r)) =>
|
||||||
|
r |> E.A.fmap(weight) |> E.A.R.firstErrorOrOpen
|
||||||
|
| _ => Error("")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|> (
|
||||||
|
fun
|
||||||
|
| Ok(r) => r
|
||||||
|
| _ => [||]
|
||||||
|
);
|
||||||
|
let withWeights =
|
||||||
|
dists
|
||||||
|
|> E.R.fmap(d => {
|
||||||
|
let iis =
|
||||||
|
d |> E.A.length |> Belt.Array.makeUninitializedUnsafe;
|
||||||
|
for (i in 0 to (d |> E.A.length) - 1) {
|
||||||
|
Belt.Array.set(
|
||||||
|
iis,
|
||||||
|
i,
|
||||||
|
(
|
||||||
|
E.A.unsafe_get(d, i),
|
||||||
|
E.A.get(weights, i) |> E.O.default(1.0),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|> ignore;
|
||||||
|
};
|
||||||
|
iis;
|
||||||
|
});
|
||||||
|
let components: result(array(node), string) =
|
||||||
|
withWeights
|
||||||
|
|> E.R.fmap(
|
||||||
|
E.A.fmap(((dist, weight)) =>
|
||||||
|
`FunctionCall((
|
||||||
|
"scaleMultiply",
|
||||||
|
[|dist, `SymbolicDist(`Float(weight))|],
|
||||||
|
))
|
||||||
|
),
|
||||||
|
);
|
||||||
|
let pointwiseSum =
|
||||||
|
components
|
||||||
|
|> E.R.bind(_, r => {
|
||||||
|
E.A.length(r) > 0
|
||||||
|
? Ok(r) : Error("Invalid argument length")
|
||||||
|
})
|
||||||
|
|> E.R.fmap(r =>
|
||||||
r
|
r
|
||||||
|> E.A.fmap(foo)
|
|> Js.Array.sliceFrom(1)
|
||||||
|> E.A.R.firstErrorOrOpen
|
|
||||||
|> E.R.fmap(distributions => {
|
|
||||||
distributions
|
|
||||||
|> E.A.fold_left(
|
|> E.A.fold_left(
|
||||||
(acc, x) => {`PointwiseCombination((`Add, acc, x))},
|
(acc, x) => {`PointwiseCombination((`Add, acc, x))},
|
||||||
E.A.unsafe_get(distributions, 0),
|
E.A.unsafe_get(r, 0),
|
||||||
)
|
)
|
||||||
})
|
);
|
||||||
| _ => Error("")
|
pointwiseSum;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
| _ => Error(""),
|
| _ => Error(""),
|
||||||
(),
|
(),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user