LimitedDomainCdf file

This commit is contained in:
Ozzie Gooen 2020-02-13 17:48:47 +00:00
parent 088a623bef
commit 089dfeeef2
3 changed files with 43 additions and 2 deletions

33
src/LimitedDomainCdf.re Normal file
View File

@ -0,0 +1,33 @@
type t = {
distribution: Types.distribution,
domainMaxX: float,
};
let fromCdf = (cdf: Types.cdf, domainMaxX: float, probabilityAtMaxX: float) => {
let distribution: Types.distribution = {
xs: cdf.xs,
ys: cdf.ys |> E.A.fmap(r => r *. probabilityAtMaxX),
};
{distribution, domainMaxX};
};
let _lastElement = (a: array('a)) =>
switch (Belt.Array.size(a)) {
| 0 => None
| n => Belt.Array.get(a, n)
};
let probabilityBeforeDomainMax = (t: t) => _lastElement(t.distribution.ys);
let chanceByX = (t: t) => t.distribution;
let domainMaxX = (t: t) => t.domainMaxX;
let probabilityDistribution = (t: t) =>
t.distribution |> CdfLibrary.Distribution.toPdf;
let probability = (t: t, xPoint: float) =>
CdfLibrary.Distribution.findY(xPoint, probabilityDistribution(t));
let cumulativeProbability = (t: t, xPoint: float) =>
CdfLibrary.Distribution.findY(xPoint, t.distribution);

View File

@ -38,7 +38,7 @@ module Value = {
| SelectSingle(r) => r |> ReasonReact.string
| FloatCdf(r) =>
let cdf: Types.distribution =
CdfLibrary.Distribution.fromString(r, 1000);
CdfLibrary.Distribution.fromString(r, 2000);
<>
<ForetoldComponents.CdfChart__Large
cdf={Types.toComponentsDist(cdf)}

View File

@ -6,4 +6,12 @@ type distribution = {
let toComponentsDist = (d: distribution): ForetoldComponents.Types.Dist.t => {
xs: d.xs,
ys: d.ys,
};
};
type pdf = distribution;
type cdf = distribution;
let foo = (b: pdf) => 3.9;
let bar: cdf = {xs: [||], ys: [||]};
let cc = foo(bar);