Merge remote-tracking branch 'origin/master' into feature/1081

# Conflicts:
#	src/components/charts/GenericDistributionChart.re
This commit is contained in:
Roman Galochkin 2020-02-20 14:10:40 +03:00
commit 3ddf3561ca
5 changed files with 27 additions and 50 deletions

View File

@ -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>

View File

@ -7,11 +7,7 @@ module Mixed = {
React.useMemo1( React.useMemo1(
() => () =>
<CdfChart__Plain <CdfChart__Plain
primaryDistribution={ primaryDistribution={data.continuous}
data.continuous
|> Shape.Continuous.normalizePdf
|> E.O.toExt("")
}
discrete={data.discrete} discrete={data.discrete}
color={`hex("333")} color={`hex("333")}
timeScale timeScale
@ -77,6 +73,7 @@ module Cont = {
primaryDistribution=continuous primaryDistribution=continuous
color={`hex("333")} color={`hex("333")}
onHover onHover
timeScale
/>, />,
[|continuous|], [|continuous|],
); );
@ -129,9 +126,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}
@ -147,34 +142,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 />
}; };
}; };

View File

@ -398,25 +398,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);
} }
} }

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) { switch (t.generationSource) {
| Shape(shape) => t | Shape(shape) =>
| GuesstimatorString(_) => t 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 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);