More refactors of |> to ->
This commit is contained in:
parent
539c7cf783
commit
c158b4183b
|
@ -29,7 +29,7 @@ let normalize = (t: t) =>
|
||||||
| #SampleSet(_) => t
|
| #SampleSet(_) => t
|
||||||
}
|
}
|
||||||
|
|
||||||
let operationToFloat = (toPointSet: toPointSetFn, fnName, t) => {
|
let operationToFloat = (t, toPointSet: toPointSetFn, fnName) => {
|
||||||
let symbolicSolution = switch t {
|
let symbolicSolution = switch t {
|
||||||
| #Symbolic(r) =>
|
| #Symbolic(r) =>
|
||||||
switch SymbolicDist.T.operate(fnName, r) {
|
switch SymbolicDist.T.operate(fnName, r) {
|
||||||
|
@ -83,10 +83,10 @@ module Truncate = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let run = (
|
let run = (
|
||||||
|
t: t,
|
||||||
toPointSet: toPointSetFn,
|
toPointSet: toPointSetFn,
|
||||||
leftCutoff: option<float>,
|
leftCutoff: option<float>,
|
||||||
rightCutoff: option<float>,
|
rightCutoff: option<float>,
|
||||||
t: t,
|
|
||||||
): result<t, error> => {
|
): result<t, error> => {
|
||||||
let doesNotNeedCutoff = E.O.isNone(leftCutoff) && E.O.isNone(rightCutoff)
|
let doesNotNeedCutoff = E.O.isNone(leftCutoff) && E.O.isNone(rightCutoff)
|
||||||
if doesNotNeedCutoff {
|
if doesNotNeedCutoff {
|
||||||
|
@ -95,7 +95,7 @@ module Truncate = {
|
||||||
switch trySymbolicSimplification(leftCutoff, rightCutoff, t) {
|
switch trySymbolicSimplification(leftCutoff, rightCutoff, t) {
|
||||||
| Some(r) => Ok(r)
|
| Some(r) => Ok(r)
|
||||||
| None =>
|
| None =>
|
||||||
toPointSet(t) |> E.R.fmap(t =>
|
toPointSet(t)->E.R.fmap2(t =>
|
||||||
#PointSet(PointSetDist.T.truncate(leftCutoff, rightCutoff, t))
|
#PointSet(PointSetDist.T.truncate(leftCutoff, rightCutoff, t))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ module AlgebraicCombination = {
|
||||||
t1: t,
|
t1: t,
|
||||||
t2: t,
|
t2: t,
|
||||||
) =>
|
) =>
|
||||||
E.R.merge(toPointSet(t1), toPointSet(t2)) |> E.R.fmap(((a, b)) =>
|
E.R.merge(toPointSet(t1), toPointSet(t2))->E.R.fmap2(((a, b)) =>
|
||||||
PointSetDist.combineAlgebraically(operation, a, b)
|
PointSetDist.combineAlgebraically(operation, a, b)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -145,8 +145,8 @@ module AlgebraicCombination = {
|
||||||
t2: t,
|
t2: t,
|
||||||
) => {
|
) => {
|
||||||
let operation = Operation.Algebraic.toFn(operation)
|
let operation = Operation.Algebraic.toFn(operation)
|
||||||
E.R.merge(toSampleSet(t1), toSampleSet(t2)) |> E.R.fmap(((a, b)) => {
|
E.R.merge(toSampleSet(t1), toSampleSet(t2)) -> E.R.fmap2(((a, b)) => {
|
||||||
Belt.Array.zip(a, b) |> E.A.fmap(((a, b)) => operation(a, b))
|
Belt.Array.zip(a, b) -> E.A.fmap2(((a, b)) => operation(a, b))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ module AlgebraicCombination = {
|
||||||
switch x {
|
switch x {
|
||||||
| #Symbolic(#Float(_)) => 1
|
| #Symbolic(#Float(_)) => 1
|
||||||
| #Symbolic(_) => 1000
|
| #Symbolic(_) => 1000
|
||||||
| #PointSet(Discrete(m)) => m.xyShape |> XYShape.T.length
|
| #PointSet(Discrete(m)) => m.xyShape -> XYShape.T.length
|
||||||
| #PointSet(Mixed(_)) => 1000
|
| #PointSet(Mixed(_)) => 1000
|
||||||
| #PointSet(Continuous(_)) => 1000
|
| #PointSet(Continuous(_)) => 1000
|
||||||
| _ => 1000
|
| _ => 1000
|
||||||
|
@ -167,10 +167,10 @@ module AlgebraicCombination = {
|
||||||
: #CalculateWithConvolution
|
: #CalculateWithConvolution
|
||||||
|
|
||||||
let run = (
|
let run = (
|
||||||
|
t1: t,
|
||||||
toPointSet: toPointSetFn,
|
toPointSet: toPointSetFn,
|
||||||
toSampleSet: toSampleSetFn,
|
toSampleSet: toSampleSetFn,
|
||||||
algebraicOp,
|
algebraicOp,
|
||||||
t1: t,
|
|
||||||
t2: t,
|
t2: t,
|
||||||
): result<t, error> => {
|
): result<t, error> => {
|
||||||
switch tryAnalyticalSimplification(algebraicOp, t1, t2) {
|
switch tryAnalyticalSimplification(algebraicOp, t1, t2) {
|
||||||
|
@ -190,7 +190,7 @@ module AlgebraicCombination = {
|
||||||
let algebraicCombination = AlgebraicCombination.run
|
let algebraicCombination = AlgebraicCombination.run
|
||||||
|
|
||||||
//TODO: Add faster pointwiseCombine fn
|
//TODO: Add faster pointwiseCombine fn
|
||||||
let pointwiseCombination = (toPointSet: toPointSetFn, operation, t2: t, t1: t): result<
|
let pointwiseCombination = (t1: t, toPointSet: toPointSetFn, operation, t2: t): result<
|
||||||
t,
|
t,
|
||||||
error,
|
error,
|
||||||
> => {
|
> => {
|
||||||
|
@ -202,10 +202,10 @@ let pointwiseCombination = (toPointSet: toPointSetFn, operation, t2: t, t1: t):
|
||||||
}
|
}
|
||||||
|
|
||||||
let pointwiseCombinationFloat = (
|
let pointwiseCombinationFloat = (
|
||||||
|
t: t,
|
||||||
toPointSet: toPointSetFn,
|
toPointSet: toPointSetFn,
|
||||||
operation: GenericDist_Types.Operation.arithmeticOperation,
|
operation: GenericDist_Types.Operation.arithmeticOperation,
|
||||||
f: float,
|
f: float,
|
||||||
t: t,
|
|
||||||
): result<t, error> => {
|
): result<t, error> => {
|
||||||
switch operation {
|
switch operation {
|
||||||
| #Add | #Subtract => Error(GenericDist_Types.DistributionVerticalShiftIsInvalid)
|
| #Add | #Subtract => Error(GenericDist_Types.DistributionVerticalShiftIsInvalid)
|
||||||
|
@ -227,9 +227,9 @@ let pointwiseCombinationFloat = (
|
||||||
|
|
||||||
//Note: The result should always cumulatively sum to 1.
|
//Note: The result should always cumulatively sum to 1.
|
||||||
let mixture = (
|
let mixture = (
|
||||||
|
values: array<(t, float)>,
|
||||||
scaleMultiply: scaleMultiplyFn,
|
scaleMultiply: scaleMultiplyFn,
|
||||||
pointwiseAdd: pointwiseAddFn,
|
pointwiseAdd: pointwiseAddFn,
|
||||||
values: array<(t, float)>,
|
|
||||||
) => {
|
) => {
|
||||||
if E.A.length(values) == 0 {
|
if E.A.length(values) == 0 {
|
||||||
Error(GenericDist_Types.Other("mixture must have at least 1 element"))
|
Error(GenericDist_Types.Other("mixture must have at least 1 element"))
|
||||||
|
|
|
@ -13,32 +13,32 @@ let toString: t => string
|
||||||
|
|
||||||
let normalize: t => t
|
let normalize: t => t
|
||||||
|
|
||||||
let operationToFloat: (toPointSetFn, Operation.distToFloatOperation, t) => result<float, error>
|
let operationToFloat: (t, toPointSetFn, Operation.distToFloatOperation) => result<float, error>
|
||||||
|
|
||||||
let toPointSet: (t, int) => result<PointSetTypes.pointSetDist, error>
|
let toPointSet: (t, int) => result<PointSetTypes.pointSetDist, error>
|
||||||
|
|
||||||
let truncate: (toPointSetFn, option<float>, option<float>, t) => result<t, error>
|
let truncate: (t, toPointSetFn, option<float>, option<float>) => result<t, error>
|
||||||
|
|
||||||
let algebraicCombination: (
|
let algebraicCombination: (
|
||||||
|
t,
|
||||||
toPointSetFn,
|
toPointSetFn,
|
||||||
toSampleSetFn,
|
toSampleSetFn,
|
||||||
GenericDist_Types.Operation.arithmeticOperation,
|
GenericDist_Types.Operation.arithmeticOperation,
|
||||||
t,
|
t,
|
||||||
t,
|
|
||||||
) => result<t, error>
|
) => result<t, error>
|
||||||
|
|
||||||
let pointwiseCombination: (
|
let pointwiseCombination: (
|
||||||
|
t,
|
||||||
toPointSetFn,
|
toPointSetFn,
|
||||||
GenericDist_Types.Operation.arithmeticOperation,
|
GenericDist_Types.Operation.arithmeticOperation,
|
||||||
t,
|
t,
|
||||||
t,
|
|
||||||
) => result<t, error>
|
) => result<t, error>
|
||||||
|
|
||||||
let pointwiseCombinationFloat: (
|
let pointwiseCombinationFloat: (
|
||||||
|
t,
|
||||||
toPointSetFn,
|
toPointSetFn,
|
||||||
GenericDist_Types.Operation.arithmeticOperation,
|
GenericDist_Types.Operation.arithmeticOperation,
|
||||||
float,
|
float,
|
||||||
t,
|
|
||||||
) => result<t, error>
|
) => result<t, error>
|
||||||
|
|
||||||
let mixture: (scaleMultiplyFn, pointwiseAddFn, array<(t, float)>) => result<t, error>
|
let mixture: (array<(t, float)>, scaleMultiplyFn, pointwiseAddFn) => result<t, error>
|
||||||
|
|
|
@ -93,7 +93,7 @@ let rec run = (extra, fnName: operation): outputType => {
|
||||||
let fromDistFn = (subFn: GenericDist_Types.Operation.fromDist, dist: genericDist) =>
|
let fromDistFn = (subFn: GenericDist_Types.Operation.fromDist, dist: genericDist) =>
|
||||||
switch subFn {
|
switch subFn {
|
||||||
| #toFloat(fnName) =>
|
| #toFloat(fnName) =>
|
||||||
GenericDist.operationToFloat(toPointSet, fnName, dist)->E.R.fmap2(r => #Float(r))->fromResult
|
GenericDist.operationToFloat(dist, toPointSet, fnName)->E.R.fmap2(r => #Float(r))->fromResult
|
||||||
| #toString => dist->GenericDist.toString->(r => #String(r))
|
| #toString => dist->GenericDist.toString->(r => #String(r))
|
||||||
| #toDist(#consoleLog) => {
|
| #toDist(#consoleLog) => {
|
||||||
Js.log2("Console log requested: ", dist)
|
Js.log2("Console log requested: ", dist)
|
||||||
|
@ -101,7 +101,7 @@ let rec run = (extra, fnName: operation): outputType => {
|
||||||
}
|
}
|
||||||
| #toDist(#normalize) => dist->GenericDist.normalize->(r => #Dist(r))
|
| #toDist(#normalize) => dist->GenericDist.normalize->(r => #Dist(r))
|
||||||
| #toDist(#truncate(left, right)) =>
|
| #toDist(#truncate(left, right)) =>
|
||||||
dist |> GenericDist.truncate(toPointSet, left, right) |> E.R.fmap(r => #Dist(r)) |> fromResult
|
dist->GenericDist.truncate(toPointSet, left, right)->E.R.fmap2(r => #Dist(r))->fromResult
|
||||||
| #toDist(#toPointSet) =>
|
| #toDist(#toPointSet) =>
|
||||||
dist->GenericDist.toPointSet(xyPointLength)->E.R.fmap2(r => #Dist(#PointSet(r)))->fromResult
|
dist->GenericDist.toPointSet(xyPointLength)->E.R.fmap2(r => #Dist(#PointSet(r)))->fromResult
|
||||||
| #toDist(#toSampleSet(n)) =>
|
| #toDist(#toSampleSet(n)) =>
|
||||||
|
@ -109,26 +109,26 @@ let rec run = (extra, fnName: operation): outputType => {
|
||||||
| #toDistCombination(#Algebraic, _, #Float(_)) => #Error(NotYetImplemented)
|
| #toDistCombination(#Algebraic, _, #Float(_)) => #Error(NotYetImplemented)
|
||||||
| #toDistCombination(#Algebraic, operation, #Dist(dist2)) =>
|
| #toDistCombination(#Algebraic, operation, #Dist(dist2)) =>
|
||||||
dist
|
dist
|
||||||
|> GenericDist.algebraicCombination(toPointSet, toSampleSet, operation, dist2)
|
->GenericDist.algebraicCombination(toPointSet, toSampleSet, operation, dist2)
|
||||||
|> E.R.fmap(r => #Dist(r))
|
->E.R.fmap2(r => #Dist(r))
|
||||||
|> fromResult
|
->fromResult
|
||||||
| #toDistCombination(#Pointwise, operation, #Dist(dist2)) =>
|
| #toDistCombination(#Pointwise, operation, #Dist(dist2)) =>
|
||||||
dist
|
dist
|
||||||
|> GenericDist.pointwiseCombination(toPointSet, operation, dist2)
|
->GenericDist.pointwiseCombination(toPointSet, operation, dist2)
|
||||||
|> E.R.fmap(r => #Dist(r))
|
->E.R.fmap2(r => #Dist(r))
|
||||||
|> fromResult
|
->fromResult
|
||||||
| #toDistCombination(#Pointwise, operation, #Float(f)) =>
|
| #toDistCombination(#Pointwise, operation, #Float(f)) =>
|
||||||
dist
|
dist
|
||||||
|> GenericDist.pointwiseCombinationFloat(toPointSet, operation, f)
|
->GenericDist.pointwiseCombinationFloat(toPointSet, operation, f)
|
||||||
|> E.R.fmap(r => #Dist(r))
|
->E.R.fmap2(r => #Dist(r))
|
||||||
|> fromResult
|
->fromResult
|
||||||
}
|
}
|
||||||
|
|
||||||
switch fnName {
|
switch fnName {
|
||||||
| #fromDist(subFn, dist) => fromDistFn(subFn, dist)
|
| #fromDist(subFn, dist) => fromDistFn(subFn, dist)
|
||||||
| #fromFloat(subFn, float) => reCall(~fnName=#fromDist(subFn, GenericDist.fromFloat(float)), ())
|
| #fromFloat(subFn, float) => reCall(~fnName=#fromDist(subFn, GenericDist.fromFloat(float)), ())
|
||||||
| #mixture(dists) =>
|
| #mixture(dists) =>
|
||||||
GenericDist.mixture(scaleMultiply, pointwiseAdd, dists)->E.R.fmap2(r => #Dist(r))->fromResult
|
dists->GenericDist.mixture(scaleMultiply, pointwiseAdd)->E.R.fmap2(r => #Dist(r))->fromResult
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user