Minor fixes

This commit is contained in:
Ozzie Gooen 2020-03-25 15:12:39 +00:00
parent dceea9c6b5
commit f7e3643a1e
4 changed files with 61 additions and 21 deletions

View File

@ -77,7 +77,7 @@ let make = () => {
~validationStrategy=OnDemand,
~schema,
~onSubmit=({state}) => {None},
~initialState={guesstimatorString: "lognormal(6.1, 3)"},
~initialState={guesstimatorString: "mm(1 to 10000)"},
(),
);

View File

@ -235,12 +235,6 @@ module DistPlusChart = {
distPlus |> Distributions.DistPlus.T.Integral.yToX(~cache=None, 0.99);
};
Js.log3(
distPlus |> Distributions.DistPlus.T.Integral.yToX(~cache=None, 0.0001),
minX,
distPlus |> Distributions.DistPlus.T.Integral.yToX(~cache=None, 0.98),
);
let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson;
let toDiscreteProbabilityMass =
distPlus |> Distributions.DistPlus.T.toDiscreteProbabilityMass;

View File

@ -107,9 +107,11 @@ module MathAdtToDistDst = {
let to_: array(arg) => result(SymbolicDist.bigDist, string) =
fun
| [|Value(low), Value(high)|] => {
| [|Value(low), Value(high)|] when low < high => {
Ok(`Simple(SymbolicDist.Lognormal.from90PercentCI(low, high)));
}
| [|Value(_), Value(_)|] =>
Error("Low value must be less than high value.")
| _ => Error("Wrong number of variables in lognormal distribution");
let uniform: array(arg) => result(SymbolicDist.bigDist, string) =
@ -122,7 +124,11 @@ module MathAdtToDistDst = {
| [|Value(alpha), Value(beta)|] => Ok(`Simple(`Beta({alpha, beta})))
| _ => Error("Wrong number of variables in lognormal distribution");
let multiModal = (args: array(result(SymbolicDist.bigDist, string))) => {
let multiModal =
(
args: array(result(SymbolicDist.bigDist, string)),
weights: array(float),
) => {
let dists =
args
|> E.A.fmap(
@ -135,7 +141,9 @@ module MathAdtToDistDst = {
| 0 => Error("Multimodals need at least one input")
| _ =>
dists
|> E.A.fmap(r => (r, 1.0))
|> E.A.fmapi((index, item) =>
(item, weights |> E.A.get(_, index) |> E.O.default(1.0))
)
|> (r => Ok(`PointwiseCombination(r)))
};
};
@ -151,9 +159,25 @@ module MathAdtToDistDst = {
| Fn({name: "to", args}) => to_(args)
| Fn({name: "mm", args}) => {
let dists = args |> E.A.fmap(functionParser);
multiModal(dists);
let weights =
args
|> E.A.last
|> E.O.bind(
_,
fun
| Array(values) => Some(values)
| _ => None,
)
|> E.A.O.defaultEmpty
|> E.A.fmap(
fun
| Value(r) => Some(r)
| _ => None,
)
|> E.A.O.concatSomes;
multiModal(dists, weights);
}
| Fn({name}) => Error(name ++ ": name not found")
| Fn({name}) => Error(name ++ ": function not supported")
| _ => Error("This type not currently supported")
);

View File

@ -132,15 +132,19 @@ module GenericSimple = {
| `Uniform({high}) => high
};
let interpolateXs =
(~xSelection: [ | `Linear | `ByWeight]=`Linear, dist: dist, sampleCount) => {
switch (xSelection) {
| `Linear => Functions.range(min(dist), max(dist), sampleCount)
| `ByWeight =>
Functions.range(minCdfValue, maxCdfValue, sampleCount)
|> E.A.fmap(x => inv(x, dist))
};
};
let toShape =
(~xSelection: [ | `Linear | `ByWeight]=`Linear, dist: dist, sampleCount) => {
let xs =
switch (xSelection) {
| `Linear => Functions.range(min(dist), max(dist), sampleCount)
| `ByWeight =>
Functions.range(minCdfValue, maxCdfValue, sampleCount)
|> E.A.fmap(x => inv(x, dist))
};
let xs = interpolateXs(~xSelection, dist, sampleCount);
let ys = xs |> E.A.fmap(r => pdf(r, dist));
XYShape.T.fromArrays(xs, ys);
};
@ -166,7 +170,19 @@ module PointwiseAddDistributionsWeighted = {
dists |> E.A.fmap(d => d |> fst |> GenericSimple.max) |> Functions.max;
let toShape = (dists: t, sampleCount: int) => {
let xs = Functions.range(min(dists), max(dists), sampleCount);
let xs =
dists
|> E.A.fmap(r =>
r
|> fst
|> GenericSimple.interpolateXs(
~xSelection=`ByWeight,
_,
sampleCount / (dists |> E.A.length),
)
)
|> E.A.concatMany;
xs |> Array.fast_sort(compare);
let ys = xs |> E.A.fmap(pdf(dists));
XYShape.T.fromArrays(xs, ys);
};
@ -176,7 +192,13 @@ module PointwiseAddDistributionsWeighted = {
dists
|> E.A.fmap(d => GenericSimple.toString(fst(d)))
|> Js.Array.joinWith(",");
{j|multimodal($distString)|j};
let weights =
dists
|> E.A.fmap(d =>
snd(d) |> Js.Float.toPrecisionWithPrecision(~digits=2)
)
|> Js.Array.joinWith(",");
{j|multimodal($distString, [$weights])|j};
};
};