From 0ef6d106ea4171c2b4a5a5513fc29199ed563248 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Wed, 1 Apr 2020 19:49:59 +0100 Subject: [PATCH] Fixed issues with primary models --- src/distribution/DistPlusIngredients.re | 43 ++++++++++++++++--------- src/models/EAFunds.re | 30 +++++++++-------- src/utility/GuesstimatorDist.re | 6 ++-- 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/src/distribution/DistPlusIngredients.re b/src/distribution/DistPlusIngredients.re index 6bba41af..36a7e663 100644 --- a/src/distribution/DistPlusIngredients.re +++ b/src/distribution/DistPlusIngredients.re @@ -24,19 +24,32 @@ let toDistPlus = t: distPlusIngredients, ) : option(distPlus) => { - let samples = - Guesstimator.stringToSamples(t.guesstimatorString, sampleCount); - let shape = Samples.T.toShape(~samples, ~outputXYPoints, ~kernelWidth, ()); - shape - |> E.O.fmap( - Distributions.DistPlus.make( - ~shape=_, - ~domain=t.domain, - ~unit=t.unit, - ~guesstimatorString=Some(t.guesstimatorString), - (), - ), - ) - |> E.O.fmap(Distributions.DistPlus.T.scaleToIntegralSum(~intendedSum=1.0)) - |> applyTruncation(truncateTo); + let toDist = shape => + Distributions.DistPlus.make( + ~shape, + ~domain=t.domain, + ~unit=t.unit, + ~guesstimatorString=Some(t.guesstimatorString), + (), + ) + |> Distributions.DistPlus.T.scaleToIntegralSum(~intendedSum=1.0); + let parsed1 = MathJsParser.fromString(t.guesstimatorString); + let shape = + switch (parsed1) { + | Ok(r) => + let shape = SymbolicDist.toShape(truncateTo |> E.O.default(10000), r); + Some(shape |> toDist); + | _ => + let fewSamples = Guesstimator.stringToSamples(t.guesstimatorString, 10); + if (fewSamples |> E.A.length > 0) { + let samples = + Guesstimator.stringToSamples(t.guesstimatorString, sampleCount); + let shape = + Samples.T.toShape(~samples, ~outputXYPoints, ~kernelWidth, ()); + shape |> E.O.fmap(toDist) |> applyTruncation(truncateTo); + } else { + None; + }; + }; + shape; }; \ No newline at end of file diff --git a/src/models/EAFunds.re b/src/models/EAFunds.re index 96407d88..aeacb1b2 100644 --- a/src/models/EAFunds.re +++ b/src/models/EAFunds.re @@ -35,26 +35,26 @@ module Data = { makeFundWithInfo( "Animal Welfare Fund", Fund(ANIMAL_WELFARE), - Some(4000.0), - Some(10.0), + Some(400000.0), + Some(100000.0), ), makeFundWithInfo( "Global Health Fund", Fund(GLOBAL_HEALTH), - Some(4000.0), - Some(10.0), + Some(400000.0), + Some(100000.0), ), makeFundWithInfo( "Long Term Future Fund", Fund(LONG_TERM_FUTURE), - Some(4000.0), - Some(10.0), + Some(400000.0), + Some(100000.0), ), makeFundWithInfo( "Meta Fund", Fund(ANIMAL_WELFARE), - Some(4000.0), - Some(10.0), + Some(400000.0), + Some(100000.0), ), makeFundWithInfo("All", All, None, None), |]; @@ -63,14 +63,14 @@ module Data = { module Model = { open Data; let currentYear = 2020.; - let firstYearStdDev = 0.2; + let firstYearStdDev = 400000.; type yearlyNumericDiff = { meanDiff: float, stdDiff: float, }; let yearlyMeanGrowthRateIfNotClosed = (group: group): yearlyNumericDiff => { - {meanDiff: 1.1, stdDiff: 1.08}; + {meanDiff: 1.1, stdDiff: 1.2}; }; let calculateDifference = @@ -141,10 +141,12 @@ module Model = { | None => let foo = getGlobalCatastropheChance(dateTime) - |> E.O.fmap(E.Float.with2DigitsPrecision) - |> E.O.fmap((r: string) => - "uniform(0,1) > " ++ r ++ " ? " ++ difference ++ ": 0" - ); + |> E.O.fmap(r => { + let chance = r; + let opposite = 1.0 -. r; + let reg = difference; + {j|mm(0, $reg, [$chance, $opposite])|j}; + }); foo |> E.O.default(""); }; diff --git a/src/utility/GuesstimatorDist.re b/src/utility/GuesstimatorDist.re index 74f54e50..eb843076 100644 --- a/src/utility/GuesstimatorDist.re +++ b/src/utility/GuesstimatorDist.re @@ -10,9 +10,9 @@ let normal = (mean: float, std: float) => let logNormal = (mean: float, std: float) => { Js.Float.( { - let nMean = toPrecisionWithPrecision(Js.Math.log10(mean), ~digits=4); - let nStd = toPrecisionWithPrecision(Js.Math.log10(std), ~digits=2); - {j|lognormal($(nMean), $(nStd))|j}; + let nMean = toPrecisionWithPrecision(mean, ~digits=4); + let nStd = toPrecisionWithPrecision(std, ~digits=2); + {j|lognormal({mean: $(nMean), stdev: $(nStd)})|j}; } ); };