Initial work on time domain
This commit is contained in:
parent
2b0e00ea3b
commit
5970f46c06
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -11,3 +11,5 @@ lib/*
|
||||||
build
|
build
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
*.bs.js
|
*.bs.js
|
||||||
|
# Local Netlify folder
|
||||||
|
.netlify
|
|
@ -19,8 +19,6 @@ let _lastElement = (a: array('a)) =>
|
||||||
|
|
||||||
let probabilityBeforeDomainMax = (t: t) => _lastElement(t.distribution.ys);
|
let probabilityBeforeDomainMax = (t: t) => _lastElement(t.distribution.ys);
|
||||||
|
|
||||||
let chanceByX = (t: t) => t.distribution;
|
|
||||||
|
|
||||||
let domainMaxX = (t: t) => t.domainMaxX;
|
let domainMaxX = (t: t) => t.domainMaxX;
|
||||||
|
|
||||||
let probabilityDistribution = (t: t) =>
|
let probabilityDistribution = (t: t) =>
|
||||||
|
@ -29,5 +27,11 @@ let probabilityDistribution = (t: t) =>
|
||||||
let probability = (t: t, xPoint: float) =>
|
let probability = (t: t, xPoint: float) =>
|
||||||
CdfLibrary.Distribution.findY(xPoint, probabilityDistribution(t));
|
CdfLibrary.Distribution.findY(xPoint, probabilityDistribution(t));
|
||||||
|
|
||||||
|
let probabilityInverse = (t: t, yPoint: float) =>
|
||||||
|
CdfLibrary.Distribution.findX(yPoint, probabilityDistribution(t));
|
||||||
|
|
||||||
let cumulativeProbability = (t: t, xPoint: float) =>
|
let cumulativeProbability = (t: t, xPoint: float) =>
|
||||||
CdfLibrary.Distribution.findY(xPoint, t.distribution);
|
CdfLibrary.Distribution.findY(xPoint, t.distribution);
|
||||||
|
|
||||||
|
let cumulativeProbabilityInverse = (t: t, yPoint: float) =>
|
||||||
|
CdfLibrary.Distribution.findX(yPoint, t.distribution);
|
74
src/TimeLimitedDomainCdf.re
Normal file
74
src/TimeLimitedDomainCdf.re
Normal 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),
|
||||||
|
);
|
|
@ -1,9 +1,4 @@
|
||||||
module Model = {
|
module Model = {
|
||||||
let foo = {
|
|
||||||
let bar = 2.0;
|
|
||||||
();
|
|
||||||
};
|
|
||||||
|
|
||||||
let make = (dateTime: MomentRe.Moment.t, currentDateTime: MomentRe.Moment.t) => {
|
let make = (dateTime: MomentRe.Moment.t, currentDateTime: MomentRe.Moment.t) => {
|
||||||
let yearDiff = MomentRe.diff(dateTime, currentDateTime, `days) /. 365.;
|
let yearDiff = MomentRe.diff(dateTime, currentDateTime, `days) /. 365.;
|
||||||
Prop.Value.Probability(0.001 *. yearDiff);
|
Prop.Value.Probability(0.001 *. yearDiff);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user