Change extrapolation handling in Continuous.combinePointwise to explicit distributionType param
This commit is contained in:
parent
f3922761f4
commit
d9141f6b2b
|
@ -209,30 +209,9 @@ let toDiscretePointMassesFromDiscrete = (s: DistTypes.xyShape): pointMassesWithM
|
||||||
let {xs, ys}: XYShape.T.t = s;
|
let {xs, ys}: XYShape.T.t = s;
|
||||||
let n = E.A.length(xs);
|
let n = E.A.length(xs);
|
||||||
|
|
||||||
let masses: array(float) = Belt.Array.makeUninitializedUnsafe(n); // doesn't include the fake first and last points
|
let masses: array(float) = Belt.Array.makeBy(n, i => ys[i]);
|
||||||
let means: array(float) = Belt.Array.makeUninitializedUnsafe(n);
|
let means: array(float) = Belt.Array.makeBy(n, i => xs[i]);
|
||||||
let variances: array(float) = Belt.Array.makeUninitializedUnsafe(n);
|
let variances: array(float) = Belt.Array.makeBy(n, i => 0.0);
|
||||||
|
|
||||||
for (i in 0 to n - 1) {
|
|
||||||
Belt.Array.set(
|
|
||||||
masses,
|
|
||||||
i,
|
|
||||||
ys[i]
|
|
||||||
) |> ignore;
|
|
||||||
|
|
||||||
Belt.Array.set(
|
|
||||||
means,
|
|
||||||
i,
|
|
||||||
xs[i]
|
|
||||||
) |> ignore;
|
|
||||||
|
|
||||||
Belt.Array.set(
|
|
||||||
variances,
|
|
||||||
i,
|
|
||||||
0.0
|
|
||||||
) |> ignore;
|
|
||||||
();
|
|
||||||
};
|
|
||||||
|
|
||||||
{n, masses, means, variances};
|
{n, masses, means, variances};
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,7 +41,7 @@ let combinePointwise =
|
||||||
(
|
(
|
||||||
~integralSumCachesFn=(_, _) => None,
|
~integralSumCachesFn=(_, _) => None,
|
||||||
~integralCachesFn: (t, t) => option(t) =(_, _) => None,
|
~integralCachesFn: (t, t) => option(t) =(_, _) => None,
|
||||||
~extrapolation=`UseZero,
|
~distributionType: DistTypes.distributionType = `PDF,
|
||||||
fn: (float, float) => float,
|
fn: (float, float) => float,
|
||||||
t1: DistTypes.continuousShape,
|
t1: DistTypes.continuousShape,
|
||||||
t2: DistTypes.continuousShape,
|
t2: DistTypes.continuousShape,
|
||||||
|
@ -68,6 +68,11 @@ let combinePointwise =
|
||||||
| (`Stepwise, `Linear) => (stepwiseToLinear(t1), t2);
|
| (`Stepwise, `Linear) => (stepwiseToLinear(t1), t2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let extrapolation = switch (distributionType) {
|
||||||
|
| `PDF => `UseZero
|
||||||
|
| `CDF => `UseOutermostPoints
|
||||||
|
};
|
||||||
|
|
||||||
let interpolator = XYShape.XtoY.continuousInterpolator(t1.interpolation, extrapolation);
|
let interpolator = XYShape.XtoY.continuousInterpolator(t1.interpolation, extrapolation);
|
||||||
|
|
||||||
make(
|
make(
|
||||||
|
|
|
@ -9,6 +9,11 @@ type domain =
|
||||||
| RightLimited(domainLimit)
|
| RightLimited(domainLimit)
|
||||||
| LeftAndRightLimited(domainLimit, domainLimit);
|
| LeftAndRightLimited(domainLimit, domainLimit);
|
||||||
|
|
||||||
|
type distributionType = [
|
||||||
|
| `PDF
|
||||||
|
| `CDF
|
||||||
|
];
|
||||||
|
|
||||||
type xyShape = {
|
type xyShape = {
|
||||||
xs: array(float),
|
xs: array(float),
|
||||||
ys: array(float),
|
ys: array(float),
|
||||||
|
|
|
@ -131,7 +131,7 @@ module PointwiseCombination = {
|
||||||
`RenderedDist(
|
`RenderedDist(
|
||||||
Shape.combinePointwise(
|
Shape.combinePointwise(
|
||||||
~integralSumCachesFn=(a, b) => Some(a +. b),
|
~integralSumCachesFn=(a, b) => Some(a +. b),
|
||||||
~integralCachesFn=(a, b) => Some(Continuous.combinePointwise(~extrapolation=`UseOutermostPoints, (+.), a, b)),
|
~integralCachesFn=(a, b) => Some(Continuous.combinePointwise(~distributionType=`CDF, (+.), a, b)),
|
||||||
(+.),
|
(+.),
|
||||||
rs1,
|
rs1,
|
||||||
rs2,
|
rs2,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user