Minor cleanup
This commit is contained in:
parent
1a547748c7
commit
17e40a9098
15
src/core/MixedCdf.re
Normal file
15
src/core/MixedCdf.re
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
type t = DistributionTypes.mixedShape;
|
||||||
|
|
||||||
|
type yPdfPoint = {
|
||||||
|
continuous: float,
|
||||||
|
discrete: float,
|
||||||
|
};
|
||||||
|
|
||||||
|
let getY = (t: t, x: float): yPdfPoint => {
|
||||||
|
continuous: Shape.Continuous.findY(x, t.continuous),
|
||||||
|
discrete: Shape.Discrete.findY(x, t.discrete),
|
||||||
|
} /* }*/;
|
||||||
|
|
||||||
|
// let getIntegralY = (t: t, x: float): float => {
|
||||||
|
// continuous: Shape.Continuous.findY(x, t.continuous),
|
||||||
|
// discrete: Shape.Discrete.findY(x, t.discrete),
|
|
@ -14,9 +14,11 @@ module XYShape = {
|
||||||
};
|
};
|
||||||
|
|
||||||
let fmap = (t: t, y): t => {xs: t.xs, ys: t.ys |> E.A.fmap(y)};
|
let fmap = (t: t, y): t => {xs: t.xs, ys: t.ys |> E.A.fmap(y)};
|
||||||
|
|
||||||
let yFold = (fn, t: t) => {
|
let yFold = (fn, t: t) => {
|
||||||
E.A.fold_left(fn, 0., t.ys);
|
E.A.fold_left(fn, 0., t.ys);
|
||||||
};
|
};
|
||||||
|
|
||||||
let ySum = yFold((a, b) => a +. b);
|
let ySum = yFold((a, b) => a +. b);
|
||||||
|
|
||||||
let fromArrays = (xs, ys): t => {xs, ys};
|
let fromArrays = (xs, ys): t => {xs, ys};
|
||||||
|
@ -34,8 +36,8 @@ module XYShape = {
|
||||||
fromArrays(xs, ys);
|
fromArrays(xs, ys);
|
||||||
};
|
};
|
||||||
|
|
||||||
let derivative = transverse((aCurrent, aLast) => aCurrent -. aLast);
|
|
||||||
let integral = transverse((aCurrent, aLast) => aCurrent +. aLast);
|
let integral = transverse((aCurrent, aLast) => aCurrent +. aLast);
|
||||||
|
let derivative = transverse((aCurrent, aLast) => aCurrent -. aLast);
|
||||||
};
|
};
|
||||||
|
|
||||||
module Continuous = {
|
module Continuous = {
|
||||||
|
@ -84,6 +86,16 @@ module Mixed = {
|
||||||
discrete,
|
discrete,
|
||||||
discreteProbabilityMassFraction,
|
discreteProbabilityMassFraction,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type yPdfPoint = {
|
||||||
|
continuous: float,
|
||||||
|
discrete: float,
|
||||||
|
};
|
||||||
|
|
||||||
|
let getY = (t: DistributionTypes.mixedShape, x: float): yPdfPoint => {
|
||||||
|
continuous: Continuous.findY(x, t.continuous),
|
||||||
|
discrete: Discrete.findY(x, t.discrete),
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module DomainMixed = {
|
module DomainMixed = {
|
||||||
|
|
|
@ -12,6 +12,11 @@ module Value = {
|
||||||
| GenericDistribution(DistributionTypes.genericDistribution)
|
| GenericDistribution(DistributionTypes.genericDistribution)
|
||||||
| ConditionalArray(array(conditional))
|
| ConditionalArray(array(conditional))
|
||||||
| FloatCdf(string);
|
| FloatCdf(string);
|
||||||
|
|
||||||
|
module ConditionalArray = {
|
||||||
|
let get = (conditionals: array(conditional), name: string) =>
|
||||||
|
Belt.Array.getBy(conditionals, (c: conditional) => c.name == name);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module ValueCombination = {
|
module ValueCombination = {
|
||||||
|
|
|
@ -17,4 +17,5 @@ let logNormal = (mean: float, std: float) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
let divide = (str1: string, str2: string) => {j|$(str1)/$(str2)|j};
|
let divide = (str1: string, str2: string) => {j|$(str1)/$(str2)|j};
|
||||||
|
let min = (str1: string, str2: string) => {j|min($(str1),$(str2))|j};
|
|
@ -103,13 +103,19 @@ module Model = {
|
||||||
| (_, CHANCE_OF_EXISTENCE) => 0.0
|
| (_, CHANCE_OF_EXISTENCE) => 0.0
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let xRisk = conditionals =>
|
||||||
|
Prop.Value.ConditionalArray.get(conditionals, "Global Existential Event");
|
||||||
|
|
||||||
let make =
|
let make =
|
||||||
(
|
(
|
||||||
group: group,
|
group: group,
|
||||||
dateTime: MomentRe.Moment.t,
|
dateTime: MomentRe.Moment.t,
|
||||||
currentDateTime: MomentRe.Moment.t,
|
currentDateTime: MomentRe.Moment.t,
|
||||||
output: output,
|
output: output,
|
||||||
|
conditionals: array(Prop.Value.conditional),
|
||||||
) => {
|
) => {
|
||||||
|
let xRisk = xRisk(conditionals);
|
||||||
switch (output) {
|
switch (output) {
|
||||||
| DONATIONS
|
| DONATIONS
|
||||||
| PAYOUTS =>
|
| PAYOUTS =>
|
||||||
|
@ -120,16 +126,37 @@ module Model = {
|
||||||
currentDateTime,
|
currentDateTime,
|
||||||
yearlyMeanGrowthRateIfNotClosed(group),
|
yearlyMeanGrowthRateIfNotClosed(group),
|
||||||
);
|
);
|
||||||
|
let str =
|
||||||
|
switch (xRisk) {
|
||||||
|
| Some({truthValue: true}) => "0"
|
||||||
|
| Some({truthValue: false}) => difference
|
||||||
|
| None => "uniform(0,1) > .3 ? " ++ difference ++ ": 0"
|
||||||
|
};
|
||||||
let genericDistribution =
|
let genericDistribution =
|
||||||
GenericDistribution.make(
|
GenericDistribution.make(
|
||||||
~generationSource=GuesstimatorString(difference),
|
~generationSource=GuesstimatorString(str),
|
||||||
~probabilityType=Cdf,
|
~probabilityType=Cdf,
|
||||||
~domain=Complete,
|
~domain=Complete,
|
||||||
~unit=Unspecified,
|
~unit=Unspecified,
|
||||||
(),
|
(),
|
||||||
);
|
);
|
||||||
Prop.Value.GenericDistribution(genericDistribution);
|
Prop.Value.GenericDistribution(genericDistribution);
|
||||||
| CHANCE_OF_EXISTENCE => Prop.Value.Probability(0.3)
|
| CHANCE_OF_EXISTENCE =>
|
||||||
|
Prop.Value.GenericDistribution(
|
||||||
|
GenericDistribution.make(
|
||||||
|
~generationSource=
|
||||||
|
GuesstimatorString(
|
||||||
|
GuesstimatorDist.min(
|
||||||
|
GlobalCatastrophe.guesstimatorString,
|
||||||
|
GuesstimatorDist.logNormal(40., 4.),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
~probabilityType=Cdf,
|
||||||
|
~domain=RightLimited({xPoint: 100., excludingProbabilityMass: 0.3}),
|
||||||
|
~unit=Time({zero: currentDateTime, unit: `years}),
|
||||||
|
(),
|
||||||
|
),
|
||||||
|
)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -158,7 +185,7 @@ module Interface = {
|
||||||
Some(DateTime(intendedYear)),
|
Some(DateTime(intendedYear)),
|
||||||
Some(DateTime(currentYear)),
|
Some(DateTime(currentYear)),
|
||||||
Some(SelectSingle(output)),
|
Some(SelectSingle(output)),
|
||||||
_,
|
Some(ConditionalArray(conditionals)),
|
||||||
|] =>
|
|] =>
|
||||||
choiceFromString(fund)
|
choiceFromString(fund)
|
||||||
|> E.O.fmap(fund =>
|
|> E.O.fmap(fund =>
|
||||||
|
@ -167,6 +194,7 @@ module Interface = {
|
||||||
intendedYear,
|
intendedYear,
|
||||||
currentYear,
|
currentYear,
|
||||||
outputFromString(output),
|
outputFromString(output),
|
||||||
|
conditionals,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
| _ => None
|
| _ => None
|
||||||
|
@ -229,9 +257,9 @@ module Interface = {
|
||||||
SelectSingle({
|
SelectSingle({
|
||||||
default: Some("Output"),
|
default: Some("Output"),
|
||||||
options: [
|
options: [
|
||||||
{name: "Donations | Exists", id: "donations"},
|
{name: "Donations", id: "donations"},
|
||||||
{name: "Funding | Exists", id: "funding"},
|
{name: "Funding", id: "funding"},
|
||||||
{name: "Exists", id: "exists"},
|
{name: "Closing", id: "exists"},
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
(),
|
(),
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
|
let guesstimatorString = GuesstimatorDist.logNormal(20., 3.);
|
||||||
|
|
||||||
module Model = {
|
module Model = {
|
||||||
let make = (currentDateTime: MomentRe.Moment.t) => {
|
let make = (currentDateTime: MomentRe.Moment.t) => {
|
||||||
let genericDistribution =
|
let genericDistribution =
|
||||||
GenericDistribution.make(
|
GenericDistribution.make(
|
||||||
~generationSource=
|
~generationSource=GuesstimatorString(guesstimatorString),
|
||||||
GuesstimatorString(GuesstimatorDist.logNormal(20., 3.)),
|
|
||||||
~probabilityType=Cdf,
|
~probabilityType=Cdf,
|
||||||
~domain=RightLimited({xPoint: 200., excludingProbabilityMass: 0.3}),
|
~domain=RightLimited({xPoint: 200., excludingProbabilityMass: 0.3}),
|
||||||
~unit=Time({zero: currentDateTime, unit: `years}),
|
~unit=Time({zero: currentDateTime, unit: `years}),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user