It is time to fix time vector (2)

This commit is contained in:
Roman Galochkin 2020-02-19 10:54:40 +03:00
parent 10ad3be6b3
commit 64e7067f6b
7 changed files with 57 additions and 17 deletions

View File

@ -8,7 +8,7 @@ let mixedDist =
~generationSource=GuesstimatorString("mm(3, normal(5,1), [.5,.5])"),
~probabilityType=Pdf,
~domain=Complete,
~unit=Unspecified,
~unit=UnspecifiedDistribution,
(),
)
|> GenericDistribution.renderIfNeeded(~sampleCount=3000);
@ -18,7 +18,16 @@ let timeDist =
~generationSource=GuesstimatorString("mm(3, normal(5,1), [.5,.5])"),
~probabilityType=Pdf,
~domain=Complete,
~unit=Time({zero: MomentRe.momentNow(), unit: `years}),
~unit=
TimeDistribution({
zero: MomentRe.momentNow(),
step: `years,
length:
MomentRe.Moment.add(
~duration=MomentRe.duration(5., `years),
MomentRe.momentNow(),
),
}),
(),
)
|> GenericDistribution.renderIfNeeded(~sampleCount=3000);
@ -28,7 +37,7 @@ let domainLimitedDist =
~generationSource=GuesstimatorString("mm(3, normal(5,1), [.5,.5])"),
~probabilityType=Pdf,
~domain=RightLimited({xPoint: 6.0, excludingProbabilityMass: 0.3}),
~unit=Unspecified,
~unit=UnspecifiedDistribution,
(),
)
|> GenericDistribution.renderIfNeeded(~sampleCount=3000);

View File

@ -33,8 +33,8 @@ type generationSource =
| Shape(pointsType);
type distributionUnit =
| Unspecified
| Time(TimeTypes.timeVector);
| UnspecifiedDistribution
| TimeDistribution(TimeTypes.timeVector);
type probabilityType =
| Cdf
@ -51,9 +51,13 @@ type genericDistribution = {
module DistributionUnit = {
let toJson = (distributionUnit: distributionUnit) =>
switch (distributionUnit) {
| Time({zero, unit}) =>
| TimeDistribution({zero, step, length}) =>
Js.Null.fromOption(
Some({"zero": zero, "unit": unit |> TimeTypes.TimeUnit.toString}),
Some({
"zero": zero,
"step": step |> TimeTypes.TimeUnit.toString,
"length": length,
}),
)
| _ => Js.Null.fromOption(None)
};

View File

@ -5,7 +5,7 @@ let make =
~generationSource,
~probabilityType=Pdf,
~domain=Complete,
~unit=Unspecified,
~unit=UnspecifiedDistribution,
(),
)
: genericDistribution => {

View File

@ -12,7 +12,8 @@ type timeUnit = [
type timeVector = {
zero: MomentRe.Moment.t,
unit: timeUnit,
length: MomentRe.Moment.t,
step: timeUnit,
};
type timePoint = {
@ -42,12 +43,12 @@ module TimePoint = {
timePoint.timeVector.zero
|> MomentRe.Moment.add(
~duration=
MomentRe.duration(timePoint.value, timePoint.timeVector.unit),
MomentRe.duration(timePoint.value, timePoint.timeVector.step),
);
};
let fromMoment = (timeVector: timeVector, moment: MomentRe.Moment.t) =>
MomentRe.diff(timeVector.zero, moment, timeVector.unit);
MomentRe.diff(timeVector.zero, moment, timeVector.step);
};
module RelativeTimePoint = {
@ -60,7 +61,7 @@ module RelativeTimePoint = {
| Time(r) => r
| XValue(r) =>
timeVector.zero
|> MomentRe.Moment.add(~duration=MomentRe.duration(r, timeVector.unit))
|> MomentRe.Moment.add(~duration=MomentRe.duration(r, timeVector.step))
};
let _timeToX = (time, timeStart, timeUnit) =>
@ -68,7 +69,7 @@ module RelativeTimePoint = {
let toXValue = (timeVector: timeVector, timeInVector: timeInVector) =>
switch (timeInVector) {
| Time(r) => _timeToX(r, timeVector.zero, timeVector.unit)
| Time(r) => _timeToX(r, timeVector.zero, timeVector.step)
| XValue(r) => r
};
};

View File

@ -221,6 +221,21 @@ module TypeWithMetadata = {
~assumptionType=ASSUMPTION,
(),
);
let nextTenYears =
make(
~id="nextTenYears",
~name="Next Ten Years",
~description=None,
~type_=
DateTime({
default: Some(MomentRe.momentNow()),
min: Some(MomentRe.momentNow()),
max: Some(MomentRe.momentNow()),
}),
~assumptionType=ASSUMPTION,
(),
);
};
module Model = {

View File

@ -137,10 +137,11 @@ module Model = {
~generationSource=GuesstimatorString(str),
~probabilityType=Cdf,
~domain=Complete,
~unit=Unspecified,
~unit=UnspecifiedDistribution,
(),
);
Prop.Value.GenericDistribution(genericDistribution);
| CHANCE_OF_EXISTENCE =>
Prop.Value.GenericDistribution(
GenericDistribution.make(
@ -153,7 +154,12 @@ module Model = {
),
~probabilityType=Cdf,
~domain=RightLimited({xPoint: 100., excludingProbabilityMass: 0.3}),
~unit=Time({zero: currentDateTime, unit: `years}),
~unit=
TimeDistribution({
zero: currentDateTime,
step: `years,
length: currentDateTime,
}),
(),
),
)

View File

@ -7,7 +7,12 @@ module Model = {
~generationSource=GuesstimatorString(guesstimatorString),
~probabilityType=Cdf,
~domain=RightLimited({xPoint: 200., excludingProbabilityMass: 0.3}),
~unit=Time({zero: currentDateTime, unit: `years}),
~unit=
TimeDistribution({
zero: currentDateTime,
step: `years,
length: currentDateTime,
}),
(),
);
Prop.Value.GenericDistribution(genericDistribution);
@ -30,7 +35,7 @@ module Interface = {
description: "The chances of having at least one catastrophe per year in the future, assuming no other catastrophe until then.",
version: "1.0.0",
author: "Ozzie Gooen",
inputTypes: [|TypeWithMetadata.currentYear|],
inputTypes: [|TypeWithMetadata.nextTenYears|],
outputTypes: [||],
run,
};