Tried to fix changes from skosch
This commit is contained in:
parent
db790daab9
commit
84b6d7176c
|
@ -201,59 +201,32 @@ module T =
|
||||||
each discrete data point, and then adds them all together. */
|
each discrete data point, and then adds them all together. */
|
||||||
let combineAlgebraicallyWithDiscrete =
|
let combineAlgebraicallyWithDiscrete =
|
||||||
(
|
(
|
||||||
~downsample=false,
|
|
||||||
op: ExpressionTypes.algebraicOperation,
|
op: ExpressionTypes.algebraicOperation,
|
||||||
t1: t,
|
t1: t,
|
||||||
t2: DistTypes.discreteShape,
|
t2: DistTypes.discreteShape,
|
||||||
) => {
|
) => {
|
||||||
let t1s = t1 |> getShape;
|
let s1 = t1 |> getShape;
|
||||||
let t2s = t2.xyShape; // would like to use Discrete.getShape here, but current file structure doesn't allow for that
|
let s2 = t2.xyShape;
|
||||||
let t1n = t1s |> XYShape.T.length;
|
let t1n = s1 |> XYShape.T.length;
|
||||||
let t2n = t2s |> XYShape.T.length;
|
let t2n = s2 |> XYShape.T.length;
|
||||||
|
if (t1n == 0 || t2n == 0) {
|
||||||
let fn = Operation.Algebraic.toFn(op);
|
empty;
|
||||||
|
} else {
|
||||||
let outXYShapes: array(array((float, float))) =
|
let combinedShape =
|
||||||
Belt.Array.makeUninitializedUnsafe(t2n);
|
AlgebraicShapeCombination.combineShapesContinuousDiscrete(op, s1, s2);
|
||||||
|
|
||||||
for (j in 0 to t2n - 1) {
|
|
||||||
// for each one of the discrete points
|
|
||||||
// create a new distribution, as long as the original continuous one
|
|
||||||
|
|
||||||
let dxyShape: array((float, float)) =
|
|
||||||
Belt.Array.makeUninitializedUnsafe(t1n);
|
|
||||||
for (i in 0 to t1n - 1) {
|
|
||||||
let _ =
|
|
||||||
Belt.Array.set(
|
|
||||||
dxyShape,
|
|
||||||
i,
|
|
||||||
(fn(t1s.xs[i], t2s.xs[j]), t1s.ys[i] *. t2s.ys[j]),
|
|
||||||
);
|
|
||||||
();
|
|
||||||
};
|
|
||||||
|
|
||||||
let _ = Belt.Array.set(outXYShapes, j, dxyShape);
|
|
||||||
();
|
|
||||||
};
|
|
||||||
|
|
||||||
let combinedIntegralSum =
|
let combinedIntegralSum =
|
||||||
Common.combineIntegralSums(
|
Common.combineIntegralSums(
|
||||||
(a, b) => Some(a *. b),
|
(a, b) => Some(a *. b),
|
||||||
t1.knownIntegralSum,
|
t1.knownIntegralSum,
|
||||||
t2.knownIntegralSum,
|
t2.knownIntegralSum,
|
||||||
);
|
);
|
||||||
|
// return a new Continuous distribution
|
||||||
outXYShapes
|
make(`Linear, combinedShape, combinedIntegralSum);
|
||||||
|> E.A.fmap(s => {
|
};
|
||||||
let xyShape = XYShape.T.fromZippedArray(s);
|
|
||||||
make(`Linear, xyShape, None);
|
|
||||||
})
|
|
||||||
|> reduce((+.))
|
|
||||||
|> updateKnownIntegralSum(combinedIntegralSum);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let combineAlgebraically =
|
let combineAlgebraically =
|
||||||
(~downsample=false, op: ExpressionTypes.algebraicOperation, t1: t, t2: t) => {
|
(op: ExpressionTypes.algebraicOperation, t1: t, t2: t) => {
|
||||||
let s1 = t1 |> getShape;
|
let s1 = t1 |> getShape;
|
||||||
let s2 = t2 |> getShape;
|
let s2 = t2 |> getShape;
|
||||||
let t1n = s1 |> XYShape.T.length;
|
let t1n = s1 |> XYShape.T.length;
|
||||||
|
|
|
@ -257,7 +257,7 @@ module T =
|
||||||
});
|
});
|
||||||
|
|
||||||
let combineAlgebraically =
|
let combineAlgebraically =
|
||||||
(~downsample=false, op: ExpressionTypes.algebraicOperation, t1: t, t2: t)
|
(op: ExpressionTypes.algebraicOperation, t1: t, t2: t)
|
||||||
: t => {
|
: t => {
|
||||||
// Discrete convolution can cause a huge increase in the number of samples,
|
// Discrete convolution can cause a huge increase in the number of samples,
|
||||||
// so we'll first downsample.
|
// so we'll first downsample.
|
||||||
|
@ -265,33 +265,31 @@ let combineAlgebraically =
|
||||||
// An alternative (to be explored in the future) may be to first perform the full convolution and then to downsample the result;
|
// An alternative (to be explored in the future) may be to first perform the full convolution and then to downsample the result;
|
||||||
// to use non-uniform fast Fourier transforms (for addition only), add web workers or gpu.js, etc. ...
|
// to use non-uniform fast Fourier transforms (for addition only), add web workers or gpu.js, etc. ...
|
||||||
|
|
||||||
let downsampleIfTooLarge = (t: t) => {
|
// we have to figure out where to downsample, and how to effectively
|
||||||
let sqtl = sqrt(float_of_int(totalLength(t)));
|
//let downsampleIfTooLarge = (t: t) => {
|
||||||
sqtl > 10. && downsample ? T.downsample(int_of_float(sqtl), t) : t;
|
// let sqtl = sqrt(float_of_int(totalLength(t)));
|
||||||
};
|
// sqtl > 10 ? T.downsample(int_of_float(sqtl), t) : t;
|
||||||
|
//};
|
||||||
|
|
||||||
let t1d = downsampleIfTooLarge(t1);
|
let t1d = t1;
|
||||||
let t2d = downsampleIfTooLarge(t2);
|
let t2d = t2;
|
||||||
|
|
||||||
// continuous (*) continuous => continuous, but also
|
// continuous (*) continuous => continuous, but also
|
||||||
// discrete (*) continuous => continuous (and vice versa). We have to take care of all combos and then combine them:
|
// discrete (*) continuous => continuous (and vice versa). We have to take care of all combos and then combine them:
|
||||||
let ccConvResult =
|
let ccConvResult =
|
||||||
Continuous.combineAlgebraically(
|
Continuous.combineAlgebraically(
|
||||||
~downsample=false,
|
|
||||||
op,
|
op,
|
||||||
t1d.continuous,
|
t1d.continuous,
|
||||||
t2d.continuous,
|
t2d.continuous,
|
||||||
);
|
);
|
||||||
let dcConvResult =
|
let dcConvResult =
|
||||||
Continuous.combineAlgebraicallyWithDiscrete(
|
Continuous.combineAlgebraicallyWithDiscrete(
|
||||||
~downsample=false,
|
|
||||||
op,
|
op,
|
||||||
t2d.continuous,
|
t2d.continuous,
|
||||||
t1d.discrete,
|
t1d.discrete,
|
||||||
);
|
);
|
||||||
let cdConvResult =
|
let cdConvResult =
|
||||||
Continuous.combineAlgebraicallyWithDiscrete(
|
Continuous.combineAlgebraicallyWithDiscrete(
|
||||||
~downsample=false,
|
|
||||||
op,
|
op,
|
||||||
t1d.continuous,
|
t1d.continuous,
|
||||||
t2d.discrete,
|
t2d.discrete,
|
||||||
|
|
|
@ -27,14 +27,13 @@ let combineAlgebraically =
|
||||||
switch (t1, t2) {
|
switch (t1, t2) {
|
||||||
| (Continuous(m1), Continuous(m2)) =>
|
| (Continuous(m1), Continuous(m2)) =>
|
||||||
DistTypes.Continuous(
|
DistTypes.Continuous(
|
||||||
Continuous.combineAlgebraically(~downsample=true, op, m1, m2),
|
Continuous.combineAlgebraically(op, m1, m2),
|
||||||
)
|
)
|
||||||
| (Discrete(m1), Discrete(m2)) =>
|
| (Discrete(m1), Discrete(m2)) =>
|
||||||
DistTypes.Discrete(Discrete.combineAlgebraically(op, m1, m2))
|
DistTypes.Discrete(Discrete.combineAlgebraically(op, m1, m2))
|
||||||
| (m1, m2) =>
|
| (m1, m2) =>
|
||||||
DistTypes.Mixed(
|
DistTypes.Mixed(
|
||||||
Mixed.combineAlgebraically(
|
Mixed.combineAlgebraically(
|
||||||
~downsample=true,
|
|
||||||
op,
|
op,
|
||||||
toMixed(m1),
|
toMixed(m1),
|
||||||
toMixed(m2),
|
toMixed(m2),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user