Fixed issues with primary models

This commit is contained in:
Ozzie Gooen 2020-04-01 19:49:59 +01:00
parent e80bd4108e
commit 0ef6d106ea
3 changed files with 47 additions and 32 deletions

View File

@ -24,19 +24,32 @@ let toDistPlus =
t: distPlusIngredients, t: distPlusIngredients,
) )
: option(distPlus) => { : option(distPlus) => {
let samples = let toDist = shape =>
Guesstimator.stringToSamples(t.guesstimatorString, sampleCount); Distributions.DistPlus.make(
let shape = Samples.T.toShape(~samples, ~outputXYPoints, ~kernelWidth, ()); ~shape,
shape ~domain=t.domain,
|> E.O.fmap( ~unit=t.unit,
Distributions.DistPlus.make( ~guesstimatorString=Some(t.guesstimatorString),
~shape=_, (),
~domain=t.domain, )
~unit=t.unit, |> Distributions.DistPlus.T.scaleToIntegralSum(~intendedSum=1.0);
~guesstimatorString=Some(t.guesstimatorString), let parsed1 = MathJsParser.fromString(t.guesstimatorString);
(), let shape =
), switch (parsed1) {
) | Ok(r) =>
|> E.O.fmap(Distributions.DistPlus.T.scaleToIntegralSum(~intendedSum=1.0)) let shape = SymbolicDist.toShape(truncateTo |> E.O.default(10000), r);
|> applyTruncation(truncateTo); 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;
}; };

View File

@ -35,26 +35,26 @@ module Data = {
makeFundWithInfo( makeFundWithInfo(
"Animal Welfare Fund", "Animal Welfare Fund",
Fund(ANIMAL_WELFARE), Fund(ANIMAL_WELFARE),
Some(4000.0), Some(400000.0),
Some(10.0), Some(100000.0),
), ),
makeFundWithInfo( makeFundWithInfo(
"Global Health Fund", "Global Health Fund",
Fund(GLOBAL_HEALTH), Fund(GLOBAL_HEALTH),
Some(4000.0), Some(400000.0),
Some(10.0), Some(100000.0),
), ),
makeFundWithInfo( makeFundWithInfo(
"Long Term Future Fund", "Long Term Future Fund",
Fund(LONG_TERM_FUTURE), Fund(LONG_TERM_FUTURE),
Some(4000.0), Some(400000.0),
Some(10.0), Some(100000.0),
), ),
makeFundWithInfo( makeFundWithInfo(
"Meta Fund", "Meta Fund",
Fund(ANIMAL_WELFARE), Fund(ANIMAL_WELFARE),
Some(4000.0), Some(400000.0),
Some(10.0), Some(100000.0),
), ),
makeFundWithInfo("All", All, None, None), makeFundWithInfo("All", All, None, None),
|]; |];
@ -63,14 +63,14 @@ module Data = {
module Model = { module Model = {
open Data; open Data;
let currentYear = 2020.; let currentYear = 2020.;
let firstYearStdDev = 0.2; let firstYearStdDev = 400000.;
type yearlyNumericDiff = { type yearlyNumericDiff = {
meanDiff: float, meanDiff: float,
stdDiff: float, stdDiff: float,
}; };
let yearlyMeanGrowthRateIfNotClosed = (group: group): yearlyNumericDiff => { let yearlyMeanGrowthRateIfNotClosed = (group: group): yearlyNumericDiff => {
{meanDiff: 1.1, stdDiff: 1.08}; {meanDiff: 1.1, stdDiff: 1.2};
}; };
let calculateDifference = let calculateDifference =
@ -141,10 +141,12 @@ module Model = {
| None => | None =>
let foo = let foo =
getGlobalCatastropheChance(dateTime) getGlobalCatastropheChance(dateTime)
|> E.O.fmap(E.Float.with2DigitsPrecision) |> E.O.fmap(r => {
|> E.O.fmap((r: string) => let chance = r;
"uniform(0,1) > " ++ r ++ " ? " ++ difference ++ ": 0" let opposite = 1.0 -. r;
); let reg = difference;
{j|mm(0, $reg, [$chance, $opposite])|j};
});
foo |> E.O.default(""); foo |> E.O.default("");
}; };

View File

@ -10,9 +10,9 @@ let normal = (mean: float, std: float) =>
let logNormal = (mean: float, std: float) => { let logNormal = (mean: float, std: float) => {
Js.Float.( Js.Float.(
{ {
let nMean = toPrecisionWithPrecision(Js.Math.log10(mean), ~digits=4); let nMean = toPrecisionWithPrecision(mean, ~digits=4);
let nStd = toPrecisionWithPrecision(Js.Math.log10(std), ~digits=2); let nStd = toPrecisionWithPrecision(std, ~digits=2);
{j|lognormal($(nMean), $(nStd))|j}; {j|lognormal({mean: $(nMean), stdev: $(nStd)})|j};
} }
); );
}; };