Fixed mass-ratio of continuous vs. discrete

This commit is contained in:
Ozzie Gooen 2020-02-25 12:54:52 +00:00
parent 67ee34d821
commit a940fa30b7
4 changed files with 74 additions and 20 deletions

View File

@ -24,7 +24,7 @@ let distributions = () =>
<h2> {"Single-Discrete" |> ReasonReact.string} </h2> <h2> {"Single-Discrete" |> ReasonReact.string} </h2>
{setup( {setup(
DistPlusIngredients.make( DistPlusIngredients.make(
~guesstimatorString="mm(5 to 20, floor(normal(20,2)), [.5, .05])", ~guesstimatorString="mm(5 to 20, floor(normal(20,2)), [.5, .5])",
~domain=Complete, ~domain=Complete,
(), (),
), ),

View File

@ -77,6 +77,9 @@ let make = (~distPlus: DistTypes.distPlus) => {
<th className="px-4 py-2"> <th className="px-4 py-2">
{"Y Integral to Point" |> ReasonReact.string} {"Y Integral to Point" |> ReasonReact.string}
</th> </th>
<th className="px-4 py-2">
{"Y Integral Total" |> ReasonReact.string}
</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -104,12 +107,73 @@ let make = (~distPlus: DistTypes.distPlus) => {
|> E.Float.with2DigitsPrecision |> E.Float.with2DigitsPrecision
|> ReasonReact.string} |> ReasonReact.string}
</th> </th>
</tr>
</tbody>
</table>
<table className="table-auto">
<thead>
<tr>
<th className="px-4 py-2">
{"Y Integral Total" |> ReasonReact.string}
</th>
<th className="px-4 py-2">
{"Continuous Total" |> ReasonReact.string}
</th>
<th className="px-4 py-2">
{"Scaled Continuous Total" |> ReasonReact.string}
</th>
<th className="px-4 py-2">
{"Discrete Total" |> ReasonReact.string}
</th>
<th className="px-4 py-2">
{"Scaled Discrete Total" |> ReasonReact.string}
</th>
</tr>
</thead>
<tbody>
<tr>
<th className="px-4 py-2 border "> <th className="px-4 py-2 border ">
{distPlus {distPlus
|> Distributions.DistPlus.T.Integral.sum(~cache=None) |> Distributions.DistPlus.T.Integral.sum(~cache=None)
|> E.Float.with2DigitsPrecision |> E.Float.with2DigitsPrecision
|> ReasonReact.string} |> ReasonReact.string}
</th> </th>
<th className="px-4 py-2 border ">
{distPlus
|> Distributions.DistPlus.T.toContinuous
|> E.O.fmap(
Distributions.Continuous.T.Integral.sum(~cache=None),
)
|> E.O.fmap(E.Float.with2DigitsPrecision)
|> E.O.default("")
|> ReasonReact.string}
</th>
<th className="px-4 py-2 border ">
{distPlus
|> Distributions.DistPlus.T.toScaledContinuous
|> E.O.fmap(
Distributions.Continuous.T.Integral.sum(~cache=None),
)
|> E.O.fmap(E.Float.with2DigitsPrecision)
|> E.O.default("")
|> ReasonReact.string}
</th>
<th className="px-4 py-2 border ">
{distPlus
|> Distributions.DistPlus.T.toDiscrete
|> E.O.fmap(Distributions.Discrete.T.Integral.sum(~cache=None))
|> E.O.fmap(E.Float.with2DigitsPrecision)
|> E.O.default("")
|> ReasonReact.string}
</th>
<th className="px-4 py-2 border ">
{distPlus
|> Distributions.DistPlus.T.toScaledDiscrete
|> E.O.fmap(Distributions.Discrete.T.Integral.sum(~cache=None))
|> E.O.fmap(E.Float.with2DigitsPrecision)
|> E.O.default("")
|> ReasonReact.string}
</th>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -191,21 +191,6 @@ module Mixed = {
discreteProbabilityMassFraction, discreteProbabilityMassFraction,
}; };
let clean = (t: DistTypes.mixedShape): option(DistTypes.shape) => {
switch (t) {
| {
continuous: {xyShape: {xs: [||], ys: [||]}},
discrete: {xs: [||], ys: [||]},
} =>
None
| {continuous, discrete: {xs: [||], ys: [||]}} =>
Some(Continuous(continuous))
| {continuous: {xyShape: {xs: [||], ys: [||]}}, discrete} =>
Some(Discrete(discrete))
| shape => Some(Mixed(shape))
};
};
// todo: Put into scaling module // todo: Put into scaling module
let scaleDiscreteFn = let scaleDiscreteFn =
({discreteProbabilityMassFraction}: DistTypes.mixedShape, f) => ({discreteProbabilityMassFraction}: DistTypes.mixedShape, f) =>

View File

@ -21,16 +21,21 @@ let buildSimple = (~continuous, ~discrete): option(DistTypes.shape) => {
Distributions.Discrete.T.Integral.sum(~cache=None, discrete); Distributions.Discrete.T.Integral.sum(~cache=None, discrete);
let discrete = let discrete =
Distributions.Discrete.T.scaleToIntegralSum(~intendedSum=1.0, discrete); Distributions.Discrete.T.scaleToIntegralSum(~intendedSum=1.0, discrete);
let foobar = let continuous =
Distributions.Continuous.T.scaleToIntegralSum(
~intendedSum=1.0,
continuous,
);
let mixedDist =
Distributions.Mixed.make( Distributions.Mixed.make(
~continuous, ~continuous,
~discrete, ~discrete,
~discreteProbabilityMassFraction, ~discreteProbabilityMassFraction,
) );
|> Distributions.Mixed.clean; Some(Mixed(mixedDist));
foobar;
}; };
}; };
let build = (~continuous, ~discrete, ~assumptions) => let build = (~continuous, ~discrete, ~assumptions) =>
switch (assumptions) { switch (assumptions) {
| { | {