Rename flip argument to be more descriptive
This commit is contained in:
parent
62653d55b4
commit
6bfecf2204
|
@ -9,7 +9,7 @@ describe("Combining Continuous and Discrete Distributions", () => {
|
|||
#Multiply,
|
||||
{xs: [0., 1.], ys: [1., 1.]},
|
||||
{xs: [-1.], ys: [1.]},
|
||||
false
|
||||
~discretePosition=Second,
|
||||
),
|
||||
), // Multiply distribution by -1
|
||||
true,
|
||||
|
|
|
@ -187,18 +187,20 @@ let toDiscretePointMassesFromDiscrete = (s: PointSetTypes.xyShape): pointMassesW
|
|||
{n: n, masses: masses, means: means, variances: variances}
|
||||
}
|
||||
|
||||
type argumentPosition = First | Second
|
||||
|
||||
let combineShapesContinuousDiscrete = (
|
||||
op: Operation.convolutionOperation,
|
||||
continuousShape: PointSetTypes.xyShape,
|
||||
discreteShape: PointSetTypes.xyShape,
|
||||
flip: bool,
|
||||
~discretePosition: argumentPosition,
|
||||
): PointSetTypes.xyShape => {
|
||||
let t1n = continuousShape |> XYShape.T.length
|
||||
let t2n = discreteShape |> XYShape.T.length
|
||||
|
||||
// each x pair is added/subtracted
|
||||
let opFunc = Operation.Convolution.toFn(op)
|
||||
let fn = flip ? (a, b) => opFunc(b, a) : opFunc
|
||||
let fn = discretePosition == First ? (a, b) => opFunc(b, a) : opFunc
|
||||
|
||||
let outXYShapes: array<array<(float, float)>> = Belt.Array.makeUninitializedUnsafe(t2n)
|
||||
|
||||
|
@ -212,7 +214,7 @@ let combineShapesContinuousDiscrete = (
|
|||
// When this operation is flipped (like 1 - normal(5, 2)) then the
|
||||
// x axis coordinates would all come out the wrong order. So we need
|
||||
// to fill them out in the opposite direction
|
||||
let index = flip ? t1n - 1 - i : i
|
||||
let index = discretePosition == First ? t1n - 1 - i : i
|
||||
Belt.Array.set(
|
||||
dxyShape,
|
||||
index,
|
||||
|
|
|
@ -278,7 +278,7 @@ let combineAlgebraicallyWithDiscrete = (
|
|||
op: Operation.convolutionOperation,
|
||||
t1: t,
|
||||
t2: PointSetTypes.discreteShape,
|
||||
flip: bool,
|
||||
~discretePosition: AlgebraicShapeCombination.argumentPosition,
|
||||
) => {
|
||||
let t1s = t1 |> getShape
|
||||
let t2s = t2.xyShape // TODO would like to use Discrete.getShape here, but current file structure doesn't allow for that
|
||||
|
@ -295,7 +295,7 @@ let combineAlgebraicallyWithDiscrete = (
|
|||
op,
|
||||
continuousAsLinear |> getShape,
|
||||
t2s,
|
||||
flip,
|
||||
~discretePosition,
|
||||
)
|
||||
|
||||
let combinedIntegralSum = switch op {
|
||||
|
|
|
@ -281,13 +281,13 @@ let combineAlgebraically = (op: Operation.convolutionOperation, t1: t, t2: t): t
|
|||
op,
|
||||
t2.continuous,
|
||||
t1.discrete,
|
||||
true,
|
||||
~discretePosition=First,
|
||||
)
|
||||
let cdConvResult = Continuous.combineAlgebraicallyWithDiscrete(
|
||||
op,
|
||||
t1.continuous,
|
||||
t2.discrete,
|
||||
false,
|
||||
~discretePosition=Second,
|
||||
)
|
||||
let continuousConvResult = Continuous.sum([ccConvResult, dcConvResult, cdConvResult])
|
||||
|
||||
|
|
|
@ -47,9 +47,19 @@ let combineAlgebraically = (op: Operation.convolutionOperation, t1: t, t2: t): t
|
|||
| (Continuous(m1), Continuous(m2)) =>
|
||||
Continuous.combineAlgebraically(op, m1, m2) |> Continuous.T.toPointSetDist
|
||||
| (Discrete(m1), Continuous(m2)) =>
|
||||
Continuous.combineAlgebraicallyWithDiscrete(op, m2, m1, true) |> Continuous.T.toPointSetDist
|
||||
Continuous.combineAlgebraicallyWithDiscrete(
|
||||
op,
|
||||
m2,
|
||||
m1,
|
||||
~discretePosition=First,
|
||||
) |> Continuous.T.toPointSetDist
|
||||
| (Continuous(m1), Discrete(m2)) =>
|
||||
Continuous.combineAlgebraicallyWithDiscrete(op, m1, m2, false) |> Continuous.T.toPointSetDist
|
||||
Continuous.combineAlgebraicallyWithDiscrete(
|
||||
op,
|
||||
m1,
|
||||
m2,
|
||||
~discretePosition=Second,
|
||||
) |> Continuous.T.toPointSetDist
|
||||
| (Discrete(m1), Discrete(m2)) =>
|
||||
Discrete.combineAlgebraically(op, m1, m2) |> Discrete.T.toPointSetDist
|
||||
| (m1, m2) => Mixed.combineAlgebraically(op, toMixed(m1), toMixed(m2)) |> Mixed.T.toPointSetDist
|
||||
|
|
Loading…
Reference in New Issue
Block a user