Minor cleanup

This commit is contained in:
Ozzie Gooen 2020-02-20 10:57:01 +00:00
parent 25f83d5290
commit 8f6053acee
5 changed files with 33 additions and 51 deletions

View File

@ -18,7 +18,10 @@ let mixedDist =
let timeDist =
GenericDistribution.make(
~generationSource=GuesstimatorString("mm(3, normal(5,1), [.5,.5])"),
~generationSource=
GuesstimatorString(
"mm(floor(uniform(40, 50)), normal(50,10), [.5,.5])",
),
~probabilityType=Pdf,
~domain=Complete,
~unit=TimeDistribution({zero: MomentRe.momentNow(), unit: `years}),
@ -41,6 +44,7 @@ let distributions = () =>
<div>
<h2> {"Basic Mixed Distribution" |> ReasonReact.string} </h2>
{timeDist
|> E.O.bind(_, GenericDistribution.normalize)
|> E.O.React.fmapOrNull(dist => <GenericDistributionChart dist />)}
<h2> {"Simple Continuous" |> ReasonReact.string} </h2>
</div>

View File

@ -7,11 +7,7 @@ module Mixed = {
React.useMemo1(
() =>
<CdfChart__Plain
data={
data.continuous
|> Shape.Continuous.normalizePdf
|> E.O.toExt("")
}
data={data.continuous}
color={`hex("333")}
timeScale
onHover={r => setX(_ => r)}
@ -70,7 +66,13 @@ module Cont = {
let make = (~continuous, ~onHover, ~timeScale) => {
let chart =
React.useMemo1(
() => <CdfChart__Plain data=continuous color={`hex("333")} onHover />,
() =>
<CdfChart__Plain
data=continuous
color={`hex("333")}
onHover
timeScale
/>,
[|continuous|],
);
chart;
@ -122,9 +124,7 @@ module GenericDist = {
{x |> E.Float.toString |> ReasonReact.string}
</th>
<th className="px-4 py-2 border ">
{genericDistribution
|> DistributionTypes.shape
|> E.O.bind(_, r => Shape.Any.yIntegral(r, x))
{genericDistribution->GenericDistribution.yIntegral(x)
|> E.O.fmap(E.Float.with2DigitsPrecision)
|> E.O.default("")
|> ReasonReact.string}
@ -140,34 +140,8 @@ module GenericDist = {
[@react.component]
let make = (~dist) => {
switch ((dist: DistributionTypes.genericDistribution)) {
| {
unit,
generationSource:
Shape(
Mixed({
continuous: n,
discrete: d,
discreteProbabilityMassFraction: f,
}),
),
} =>
<div>
<GenericDist genericDistribution=dist />
<Mixed
unit
data={
continuous:
n
|> Shape.XYShape.Range.integrateWithTriangles
|> E.O.toExt("")
|> Shape.XYShape.scaleCdfTo
|> Shape.Continuous.toPdf
|> E.O.toExt(""),
discrete: d,
discreteProbabilityMassFraction: f,
}
/>
</div>
| {generationSource: Shape(_)} =>
<div> <GenericDist genericDistribution=dist /> </div>
| _ => <div />
};
};

View File

@ -347,25 +347,25 @@ export class CdfChartD3 {
getTimeTicksByStr(unit) {
switch (unit) {
case "months":
return d3.timeMonth.every(1);
return d3.timeMonth.every(4);
case "quarters":
return d3.timeMonth.every(3);
case "hours":
return d3.timeHour.every(1);
return d3.timeHour.every(10);
case "days":
return d3.timeDay.every(1);
return d3.timeDay.every(7);
case "seconds":
return d3.timeSecond.every(1);
return d3.timeSecond.every(10);
case "years":
return d3.timeYear.every(1);
return d3.timeYear.every(10);
case "minutes":
return d3.timeMinute.every(1);
return d3.timeMinute.every(10);
case "weeks":
return d3.timeWeek.every(1);
return d3.timeWeek.every(10);
case "milliseconds":
return d3.timeMillisecond.every(1);
return d3.timeMillisecond.every(10);
default:
return d3.timeYear.every(1);
return d3.timeYear.every(10);
}
}
}

View File

@ -68,10 +68,12 @@ let normalizePdf = (t: DistributionTypes.pointsType) => {
};
};
let normalize = (t: genericDistribution): genericDistribution => {
let normalize = (t: genericDistribution): option(genericDistribution) => {
switch (t.generationSource) {
| Shape(shape) => t
| GuesstimatorString(_) => t
| Shape(shape) =>
normalizePdf(shape)
|> E.O.fmap(shape => {...t, generationSource: Shape(shape)})
| GuesstimatorString(_) => Some(t)
};
};

View File

@ -107,7 +107,9 @@ module Continuous = {
let toCdf = XYShape.Range.integrateWithTriangles;
let findX = CdfLibrary.Distribution.findX;
let findY = CdfLibrary.Distribution.findY;
let findIntegralY = (f, r) => r |> toCdf |> E.O.fmap(findY(f));
let findIntegralY = (f, r) => {
r |> toCdf |> E.O.fmap(findY(f));
};
let normalizeCdf = (continuousShape: continuousShape) =>
continuousShape |> XYShape.scaleCdfTo(~scaleTo=1.0);