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(
DistPlusIngredients.make(
~guesstimatorString=
"uniform(0,1) > 0.036 ? lognormal(6.652, -0.41): 0",
"uniform(0,1) > 0.3 ? lognormal(6.652, -0.41): 0",
~domain=
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 = {
[@react.component]
let make = (~distPlus: DistTypes.distPlus, ~onHover) => {
@ -16,9 +28,15 @@ module DistPlusChart = {
let maxX = T.maxX(distPlus);
let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson;
let toDiscreteProbabilityMass =
distPlus |> Distributions.DistPlus.T.toDiscreteProbabilityMass;
let (yMaxDiscreteDomainFactor, yMaxContinuousDomainFactor) =
adjustBoth(toDiscreteProbabilityMass);
<DistributionPlot
minX
maxX
yMaxDiscreteDomainFactor
yMaxContinuousDomainFactor
height=120
?discrete
?continuous

View File

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

View File

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

View File

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

View File

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