diff --git a/showcase/entries/Continuous.re b/showcase/entries/Continuous.re index 0406f5b8..4dba4e73 100644 --- a/showcase/entries/Continuous.re +++ b/showcase/entries/Continuous.re @@ -3,7 +3,7 @@ let timeDist = DistPlusIngredients.make( - ~guesstimatorString="mm(floor(10 to 15), 10 to 11, [.9,.1])", + ~guesstimatorString="(floor(10 to 15))", ~domain=Complete, ~unit= DistTypes.TimeDistribution({zero: MomentRe.momentNow(), unit: `years}), @@ -12,7 +12,11 @@ let timeDist = let setup = dist => dist - |> DistPlusIngredients.toDistPlus(~sampleCount=5000, ~outputXYPoints=1000); + |> DistPlusIngredients.toDistPlus( + ~sampleCount=10000, + ~outputXYPoints=2000, + ~truncateTo=Some(1000), + ); let distributions = () =>
@@ -20,7 +24,7 @@ let distributions = () =>

{"Single-Discrete" |> ReasonReact.string}

{setup( DistPlusIngredients.make( - ~guesstimatorString="8 to 12, [.5,.5])", + ~guesstimatorString="mm(5 to 20, floor(normal(20,2)), [.5, .05])", ~domain=Complete, (), ), diff --git a/src/components/charts/DistPlusPlot.re b/src/components/charts/DistPlusPlot.re index 1d8027f3..4a37c99b 100644 --- a/src/components/charts/DistPlusPlot.re +++ b/src/components/charts/DistPlusPlot.re @@ -37,7 +37,6 @@ module IntegralChart = { let minX = integral |> Distributions.Continuous.T.minX; let maxX = integral |> Distributions.Continuous.T.maxX; let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson; - Js.log3("HIHI", continuous, distPlus); { let shape = Guesstimator.stringToMixedShape( ~string=t.guesstimatorString, ~sampleCount, ~outputXYPoints, + ~truncateTo, (), ); let distPlus = diff --git a/src/distributions/Distributions.re b/src/distributions/Distributions.re index 7773d453..aa9851ab 100644 --- a/src/distributions/Distributions.re +++ b/src/distributions/Distributions.re @@ -127,14 +127,15 @@ module Continuous = { // }; let integral = (~cache, t) => - cache - |> E.O.default( - t - |> xyShape - |> XYShape.Range.integrateWithTriangles - |> E.O.toExt("This should not have happened") - |> fromShape, - ); + switch (cache) { + | Some(cache) => cache + | None => + t + |> xyShape + |> XYShape.Range.integrateWithTriangles + |> E.O.toExt("This should not have happened") + |> fromShape + }; let integralEndY = (~cache, t) => t |> integral(~cache) |> lastY; let integralXtoY = (~cache, f, t) => t |> integral(~cache) |> shapeFn(CdfLibrary.Distribution.findY(f)); @@ -151,8 +152,10 @@ module Discrete = { type t = DistTypes.discreteShape; type integral = DistTypes.continuousShape; let integral = (~cache, t) => - cache - |> E.O.default(Continuous.make(XYShape.accumulateYs(t), `Stepwise)); + switch (cache) { + | Some(c) => c + | None => Continuous.make(XYShape.accumulateYs(t), `Stepwise) + }; let integralEndY = (~cache, t) => t |> integral(~cache) |> Continuous.lastY; let minX = XYShape.minX; @@ -253,32 +256,27 @@ module Mixed = { ~cache, {continuous, discrete, discreteProbabilityMassFraction} as t: t, ) => { - cache - |> E.O.default( - { - let cont = - continuous - |> Continuous.T.Integral.get(~cache=None) - |> scaleContinuous(t); - let dist = - discrete - |> Discrete.T.Integral.get(~cache=None) - |> Continuous.toLinear - |> E.O.toExn("") - |> Continuous.T.scaleBy( - ~scale=discreteProbabilityMassFraction, - ); - Continuous.make( - XYShape.Combine.combineLinear( - Continuous.getShape(cont), - Continuous.getShape(dist), - (a, b) => - a +. b - ), - `Linear, - ); - }, - ); + switch (cache) { + | Some(cache) => cache + | None => + let cont = + continuous + |> Continuous.T.Integral.get(~cache=None) + |> scaleContinuous(t); + let dist = + discrete + |> Discrete.T.Integral.get(~cache=None) + |> Continuous.toLinear + |> E.O.toExn("") + |> Continuous.T.scaleBy(~scale=discreteProbabilityMassFraction); + Continuous.make( + XYShape.Combine.combineLinear( + Continuous.getShape(cont), Continuous.getShape(dist), (a, b) => + a +. b + ), + `Linear, + ); + }; }; let integralEndY = (~cache, t: t) => { diff --git a/src/models/GlobalCatastrophe.re b/src/models/GlobalCatastrophe.re index 82cbfc56..ad633077 100644 --- a/src/models/GlobalCatastrophe.re +++ b/src/models/GlobalCatastrophe.re @@ -1,4 +1,4 @@ -let guesstimatorString = "floor(10 to 20)"; +let guesstimatorString = "normal(40,10)"; let makeI = (currentDateTime: MomentRe.Moment.t) => { DistPlusIngredients.make( diff --git a/src/utility/Guesstimator.re b/src/utility/Guesstimator.re index 9fe403bc..51ee992a 100644 --- a/src/utility/Guesstimator.re +++ b/src/utility/Guesstimator.re @@ -29,9 +29,15 @@ module Internals = { external toCombinedFormat: (string, int, int) => combined = "run"; // todo: Format to correct mass, also normalize the pdf. - let toMixedShape = (r: combined): option(DistTypes.shape) => { + let toMixedShape = + (~truncateTo=Some(500), r: combined): option(DistTypes.shape) => { + let continuous = toContinous(r); let continuous = - toContinous(r) |> Distributions.Continuous.convertToNewLength(100); + switch (truncateTo) { + | Some(t) => + continuous |> Distributions.Continuous.convertToNewLength(t) + | None => continuous + }; let discrete = toDiscrete(r); // let continuousProb = // cont |> Distributions.Continuous.T.Integral.sum(~cache=None); @@ -44,6 +50,12 @@ module Internals = { }; let stringToMixedShape = - (~string, ~sampleCount=1000, ~outputXYPoints=1000, ()) => + ( + ~string, + ~sampleCount=1000, + ~outputXYPoints=1000, + ~truncateTo=Some(500), + (), + ) => Internals.toCombinedFormat(string, sampleCount, outputXYPoints) - |> Internals.toMixedShape; \ No newline at end of file + |> Internals.toMixedShape(~truncateTo); \ No newline at end of file diff --git a/src/utility/GuesstimatorLibrary.js b/src/utility/GuesstimatorLibrary.js index 8b4deef9..06c2513c 100644 --- a/src/utility/GuesstimatorLibrary.js +++ b/src/utility/GuesstimatorLibrary.js @@ -42,7 +42,7 @@ const toPdf = (values, outputResolutionCount, min, max) => { let discrete = {xs: frequencies.map(f => f.value), ys: frequencies.map(f => f.percentage)}; let continuous = {ys: [], xs: []}; - if (continuousSamples.length > 1){ + if (continuousSamples.length > 20){ const samples = new Samples(continuousSamples); const ratioSize$ = ratioSize(samples);