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])"), ~generationSource=GuesstimatorString("mm(3, normal(5,1), [.5,.5])"),
~probabilityType=Pdf, ~probabilityType=Pdf,
~domain=Complete, ~domain=Complete,
~unit=Unspecified, ~unit=UnspecifiedDistribution,
(), (),
) )
|> GenericDistribution.renderIfNeeded(~sampleCount=3000); |> GenericDistribution.renderIfNeeded(~sampleCount=3000);
@ -18,7 +18,16 @@ let timeDist =
~generationSource=GuesstimatorString("mm(3, normal(5,1), [.5,.5])"), ~generationSource=GuesstimatorString("mm(3, normal(5,1), [.5,.5])"),
~probabilityType=Pdf, ~probabilityType=Pdf,
~domain=Complete, ~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); |> GenericDistribution.renderIfNeeded(~sampleCount=3000);
@ -28,7 +37,7 @@ let domainLimitedDist =
~generationSource=GuesstimatorString("mm(3, normal(5,1), [.5,.5])"), ~generationSource=GuesstimatorString("mm(3, normal(5,1), [.5,.5])"),
~probabilityType=Pdf, ~probabilityType=Pdf,
~domain=RightLimited({xPoint: 6.0, excludingProbabilityMass: 0.3}), ~domain=RightLimited({xPoint: 6.0, excludingProbabilityMass: 0.3}),
~unit=Unspecified, ~unit=UnspecifiedDistribution,
(), (),
) )
|> GenericDistribution.renderIfNeeded(~sampleCount=3000); |> GenericDistribution.renderIfNeeded(~sampleCount=3000);

View File

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

View File

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

View File

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

View File

@ -221,6 +221,21 @@ module TypeWithMetadata = {
~assumptionType=ASSUMPTION, ~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 = { module Model = {

View File

@ -137,10 +137,11 @@ module Model = {
~generationSource=GuesstimatorString(str), ~generationSource=GuesstimatorString(str),
~probabilityType=Cdf, ~probabilityType=Cdf,
~domain=Complete, ~domain=Complete,
~unit=Unspecified, ~unit=UnspecifiedDistribution,
(), (),
); );
Prop.Value.GenericDistribution(genericDistribution); Prop.Value.GenericDistribution(genericDistribution);
| CHANCE_OF_EXISTENCE => | CHANCE_OF_EXISTENCE =>
Prop.Value.GenericDistribution( Prop.Value.GenericDistribution(
GenericDistribution.make( GenericDistribution.make(
@ -153,7 +154,12 @@ module Model = {
), ),
~probabilityType=Cdf, ~probabilityType=Cdf,
~domain=RightLimited({xPoint: 100., excludingProbabilityMass: 0.3}), ~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), ~generationSource=GuesstimatorString(guesstimatorString),
~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=
TimeDistribution({
zero: currentDateTime,
step: `years,
length: currentDateTime,
}),
(), (),
); );
Prop.Value.GenericDistribution(genericDistribution); 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.", description: "The chances of having at least one catastrophe per year in the future, assuming no other catastrophe until then.",
version: "1.0.0", version: "1.0.0",
author: "Ozzie Gooen", author: "Ozzie Gooen",
inputTypes: [|TypeWithMetadata.currentYear|], inputTypes: [|TypeWithMetadata.nextTenYears|],
outputTypes: [||], outputTypes: [||],
run, run,
}; };