Minor fix for multimodals

This commit is contained in:
Ozzie Gooen 2020-11-05 17:04:50 -08:00
parent 4c33561b7c
commit 7566c59fef
4 changed files with 24 additions and 19 deletions

View File

@ -304,7 +304,7 @@ let rec toLeaf =
let components =
r
|> E.A.fmap(((dist, weight)) =>
`FunctionCall("scaleExp", [|dist, `SymbolicDist(`Float(weight))|]));
`FunctionCall("scaleMultiply", [|dist, `SymbolicDist(`Float(weight))|]));
let pointwiseSum =
components
|> Js.Array.sliceFrom(1)

View File

@ -91,14 +91,16 @@ let verticalScaling = (scaleOp, rs, scaleBy) => {
Operation.Scale.toFn(scaleOp, main, secondary);
let integralSumCacheFn = Operation.Scale.toIntegralSumCacheFn(scaleOp);
let integralCacheFn = Operation.Scale.toIntegralCacheFn(scaleOp);
Ok(`RenderedDist(
Ok(
`RenderedDist(
Shape.T.mapY(
~integralSumCacheFn=integralSumCacheFn(scaleBy),
~integralCacheFn=integralCacheFn(scaleBy),
~fn=fn(scaleBy),
rs,
),
));
),
);
};
let functions = [|
@ -152,7 +154,8 @@ let functions = [|
~run=
fun
| [|`SamplingDist(`SymbolicDist(c))|] => Ok(`SymbolicDist(c))
| [|`SamplingDist(`RenderedDist(c))|] => Ok(`RenderedDist(Shape.T.normalize(c)))
| [|`SamplingDist(`RenderedDist(c))|] =>
Ok(`RenderedDist(Shape.T.normalize(c)))
| e => wrongInputsError(e),
),
makeRenderedDistFloat("scaleExp", (dist, float) =>

View File

@ -22,7 +22,6 @@ let fnn =
) {
| (_, Some(`Function(argNames, tt))) =>
PTypes.Function.run(evaluationParams, args, (argNames, tt))
| ("mm", _)
| ("multimodal", _) =>
switch (args |> E.A.to_list) {
| [`Array(weights), ...dists] =>

View File

@ -204,7 +204,8 @@ module MathAdtToDistDst = {
let parseArgs = () => parseArray(args);
switch (name) {
| "lognormal" => lognormal(args, parseArgs, nodeParser)
| "mm" =>{
| "multimodal"
| "mm" =>
let weights =
args
|> E.A.last
@ -212,7 +213,7 @@ module MathAdtToDistDst = {
_,
fun
| Array(values) => Some(parseArray(values))
| _ => None
| _ => None,
);
let possibleDists =
E.O.isSome(weights)
@ -222,10 +223,12 @@ module MathAdtToDistDst = {
switch (weights, dists) {
| (Some(Error(r)), _) => Error(r)
| (_, Error(r)) => Error(r)
| (None, Ok(dists)) => Ok(`FunctionCall("multimodal", dists))
| (Some(Ok(r)), Ok(dists)) => Ok(`FunctionCall("multimodal", E.A.append([|`Array(r)|], dists)))
}
}
| (None, Ok(dists)) => Ok(`FunctionCall(("multimodal", dists)))
| (Some(Ok(r)), Ok(dists)) =>
Ok(
`FunctionCall(("multimodal", E.A.append([|`Array(r)|], dists))),
)
};
| "add"
| "subtract"
| "multiply"