Minor cleanup

This commit is contained in:
Ozzie Gooen 2020-02-13 18:28:34 +00:00
parent 089dfeeef2
commit b85f2c8729
4 changed files with 59 additions and 6 deletions

20
src/lib/Chart.re Normal file
View File

@ -0,0 +1,20 @@
[@react.component]
let make =
(
~data,
~minX=None,
~maxX=None,
~width=300,
~height=50,
~color=`hex("7e9db7"),
) =>
<ForetoldComponents.CdfChart__Base
width=0
height
?minX
?maxX
marginBottom=20
showVerticalLine=false
showDistributionLines=false
primaryDistribution=data
/>;

View File

@ -40,10 +40,7 @@ module Value = {
let cdf: Types.distribution = let cdf: Types.distribution =
CdfLibrary.Distribution.fromString(r, 2000); CdfLibrary.Distribution.fromString(r, 2000);
<> <>
<ForetoldComponents.CdfChart__Large <Chart data={cdf |> CdfLibrary.Distribution.toPdf |> Types.toJs} />
cdf={Types.toComponentsDist(cdf)}
width={Some(400)}
/>
{r |> ReasonReact.string} {r |> ReasonReact.string}
</>; </>;
| Probability(r) => | Probability(r) =>

View File

@ -3,6 +3,10 @@ type distribution = {
ys: array(float), ys: array(float),
}; };
let toJs = (t: distribution) => {
{"xs": t.xs, "ys": t.ys};
};
let toComponentsDist = (d: distribution): ForetoldComponents.Types.Dist.t => { let toComponentsDist = (d: distribution): ForetoldComponents.Types.Dist.t => {
xs: d.xs, xs: d.xs,
ys: d.ys, ys: d.ys,
@ -14,4 +18,37 @@ type cdf = distribution;
let foo = (b: pdf) => 3.9; let foo = (b: pdf) => 3.9;
let bar: cdf = {xs: [||], ys: [||]}; let bar: cdf = {xs: [||], ys: [||]};
let cc = foo(bar); let cc = foo(bar);
module LimitedDomainCdf = {
type t = {
distribution,
domainMaxX: float,
};
let fromCdf = (cdf: cdf, domainMaxX: float, probabilityAtMaxX: float) => {
let distribution: 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

@ -44,7 +44,6 @@ const toPdf = (values, sampleCount, min, max) => {
}; };
let run = (text, sampleCount, inputs=[], min=false, max=false) => { let run = (text, sampleCount, inputs=[], min=false, max=false) => {
console.log(text);
let [_error, item] = Guesstimator.parse({ text: "=" + text }); let [_error, item] = Guesstimator.parse({ text: "=" + text });
const { parsedInput } = item; const { parsedInput } = item;
const { guesstimateType } = parsedInput; const { guesstimateType } = parsedInput;