Minor fixes
This commit is contained in:
parent
dceea9c6b5
commit
f7e3643a1e
|
@ -77,7 +77,7 @@ let make = () => {
|
||||||
~validationStrategy=OnDemand,
|
~validationStrategy=OnDemand,
|
||||||
~schema,
|
~schema,
|
||||||
~onSubmit=({state}) => {None},
|
~onSubmit=({state}) => {None},
|
||||||
~initialState={guesstimatorString: "lognormal(6.1, 3)"},
|
~initialState={guesstimatorString: "mm(1 to 10000)"},
|
||||||
(),
|
(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -235,12 +235,6 @@ module DistPlusChart = {
|
||||||
distPlus |> Distributions.DistPlus.T.Integral.yToX(~cache=None, 0.99);
|
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 timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson;
|
||||||
let toDiscreteProbabilityMass =
|
let toDiscreteProbabilityMass =
|
||||||
distPlus |> Distributions.DistPlus.T.toDiscreteProbabilityMass;
|
distPlus |> Distributions.DistPlus.T.toDiscreteProbabilityMass;
|
||||||
|
|
|
@ -107,9 +107,11 @@ module MathAdtToDistDst = {
|
||||||
|
|
||||||
let to_: array(arg) => result(SymbolicDist.bigDist, string) =
|
let to_: array(arg) => result(SymbolicDist.bigDist, string) =
|
||||||
fun
|
fun
|
||||||
| [|Value(low), Value(high)|] => {
|
| [|Value(low), Value(high)|] when low < high => {
|
||||||
Ok(`Simple(SymbolicDist.Lognormal.from90PercentCI(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");
|
| _ => Error("Wrong number of variables in lognormal distribution");
|
||||||
|
|
||||||
let uniform: array(arg) => result(SymbolicDist.bigDist, string) =
|
let uniform: array(arg) => result(SymbolicDist.bigDist, string) =
|
||||||
|
@ -122,7 +124,11 @@ module MathAdtToDistDst = {
|
||||||
| [|Value(alpha), Value(beta)|] => Ok(`Simple(`Beta({alpha, beta})))
|
| [|Value(alpha), Value(beta)|] => Ok(`Simple(`Beta({alpha, beta})))
|
||||||
| _ => Error("Wrong number of variables in lognormal distribution");
|
| _ => 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 =
|
let dists =
|
||||||
args
|
args
|
||||||
|> E.A.fmap(
|
|> E.A.fmap(
|
||||||
|
@ -135,7 +141,9 @@ module MathAdtToDistDst = {
|
||||||
| 0 => Error("Multimodals need at least one input")
|
| 0 => Error("Multimodals need at least one input")
|
||||||
| _ =>
|
| _ =>
|
||||||
dists
|
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)))
|
|> (r => Ok(`PointwiseCombination(r)))
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -151,9 +159,25 @@ module MathAdtToDistDst = {
|
||||||
| Fn({name: "to", args}) => to_(args)
|
| Fn({name: "to", args}) => to_(args)
|
||||||
| Fn({name: "mm", args}) => {
|
| Fn({name: "mm", args}) => {
|
||||||
let dists = args |> E.A.fmap(functionParser);
|
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")
|
| _ => Error("This type not currently supported")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -132,15 +132,19 @@ module GenericSimple = {
|
||||||
| `Uniform({high}) => high
|
| `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 =
|
let toShape =
|
||||||
(~xSelection: [ | `Linear | `ByWeight]=`Linear, dist: dist, sampleCount) => {
|
(~xSelection: [ | `Linear | `ByWeight]=`Linear, dist: dist, sampleCount) => {
|
||||||
let xs =
|
let xs = interpolateXs(~xSelection, 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 ys = xs |> E.A.fmap(r => pdf(r, dist));
|
let ys = xs |> E.A.fmap(r => pdf(r, dist));
|
||||||
XYShape.T.fromArrays(xs, ys);
|
XYShape.T.fromArrays(xs, ys);
|
||||||
};
|
};
|
||||||
|
@ -166,7 +170,19 @@ module PointwiseAddDistributionsWeighted = {
|
||||||
dists |> E.A.fmap(d => d |> fst |> GenericSimple.max) |> Functions.max;
|
dists |> E.A.fmap(d => d |> fst |> GenericSimple.max) |> Functions.max;
|
||||||
|
|
||||||
let toShape = (dists: t, sampleCount: int) => {
|
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));
|
let ys = xs |> E.A.fmap(pdf(dists));
|
||||||
XYShape.T.fromArrays(xs, ys);
|
XYShape.T.fromArrays(xs, ys);
|
||||||
};
|
};
|
||||||
|
@ -176,7 +192,13 @@ module PointwiseAddDistributionsWeighted = {
|
||||||
dists
|
dists
|
||||||
|> E.A.fmap(d => GenericSimple.toString(fst(d)))
|
|> E.A.fmap(d => GenericSimple.toString(fst(d)))
|
||||||
|> Js.Array.joinWith(",");
|
|> 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};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user