Minor cleanup
This commit is contained in:
parent
25f83d5290
commit
8f6053acee
|
@ -18,7 +18,10 @@ let mixedDist =
|
||||||
|
|
||||||
let timeDist =
|
let timeDist =
|
||||||
GenericDistribution.make(
|
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,
|
~probabilityType=Pdf,
|
||||||
~domain=Complete,
|
~domain=Complete,
|
||||||
~unit=TimeDistribution({zero: MomentRe.momentNow(), unit: `years}),
|
~unit=TimeDistribution({zero: MomentRe.momentNow(), unit: `years}),
|
||||||
|
@ -41,6 +44,7 @@ let distributions = () =>
|
||||||
<div>
|
<div>
|
||||||
<h2> {"Basic Mixed Distribution" |> ReasonReact.string} </h2>
|
<h2> {"Basic Mixed Distribution" |> ReasonReact.string} </h2>
|
||||||
{timeDist
|
{timeDist
|
||||||
|
|> E.O.bind(_, GenericDistribution.normalize)
|
||||||
|> E.O.React.fmapOrNull(dist => <GenericDistributionChart dist />)}
|
|> E.O.React.fmapOrNull(dist => <GenericDistributionChart dist />)}
|
||||||
<h2> {"Simple Continuous" |> ReasonReact.string} </h2>
|
<h2> {"Simple Continuous" |> ReasonReact.string} </h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,11 +7,7 @@ module Mixed = {
|
||||||
React.useMemo1(
|
React.useMemo1(
|
||||||
() =>
|
() =>
|
||||||
<CdfChart__Plain
|
<CdfChart__Plain
|
||||||
data={
|
data={data.continuous}
|
||||||
data.continuous
|
|
||||||
|> Shape.Continuous.normalizePdf
|
|
||||||
|> E.O.toExt("")
|
|
||||||
}
|
|
||||||
color={`hex("333")}
|
color={`hex("333")}
|
||||||
timeScale
|
timeScale
|
||||||
onHover={r => setX(_ => r)}
|
onHover={r => setX(_ => r)}
|
||||||
|
@ -70,7 +66,13 @@ module Cont = {
|
||||||
let make = (~continuous, ~onHover, ~timeScale) => {
|
let make = (~continuous, ~onHover, ~timeScale) => {
|
||||||
let chart =
|
let chart =
|
||||||
React.useMemo1(
|
React.useMemo1(
|
||||||
() => <CdfChart__Plain data=continuous color={`hex("333")} onHover />,
|
() =>
|
||||||
|
<CdfChart__Plain
|
||||||
|
data=continuous
|
||||||
|
color={`hex("333")}
|
||||||
|
onHover
|
||||||
|
timeScale
|
||||||
|
/>,
|
||||||
[|continuous|],
|
[|continuous|],
|
||||||
);
|
);
|
||||||
chart;
|
chart;
|
||||||
|
@ -122,9 +124,7 @@ module GenericDist = {
|
||||||
{x |> E.Float.toString |> ReasonReact.string}
|
{x |> E.Float.toString |> ReasonReact.string}
|
||||||
</th>
|
</th>
|
||||||
<th className="px-4 py-2 border ">
|
<th className="px-4 py-2 border ">
|
||||||
{genericDistribution
|
{genericDistribution->GenericDistribution.yIntegral(x)
|
||||||
|> DistributionTypes.shape
|
|
||||||
|> E.O.bind(_, r => Shape.Any.yIntegral(r, x))
|
|
||||||
|> E.O.fmap(E.Float.with2DigitsPrecision)
|
|> E.O.fmap(E.Float.with2DigitsPrecision)
|
||||||
|> E.O.default("")
|
|> E.O.default("")
|
||||||
|> ReasonReact.string}
|
|> ReasonReact.string}
|
||||||
|
@ -140,34 +140,8 @@ module GenericDist = {
|
||||||
[@react.component]
|
[@react.component]
|
||||||
let make = (~dist) => {
|
let make = (~dist) => {
|
||||||
switch ((dist: DistributionTypes.genericDistribution)) {
|
switch ((dist: DistributionTypes.genericDistribution)) {
|
||||||
| {
|
| {generationSource: Shape(_)} =>
|
||||||
unit,
|
<div> <GenericDist genericDistribution=dist /> </div>
|
||||||
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>
|
|
||||||
| _ => <div />
|
| _ => <div />
|
||||||
};
|
};
|
||||||
};
|
};
|
|
@ -347,25 +347,25 @@ export class CdfChartD3 {
|
||||||
getTimeTicksByStr(unit) {
|
getTimeTicksByStr(unit) {
|
||||||
switch (unit) {
|
switch (unit) {
|
||||||
case "months":
|
case "months":
|
||||||
return d3.timeMonth.every(1);
|
return d3.timeMonth.every(4);
|
||||||
case "quarters":
|
case "quarters":
|
||||||
return d3.timeMonth.every(3);
|
return d3.timeMonth.every(3);
|
||||||
case "hours":
|
case "hours":
|
||||||
return d3.timeHour.every(1);
|
return d3.timeHour.every(10);
|
||||||
case "days":
|
case "days":
|
||||||
return d3.timeDay.every(1);
|
return d3.timeDay.every(7);
|
||||||
case "seconds":
|
case "seconds":
|
||||||
return d3.timeSecond.every(1);
|
return d3.timeSecond.every(10);
|
||||||
case "years":
|
case "years":
|
||||||
return d3.timeYear.every(1);
|
return d3.timeYear.every(10);
|
||||||
case "minutes":
|
case "minutes":
|
||||||
return d3.timeMinute.every(1);
|
return d3.timeMinute.every(10);
|
||||||
case "weeks":
|
case "weeks":
|
||||||
return d3.timeWeek.every(1);
|
return d3.timeWeek.every(10);
|
||||||
case "milliseconds":
|
case "milliseconds":
|
||||||
return d3.timeMillisecond.every(1);
|
return d3.timeMillisecond.every(10);
|
||||||
default:
|
default:
|
||||||
return d3.timeYear.every(1);
|
return d3.timeYear.every(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,10 +68,12 @@ let normalizePdf = (t: DistributionTypes.pointsType) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
let normalize = (t: genericDistribution): genericDistribution => {
|
let normalize = (t: genericDistribution): option(genericDistribution) => {
|
||||||
switch (t.generationSource) {
|
switch (t.generationSource) {
|
||||||
| Shape(shape) => t
|
| Shape(shape) =>
|
||||||
| GuesstimatorString(_) => t
|
normalizePdf(shape)
|
||||||
|
|> E.O.fmap(shape => {...t, generationSource: Shape(shape)})
|
||||||
|
| GuesstimatorString(_) => Some(t)
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,9 @@ module Continuous = {
|
||||||
let toCdf = XYShape.Range.integrateWithTriangles;
|
let toCdf = XYShape.Range.integrateWithTriangles;
|
||||||
let findX = CdfLibrary.Distribution.findX;
|
let findX = CdfLibrary.Distribution.findX;
|
||||||
let findY = CdfLibrary.Distribution.findY;
|
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) =>
|
let normalizeCdf = (continuousShape: continuousShape) =>
|
||||||
continuousShape |> XYShape.scaleCdfTo(~scaleTo=1.0);
|
continuousShape |> XYShape.scaleCdfTo(~scaleTo=1.0);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user