Renaming of core lib and charts

This commit is contained in:
Ozzie Gooen 2020-02-23 13:27:52 +00:00
parent 6a57095cad
commit f844c9cc72
16 changed files with 123 additions and 195 deletions

View File

@ -1,15 +1,12 @@
open Jest;
open Expect;
let shape: DistributionTypes.xyShape = {
xs: [|1., 4., 8.|],
ys: [|8., 9., 2.|],
};
let shape: DistTypes.xyShape = {xs: [|1., 4., 8.|], ys: [|8., 9., 2.|]};
let step: DistributionTypes.xyShape = {
let step: DistTypes.xyShape = {
xs: [|1., 4., 8.|],
ys: [|8., 17., 19.|],
} /* }*/;
} /* }*/ /* )*/;
// describe("Shape", () =>
// describe("XYShape", () => {
@ -18,4 +15,3 @@ let step: DistributionTypes.xyShape = {
// );
// test("#yFOo", () =>
// expect(Discrete.integrate(shape)) |> toEqual(step)
// );

View File

@ -1,59 +0,0 @@
[@bs.module "./cdfChartReact.js"]
external cdfChart: ReasonReact.reactClass = "default";
type primaryDistribution =
option({
.
"xs": array(float),
"ys": array(float),
});
type discrete =
option({
.
"xs": array(float),
"ys": array(float),
});
[@react.component]
let make =
(
~height=?,
~marginBottom=?,
~marginTop=?,
~maxX=?,
~minX=?,
~onHover=(f: float) => (),
~continuous=?,
~discrete=?,
~scale=?,
~showDistributionLines=?,
~showDistributionYAxis=?,
~showVerticalLine=?,
~timeScale=?,
~verticalLine=?,
~children=[||],
) =>
ReasonReact.wrapJsForReason(
~reactClass=cdfChart,
~props=
makeProps(
~height?,
~marginBottom?,
~marginTop?,
~maxX?,
~minX?,
~onHover,
~continuous?,
~discrete?,
~scale?,
~showDistributionLines?,
~showDistributionYAxis?,
~showVerticalLine?,
~timeScale?,
~verticalLine?,
(),
),
children,
)
|> ReasonReact.element;

View File

@ -1,24 +0,0 @@
module Styles = {
open Css;
let graph = chartColor =>
style([
selector(".axis", [fontSize(`px(9))]),
selector(".domain", [display(`none)]),
selector(".tick line", [display(`none)]),
selector(".tick text", [color(`hex("bfcad4"))]),
selector(".chart .area-path", [SVG.fill(chartColor)]),
]);
};
[@react.component]
let make = (~minX=None, ~maxX=None, ~height=50, ~color=`hex("7e9db7")) =>
<div className={Styles.graph(color)}>
<CdfChart__Base
height
?minX
?maxX
marginBottom=20
showVerticalLine=false
showDistributionLines=false
/>
</div>;

View File

@ -1,6 +1,6 @@
module DistPlusChart = {
[@react.component]
let make = (~distPlus: DistributionTypes.distPlus, ~onHover) => {
let make = (~distPlus: DistTypes.distPlus, ~onHover) => {
open Distributions.DistPlus;
let discrete = distPlus |> T.toDiscrete;
let continuous =
@ -9,8 +9,8 @@ module DistPlusChart = {
|> E.O.fmap(Distributions.Continuous.getShape);
let minX = T.minX(distPlus);
let maxX = T.maxX(distPlus);
let timeScale = distPlus.unit |> DistributionTypes.DistributionUnit.toJson;
<CdfChart__Plain
let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson;
<DistributionChart
minX
maxX
?discrete
@ -24,7 +24,7 @@ module DistPlusChart = {
module IntegralChart = {
[@react.component]
let make = (~distPlus: DistributionTypes.distPlus, ~onHover) => {
let make = (~distPlus: DistTypes.distPlus, ~onHover) => {
open Distributions.DistPlus;
let integral =
Distributions.DistPlus.T.Integral.get(~cache=None, distPlus);
@ -35,8 +35,8 @@ module IntegralChart = {
|> E.O.fmap(Distributions.Continuous.getShape);
let minX = T.minX(integral);
let maxX = T.maxX(integral);
let timeScale = distPlus.unit |> DistributionTypes.DistributionUnit.toJson;
<CdfChart__Plain
let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson;
<DistributionChart
minX
maxX
?continuous
@ -48,7 +48,7 @@ module IntegralChart = {
};
[@react.component]
let make = (~distPlus: DistributionTypes.distPlus) => {
let make = (~distPlus: DistTypes.distPlus) => {
let (x, setX) = React.useState(() => 0.);
let chart =
React.useMemo1(

View File

@ -1,3 +1,65 @@
module RawChart = {
[@bs.module "./cdfChartReact.js"]
external cdfChart: ReasonReact.reactClass = "default";
type primaryDistribution =
option({
.
"xs": array(float),
"ys": array(float),
});
type discrete =
option({
.
"xs": array(float),
"ys": array(float),
});
[@react.component]
let make =
(
~height=?,
~marginBottom=?,
~marginTop=?,
~maxX=?,
~minX=?,
~onHover=(f: float) => (),
~continuous=?,
~discrete=?,
~scale=?,
~showDistributionLines=?,
~showDistributionYAxis=?,
~showVerticalLine=?,
~timeScale=?,
~verticalLine=?,
~children=[||],
) =>
ReasonReact.wrapJsForReason(
~reactClass=cdfChart,
~props=
makeProps(
~height?,
~marginBottom?,
~marginTop?,
~maxX?,
~minX?,
~onHover,
~continuous?,
~discrete?,
~scale?,
~showDistributionLines?,
~showDistributionYAxis?,
~showVerticalLine?,
~timeScale?,
~verticalLine?,
(),
),
children,
)
|> ReasonReact.element;
};
module Styles = {
open Css;
let textOverlay = style([position(`absolute)]);
@ -40,7 +102,7 @@ let make =
~timeScale=?,
) => {
<div className={Styles.graph(color)}>
<CdfChart__Base
<RawChart
?maxX
?minX
?scale

View File

@ -1,6 +1,5 @@
import React, { useEffect } from 'react';
import { useSize } from 'react-use';
import { CdfChartD3 } from './cdfChartD3';
/**

View File

@ -1,4 +1,4 @@
open DistributionTypes;
open DistTypes;
let make =
(~guesstimatorString, ~domain=Complete, ~unit=UnspecifiedDistribution, ())

View File

@ -19,12 +19,12 @@ module type dist = {
let minX: t => option(float);
let maxX: t => option(float);
let pointwiseFmap: (float => float, t) => t;
let xToY: (float, t) => DistributionTypes.mixedPoint;
let toShape: t => DistributionTypes.shape;
let toContinuous: t => option(DistributionTypes.continuousShape);
let toDiscrete: t => option(DistributionTypes.discreteShape);
let toScaledContinuous: t => option(DistributionTypes.continuousShape);
let toScaledDiscrete: t => option(DistributionTypes.discreteShape);
let xToY: (float, t) => DistTypes.mixedPoint;
let toShape: t => DistTypes.shape;
let toContinuous: t => option(DistTypes.continuousShape);
let toDiscrete: t => option(DistTypes.discreteShape);
let toScaledContinuous: t => option(DistTypes.continuousShape);
let toScaledDiscrete: t => option(DistTypes.discreteShape);
type integral;
let integral: (~cache: option(integral), t) => integral;
@ -62,7 +62,7 @@ module Dist = (T: dist) => {
};
module Continuous = {
type t = DistributionTypes.continuousShape;
type t = DistTypes.continuousShape;
let xyShape = (t: t) => t.xyShape;
let getShape = (t: t) => t.xyShape;
let interpolation = (t: t) => t.interpolation;
@ -73,8 +73,7 @@ module Continuous = {
interpolation,
};
let oShapeMap =
(fn, {xyShape, interpolation}: t)
: option(DistributionTypes.continuousShape) =>
(fn, {xyShape, interpolation}: t): option(DistTypes.continuousShape) =>
fn(xyShape) |> E.O.fmap(xyShape => make(xyShape, interpolation));
let toLinear = (t: t): t =>
@ -88,8 +87,8 @@ module Continuous = {
module T =
Dist({
type t = DistributionTypes.continuousShape;
type integral = DistributionTypes.continuousShape;
type t = DistTypes.continuousShape;
type integral = DistTypes.continuousShape;
let shapeFn = (fn, t: t) => t |> xyShape |> fn;
// TODO: Obviously fix this, it's terrible
let integral = (~cache, t) =>
@ -108,11 +107,11 @@ module Continuous = {
let maxX = shapeFn(XYShape.maxX);
let pointwiseFmap = (fn, t: t) =>
t |> xyShape |> XYShape.pointwiseMap(fn) |> fromShape;
let toShape = (t: t): DistributionTypes.shape => Continuous(t);
let toShape = (t: t): DistTypes.shape => Continuous(t);
// TODO: When Roman's PR comes in, fix this bit.
let xToY = (f, t) =>
shapeFn(CdfLibrary.Distribution.findY(f), t)
|> DistributionTypes.MixedPoint.makeContinuous;
|> DistTypes.MixedPoint.makeContinuous;
let integralXtoY = (~cache, f, t) =>
t |> integral(~cache) |> shapeFn(CdfLibrary.Distribution.findY(f));
let toContinuous = t => Some(t);
@ -125,8 +124,8 @@ module Continuous = {
module Discrete = {
module T =
Dist({
type t = DistributionTypes.discreteShape;
type integral = DistributionTypes.continuousShape;
type t = DistTypes.discreteShape;
type integral = DistTypes.continuousShape;
let integral = (~cache, t) =>
cache
|> E.O.default(
@ -143,14 +142,14 @@ module Discrete = {
let minX = XYShape.minX;
let maxX = XYShape.maxX;
let pointwiseFmap = XYShape.pointwiseMap;
let toShape = (t: t): DistributionTypes.shape => Discrete(t);
let toShape = (t: t): DistTypes.shape => Discrete(t);
let toContinuous = _ => None;
let toDiscrete = t => Some(t);
let toScaledContinuous = t => None;
let toScaledDiscrete = t => Some(t);
let xToY = (f, t) =>
CdfLibrary.Distribution.findY(f, t)
|> DistributionTypes.MixedPoint.makeDiscrete;
|> DistTypes.MixedPoint.makeDiscrete;
let integralXtoY = (~cache, f, t) =>
t |> XYShape.accumulateYs |> CdfLibrary.Distribution.findY(f);
});
@ -159,14 +158,13 @@ module Discrete = {
module Mixed = {
let make =
(~continuous, ~discrete, ~discreteProbabilityMassFraction)
: DistributionTypes.mixedShape => {
: DistTypes.mixedShape => {
continuous,
discrete,
discreteProbabilityMassFraction,
};
let clean =
(t: DistributionTypes.mixedShape): option(DistributionTypes.shape) => {
let clean = (t: DistTypes.mixedShape): option(DistTypes.shape) => {
switch (t) {
| {
continuous: {xyShape: {xs: [||], ys: [||]}},
@ -183,34 +181,34 @@ module Mixed = {
};
let scaleDiscreteFn =
({discreteProbabilityMassFraction}: DistributionTypes.mixedShape, f) =>
({discreteProbabilityMassFraction}: DistTypes.mixedShape, f) =>
f *. discreteProbabilityMassFraction;
let scaleContinuousFn =
({discreteProbabilityMassFraction}: DistributionTypes.mixedShape, f) =>
({discreteProbabilityMassFraction}: DistTypes.mixedShape, f) =>
f *. (1.0 -. discreteProbabilityMassFraction);
module T =
Dist({
type t = DistributionTypes.mixedShape;
type integral = DistributionTypes.continuousShape;
type t = DistTypes.mixedShape;
type integral = DistTypes.continuousShape;
let minX = ({continuous, discrete}: t) =>
min(Continuous.T.minX(continuous), Discrete.T.minX(discrete));
let maxX = ({continuous, discrete}: t) =>
max(Continuous.T.maxX(continuous), Discrete.T.maxX(discrete));
let toShape = (t: t): DistributionTypes.shape => Mixed(t);
let toShape = (t: t): DistTypes.shape => Mixed(t);
let toContinuous = ({continuous}: t) => Some(continuous);
let toDiscrete = ({discrete}: t) => Some(discrete);
let xToY = (f, {discrete, continuous} as t: t) => {
let c =
continuous
|> Continuous.T.xToY(f)
|> DistributionTypes.MixedPoint.fmap(scaleContinuousFn(t));
|> DistTypes.MixedPoint.fmap(scaleContinuousFn(t));
let d =
discrete
|> Discrete.T.xToY(f)
|> DistributionTypes.MixedPoint.fmap(scaleDiscreteFn(t));
DistributionTypes.MixedPoint.add(c, d);
|> DistTypes.MixedPoint.fmap(scaleDiscreteFn(t));
DistTypes.MixedPoint.add(c, d);
};
let scaleContinuous =
@ -284,8 +282,8 @@ module Mixed = {
module Shape = {
module T =
Dist({
type t = DistributionTypes.shape;
type integral = DistributionTypes.continuousShape;
type t = DistTypes.shape;
type integral = DistTypes.continuousShape;
let mapToAll = (t: t, (fn1, fn2, fn3)) =>
switch (t) {
@ -389,7 +387,7 @@ module Shape = {
};
module DistPlus = {
open DistributionTypes;
open DistTypes;
let make =
(
~shape,
@ -420,8 +418,8 @@ module DistPlus = {
module T =
Dist({
type t = DistributionTypes.distPlus;
type integral = DistributionTypes.distPlus;
type t = DistTypes.distPlus;
type integral = DistTypes.distPlus;
let toShape = ({shape, _}: t) => shape;
let shapeFn = (fn, t: t) => t |> toShape |> fn;
let toContinuous = shapeFn(Shape.T.toContinuous);

View File

@ -1,4 +1,4 @@
open DistributionTypes;
open DistTypes;
let _lastElement = (a: array('a)) =>
switch (Belt.Array.size(a)) {
| 0 => None
@ -24,17 +24,17 @@ let fromArrays = (xs, ys): t => {xs, ys};
let pointwiseMap = (fn, t: t): t => {xs: t.xs, ys: t.ys |> E.A.fmap(fn)};
let intersperce = (t1: t, t2: t) => {
let foo: ref(array((float, float))) = ref([||]);
let items: ref(array((float, float))) = ref([||]);
let t1 = zip(t1);
let t2 = zip(t2);
Belt.Array.forEachWithIndex(t1, (i, item) => {
switch (Belt.Array.get(t2, i)) {
| Some(r) => foo := E.A.append(foo^, [|item, r|])
| None => foo := E.A.append(foo^, [|item|])
| Some(r) => items := E.A.append(items^, [|item, r|])
| None => items := E.A.append(items^, [|item|])
}
});
foo^ |> Belt.Array.unzip |> fromArray;
items^ |> Belt.Array.unzip |> fromArray;
};
let scaleCdfTo = (~scaleTo=1., t: t) =>
@ -70,6 +70,9 @@ let _transverseShape = (fn, p: t) => {
let accumulateYs = _transverseShape((aCurrent, aLast) => aCurrent +. aLast);
let subtractYs = _transverseShape((aCurrent, aLast) => aCurrent -. aLast);
let findY = CdfLibrary.Distribution.findY;
let findX = CdfLibrary.Distribution.findX;
module Range = {
// ((lastX, lastY), (nextX, nextY))
type zippedRange = ((float, float), (float, float));
@ -122,6 +125,3 @@ module Range = {
|> E.O.fmap(fromArray)
|> E.O.fmap(intersperce(t));
};
let findY = CdfLibrary.Distribution.findY;
let findX = CdfLibrary.Distribution.findX;

View File

@ -9,7 +9,7 @@ module Value = {
| DateTime(MomentRe.Moment.t)
| FloatPoint(float)
| Probability(float)
| DistPlusIngredients(DistributionTypes.distPlusIngredients)
| DistPlusIngredients(DistTypes.distPlusIngredients)
| ConditionalArray(array(conditional))
| FloatCdf(string);
@ -85,7 +85,7 @@ module ValueCluster = {
[ | `combination(range(MomentRe.Moment.t)) | `item(string)],
)
| Probability([ | `item(string)])
| DistPlusIngredients([ | `item(DistributionTypes.distPlusIngredients)])
| DistPlusIngredients([ | `item(DistTypes.distPlusIngredients)])
| ConditionalArray([ | `item(array(conditional))])
| FloatCdf([ | `item(string)]);
};

View File

@ -1,42 +0,0 @@
module Styles = {
open Css;
let graph = chartColor =>
style([
selector(".x-axis", [fontSize(`px(9))]),
selector(".x-axis .domain", [display(`none)]),
selector(".x-axis .tick line", [display(`none)]),
selector(".x-axis .tick text", [color(`hex("bfcad4"))]),
selector(".chart .area-path", [SVG.fill(chartColor)]),
selector(".lollipops-line", [SVG.stroke(`hex("bfcad4"))]),
selector(
".lollipops-circle",
[SVG.stroke(`hex("bfcad4")), SVG.fill(`hex("bfcad4"))],
),
selector(".lollipops-x-axis .domain", [display(`none)]),
selector(".lollipops-x-axis .tick line", [display(`none)]),
selector(".lollipops-x-axis .tick text", [display(`none)]),
]);
};
[@react.component]
let make =
(
~data,
~minX=None,
~maxX=None,
~width=300,
~height=50,
~color=`hex("7e9db7"),
) =>
<div className={Styles.graph(color)}>
<ForetoldComponents.CdfChart__Base
width=0
height
?minX
?maxX
marginBottom=20
showVerticalLine=false
showDistributionLines=false
primaryDistribution=data
/>
</div>;

View File

@ -5,16 +5,14 @@ module JS = {
ys: array(float),
};
let distToJs = (d: DistributionTypes.xyShape) =>
distJs(~xs=d.xs, ~ys=d.ys);
let distToJs = (d: DistTypes.xyShape) => distJs(~xs=d.xs, ~ys=d.ys);
let jsToDist = (d: distJs): DistributionTypes.xyShape => {
let jsToDist = (d: distJs): DistTypes.xyShape => {
xs: xsGet(d),
ys: ysGet(d),
};
let doAsDist = (f, d: DistributionTypes.xyShape) =>
d |> distToJs |> f |> jsToDist;
let doAsDist = (f, d: DistTypes.xyShape) => d |> distToJs |> f |> jsToDist;
[@bs.module "./CdfLibrary.js"]
external cdfToPdf: distJs => distJs = "cdfToPdf";

View File

@ -5,7 +5,7 @@ module Internals = {
ys: array(float),
};
let jsToDistDiscrete = (d: discrete): DistributionTypes.discreteShape => {
let jsToDistDiscrete = (d: discrete): DistTypes.discreteShape => {
xs: xsGet(d),
ys: ysGet(d),
};
@ -21,14 +21,14 @@ module Internals = {
|> CdfLibrary.JS.jsToDist
|> Distributions.Continuous.fromShape;
let toDiscrete = (r: combined): DistributionTypes.xyShape =>
let toDiscrete = (r: combined): DistTypes.xyShape =>
discreteGet(r) |> jsToDistDiscrete;
[@bs.module "./GuesstimatorLibrary.js"]
external toCombinedFormat: (string, int) => combined = "run";
// todo: Format to correct mass, also normalize the pdf.
let toMixedShape = (r: combined): option(DistributionTypes.mixedShape) => {
let toMixedShape = (r: combined): option(DistTypes.mixedShape) => {
let assumptions: MixedShapeBuilder.assumptions = {
continuous: ADDS_TO_1,
discrete: ADDS_TO_CORRECT_PROBABILITY,