Initial work on time domain

This commit is contained in:
Ozzie Gooen 2020-02-14 12:08:19 +00:00
parent 2b0e00ea3b
commit 5970f46c06
4 changed files with 84 additions and 9 deletions

2
.gitignore vendored
View File

@ -11,3 +11,5 @@ lib/*
build
yarn-error.log
*.bs.js
# Local Netlify folder
.netlify

View File

@ -19,8 +19,6 @@ let _lastElement = (a: array('a)) =>
let probabilityBeforeDomainMax = (t: t) => _lastElement(t.distribution.ys);
let chanceByX = (t: t) => t.distribution;
let domainMaxX = (t: t) => t.domainMaxX;
let probabilityDistribution = (t: t) =>
@ -29,5 +27,11 @@ let probabilityDistribution = (t: t) =>
let probability = (t: t, xPoint: float) =>
CdfLibrary.Distribution.findY(xPoint, probabilityDistribution(t));
let probabilityInverse = (t: t, yPoint: float) =>
CdfLibrary.Distribution.findX(yPoint, probabilityDistribution(t));
let cumulativeProbability = (t: t, xPoint: float) =>
CdfLibrary.Distribution.findY(xPoint, t.distribution);
let cumulativeProbabilityInverse = (t: t, yPoint: float) =>
CdfLibrary.Distribution.findX(yPoint, t.distribution);

View File

@ -0,0 +1,74 @@
type timeUnit = [
| `days
| `hours
| `milliseconds
| `minutes
| `months
| `quarters
| `seconds
| `weeks
| `years
];
type t = {
timeUnit,
timeStart: MomentRe.Moment.t,
limitedDomainCdf: LimitedDomainCdf.t,
};
module XSpecification = {
type xSpecification =
| Time(MomentRe.Moment.t)
| DifferenceFromStart(float, timeUnit)
| CdfXCoordinate(float);
let toTime = (t: t, xSpecification: xSpecification) =>
switch (xSpecification) {
| Time(r) => r
| DifferenceFromStart(r, unit) =>
t.timeStart
|> MomentRe.Moment.add(~duration=MomentRe.duration(r, unit))
| CdfXCoordinate(r) =>
t.timeStart
|> MomentRe.Moment.add(~duration=MomentRe.duration(r, t.timeUnit))
};
let rec toCdfXCoordinate = (t: t, xSpecification: xSpecification) =>
switch (xSpecification) {
| Time(r) => MomentRe.diff(t.timeStart, r, t.timeUnit)
| DifferenceFromStart(r, unit) =>
let newTime = toTime(t, DifferenceFromStart(r, unit));
toCdfXCoordinate(t, Time(newTime));
| CdfXCoordinate(r) => r
};
let fromDifference = (~t: t, ~duration: float, ~unit=t.timeUnit, ()) =>
Time(
MomentRe.Moment.add(
~duration=MomentRe.duration(duration, unit),
t.timeStart,
),
);
};
let probabilityBeforeDomainMax = (t: t) =>
LimitedDomainCdf.probabilityBeforeDomainMax(t.limitedDomainCdf);
let domainMaxX = (t: t) =>
LimitedDomainCdf.probabilityBeforeDomainMax(t.limitedDomainCdf);
let probability = (t: t, x: XSpecification.xSpecification) =>
LimitedDomainCdf.probability(
t.limitedDomainCdf,
XSpecification.toCdfXCoordinate(t, x),
);
let probabilityInverse = (t: t, y: float) =>
XSpecification.CdfXCoordinate(
LimitedDomainCdf.probabilityInverse(t.limitedDomainCdf, y),
);
let cumulativeProbabilityInverse = (t: t, y: float) =>
XSpecification.CdfXCoordinate(
LimitedDomainCdf.cumulativeProbabilityInverse(t.limitedDomainCdf, y),
);

View File

@ -1,9 +1,4 @@
module Model = {
let foo = {
let bar = 2.0;
();
};
let make = (dateTime: MomentRe.Moment.t, currentDateTime: MomentRe.Moment.t) => {
let yearDiff = MomentRe.diff(dateTime, currentDateTime, `days) /. 365.;
Prop.Value.Probability(0.001 *. yearDiff);