Minor fix to get continuous-discrete magnitudes working

This commit is contained in:
Ozzie Gooen 2020-02-26 10:08:37 +00:00
parent 7e8fa21ab7
commit ee0ff39326
6 changed files with 47 additions and 4 deletions

View File

@ -26,7 +26,7 @@ let distributions = () =>
{setup( {setup(
DistPlusIngredients.make( DistPlusIngredients.make(
~guesstimatorString= ~guesstimatorString=
"uniform(0,1) > 0.036 ? lognormal(6.652, -0.41): 0", "uniform(0,1) > 0.3 ? lognormal(6.652, -0.41): 0",
~domain= ~domain=
RightLimited({xPoint: 50.0, excludingProbabilityMass: 0.3}), RightLimited({xPoint: 50.0, excludingProbabilityMass: 0.3}),
(), (),

View File

@ -1,3 +1,15 @@
let adjustBoth = discreteProbabilityMass => {
let yMaxDiscreteDomainFactor = discreteProbabilityMass;
let yMaxContinuousDomainFactor = 1.0 -. discreteProbabilityMass;
let yMax =
yMaxDiscreteDomainFactor > yMaxContinuousDomainFactor
? yMaxDiscreteDomainFactor : yMaxContinuousDomainFactor;
(
1.0 /. (yMaxDiscreteDomainFactor /. yMax),
1.0 /. (yMaxContinuousDomainFactor /. yMax),
);
};
module DistPlusChart = { module DistPlusChart = {
[@react.component] [@react.component]
let make = (~distPlus: DistTypes.distPlus, ~onHover) => { let make = (~distPlus: DistTypes.distPlus, ~onHover) => {
@ -16,9 +28,15 @@ module DistPlusChart = {
let maxX = T.maxX(distPlus); let maxX = T.maxX(distPlus);
let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson; let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson;
let toDiscreteProbabilityMass =
distPlus |> Distributions.DistPlus.T.toDiscreteProbabilityMass;
let (yMaxDiscreteDomainFactor, yMaxContinuousDomainFactor) =
adjustBoth(toDiscreteProbabilityMass);
<DistributionPlot <DistributionPlot
minX minX
maxX maxX
yMaxDiscreteDomainFactor
yMaxContinuousDomainFactor
height=120 height=120
?discrete ?discrete
?continuous ?continuous

View File

@ -24,6 +24,8 @@ module RawPlot = {
~marginTop=?, ~marginTop=?,
~maxX=?, ~maxX=?,
~minX=?, ~minX=?,
~yMaxContinuousDomainFactor=?,
~yMaxDiscreteDomainFactor=?,
~onHover=(f: float) => (), ~onHover=(f: float) => (),
~continuous=?, ~continuous=?,
~discrete=?, ~discrete=?,
@ -44,6 +46,8 @@ module RawPlot = {
~marginTop?, ~marginTop?,
~maxX?, ~maxX?,
~minX?, ~minX?,
~yMaxContinuousDomainFactor?,
~yMaxDiscreteDomainFactor?,
~onHover, ~onHover,
~continuous?, ~continuous?,
~discrete?, ~discrete?,
@ -93,6 +97,8 @@ let make =
~height=200, ~height=200,
~maxX=?, ~maxX=?,
~minX=?, ~minX=?,
~yMaxDiscreteDomainFactor=?,
~yMaxContinuousDomainFactor=?,
~onHover: float => unit, ~onHover: float => unit,
~continuous=?, ~continuous=?,
~scale=?, ~scale=?,
@ -105,6 +111,8 @@ let make =
<RawPlot <RawPlot
?maxX ?maxX
?minX ?minX
?yMaxDiscreteDomainFactor
?yMaxContinuousDomainFactor
?scale ?scale
?timeScale ?timeScale
discrete={discrete |> E.O.fmap(XYShape.toJs)} discrete={discrete |> E.O.fmap(XYShape.toJs)}

View File

@ -50,8 +50,8 @@ function CdfChartReact(props) {
.set('container', containerRef.current) .set('container', containerRef.current)
.set('scale', scale) .set('scale', scale)
.set('timeScale', props.timeScale) .set('timeScale', props.timeScale)
.set('yMaxContinuousDomainFactor', 1) .set('yMaxContinuousDomainFactor', props.yMaxContinuousDomainFactor)
.set('yMaxDiscreteDomainFactor', 1) .set('yMaxDiscreteDomainFactor', props.yMaxDiscreteDomainFactor)
.data({ .data({
continuous: props.continuous, continuous: props.continuous,
discrete: props.discrete, discrete: props.discrete,

View File

@ -25,6 +25,7 @@ module type dist = {
let toDiscrete: t => option(DistTypes.discreteShape); let toDiscrete: t => option(DistTypes.discreteShape);
let toScaledContinuous: t => option(DistTypes.continuousShape); let toScaledContinuous: t => option(DistTypes.continuousShape);
let toScaledDiscrete: t => option(DistTypes.discreteShape); let toScaledDiscrete: t => option(DistTypes.discreteShape);
let toDiscreteProbabilityMass: t => float;
type integral; type integral;
let integral: (~cache: option(integral), t) => integral; let integral: (~cache: option(integral), t) => integral;
@ -45,6 +46,7 @@ module Dist = (T: dist) => {
let pointwiseFmap = T.pointwiseFmap; let pointwiseFmap = T.pointwiseFmap;
let xToY = T.xToY; let xToY = T.xToY;
let toShape = T.toShape; let toShape = T.toShape;
let toDiscreteProbabilityMass = T.toDiscreteProbabilityMass;
let toContinuous = T.toContinuous; let toContinuous = T.toContinuous;
let toDiscrete = T.toDiscrete; let toDiscrete = T.toDiscrete;
let toScaledContinuous = T.toScaledContinuous; let toScaledContinuous = T.toScaledContinuous;
@ -103,6 +105,7 @@ module Continuous = {
type integral = DistTypes.continuousShape; type integral = DistTypes.continuousShape;
let minX = shapeFn(XYShape.minX); let minX = shapeFn(XYShape.minX);
let maxX = shapeFn(XYShape.maxX); let maxX = shapeFn(XYShape.maxX);
let toDiscreteProbabilityMass = t => 0.0;
let pointwiseFmap = (fn, t: t) => let pointwiseFmap = (fn, t: t) =>
t |> xyShape |> XYShape.pointwiseMap(fn) |> fromShape; t |> xyShape |> XYShape.pointwiseMap(fn) |> fromShape;
let toShape = (t: t): DistTypes.shape => Continuous(t); let toShape = (t: t): DistTypes.shape => Continuous(t);
@ -160,6 +163,7 @@ module Discrete = {
t |> integral(~cache) |> Continuous.lastY; t |> integral(~cache) |> Continuous.lastY;
let minX = XYShape.minX; let minX = XYShape.minX;
let maxX = XYShape.maxX; let maxX = XYShape.maxX;
let toDiscreteProbabilityMass = t => 1.0;
let pointwiseFmap = XYShape.pointwiseMap; let pointwiseFmap = XYShape.pointwiseMap;
let toShape = (t: t): DistTypes.shape => Discrete(t); let toShape = (t: t): DistTypes.shape => Discrete(t);
let toContinuous = _ => None; let toContinuous = _ => None;
@ -224,6 +228,7 @@ module Mixed = {
let toShape = (t: t): DistTypes.shape => Mixed(t); let toShape = (t: t): DistTypes.shape => Mixed(t);
let toContinuous = ({continuous}: t) => Some(continuous); let toContinuous = ({continuous}: t) => Some(continuous);
let toDiscrete = ({discrete}: t) => Some(discrete); let toDiscrete = ({discrete}: t) => Some(discrete);
let toDiscreteProbabilityMass = ({discreteProbabilityMassFraction}: t) => discreteProbabilityMassFraction;
let xToY = (f, {discrete, continuous} as t: t) => { let xToY = (f, {discrete, continuous} as t: t) => {
let c = let c =
continuous continuous
@ -356,6 +361,17 @@ module Shape = {
Continuous.T.toDiscrete, Continuous.T.toDiscrete,
), ),
); );
let toDiscreteProbabilityMass = (t: t) =>
mapToAll(
t,
(
Mixed.T.toDiscreteProbabilityMass,
Discrete.T.toDiscreteProbabilityMass,
Continuous.T.toDiscreteProbabilityMass,
),
);
let toScaledDiscrete = (t: t) => let toScaledDiscrete = (t: t) =>
mapToAll( mapToAll(
t, t,
@ -508,6 +524,8 @@ module DistPlus = {
let minX = shapeFn(Shape.T.minX); let minX = shapeFn(Shape.T.minX);
let maxX = shapeFn(Shape.T.maxX); let maxX = shapeFn(Shape.T.maxX);
let toDiscreteProbabilityMass =
shapeFn(Shape.T.toDiscreteProbabilityMass);
// This bit is kind of akward, could probably use rethinking. // This bit is kind of akward, could probably use rethinking.
let integral = (~cache, t: t) => let integral = (~cache, t: t) =>

View File

@ -64,7 +64,6 @@ module ModelForm = {
{type_.name |> ReasonReact.string} {type_.name |> ReasonReact.string}
</label> </label>
<ValueForm <ValueForm
key={type_.id}
type_ type_
value value
onChange={newValue => onChange={newValue =>