Responded to two simple CR comments
This commit is contained in:
parent
2fce3d67e9
commit
ffc622fb6d
|
@ -59,7 +59,7 @@ describe("toPointSet", () => {
|
|||
run(#fromDist(#toDist(#toPointSet), #SampleSet([0.0, 1.0, 2.0, 3.0])))->fmap(
|
||||
#fromDist(#toFloat(#Mean)),
|
||||
)
|
||||
expect(result)->toEqual(#Error(Other("Converting sampleSet to pointSet failed")))
|
||||
expect(result)->toEqual(#GenDistError(Other("Converting sampleSet to pointSet failed")))
|
||||
})
|
||||
|
||||
test("on sample set", () => {
|
||||
|
|
|
@ -207,7 +207,7 @@ let pointwiseCombinationFloat = (
|
|||
operation: GenericDist_Types.Operation.arithmeticOperation,
|
||||
f: float,
|
||||
): result<t, error> => {
|
||||
switch operation {
|
||||
let m = switch operation {
|
||||
| #Add | #Subtract => Error(GenericDist_Types.DistributionVerticalShiftIsInvalid)
|
||||
| (#Multiply | #Divide | #Exponentiate | #Log) as operation =>
|
||||
toPointSet(t)->E.R2.fmap(t => {
|
||||
|
@ -222,10 +222,12 @@ let pointwiseCombinationFloat = (
|
|||
t,
|
||||
)
|
||||
})
|
||||
}->E.R2.fmap(r => #PointSet(r))
|
||||
}
|
||||
m->E.R2.fmap(r => #PointSet(r))
|
||||
}
|
||||
|
||||
//Note: The result should always cumulatively sum to 1. This would be good to test.
|
||||
//Note: If the inputs are not normalized, this will return poor results. The weights probably refer to the post-normalized forms. It would be good to apply a catch to this.
|
||||
let mixture = (
|
||||
values: array<(t, float)>,
|
||||
scaleMultiply: scaleMultiplyFn,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
type operation = GenericDist_Types.Operation.genericFunctionCall
|
||||
type operation = GenericDist_Types.Operation.genericFunctionCallInfo
|
||||
type genericDist = GenericDist_Types.genericDist
|
||||
type error = GenericDist_Types.error
|
||||
|
||||
|
@ -11,9 +11,9 @@ type params = {
|
|||
|
||||
type outputType = [
|
||||
| #Dist(genericDist)
|
||||
| #Error(error)
|
||||
| #Float(float)
|
||||
| #String(string)
|
||||
| #GenDistError(error)
|
||||
]
|
||||
|
||||
module Output = {
|
||||
|
@ -37,7 +37,7 @@ module Output = {
|
|||
|
||||
let toError = (o: outputType) =>
|
||||
switch o {
|
||||
| #Error(d) => Some(d)
|
||||
| #GenDistError(d) => Some(d)
|
||||
| _ => None
|
||||
}
|
||||
}
|
||||
|
@ -45,14 +45,14 @@ module Output = {
|
|||
let fromResult = (r: result<outputType, error>): outputType =>
|
||||
switch r {
|
||||
| Ok(o) => o
|
||||
| Error(e) => #Error(e)
|
||||
| Error(e) => #GenDistError(e)
|
||||
}
|
||||
|
||||
let outputToDistResult = (b: outputType): result<genericDist, error> =>
|
||||
switch b {
|
||||
| #Dist(r) => Ok(r)
|
||||
| #Error(r) => Error(r)
|
||||
| _ => Error(ImpossiblePath)
|
||||
| #GenDistError(r) => Error(r)
|
||||
| _ => Error(Unreachable)
|
||||
}
|
||||
|
||||
let rec run = (extra, fnName: operation): outputType => {
|
||||
|
@ -65,16 +65,16 @@ let rec run = (extra, fnName: operation): outputType => {
|
|||
let toPointSet = r => {
|
||||
switch reCall(~fnName=#fromDist(#toDist(#toPointSet), r), ()) {
|
||||
| #Dist(#PointSet(p)) => Ok(p)
|
||||
| #Error(r) => Error(r)
|
||||
| _ => Error(ImpossiblePath)
|
||||
| #GenDistError(r) => Error(r)
|
||||
| _ => Error(Unreachable)
|
||||
}
|
||||
}
|
||||
|
||||
let toSampleSet = r => {
|
||||
switch reCall(~fnName=#fromDist(#toDist(#toSampleSet(sampleCount)), r), ()) {
|
||||
| #Dist(#SampleSet(p)) => Ok(p)
|
||||
| #Error(r) => Error(r)
|
||||
| _ => Error(ImpossiblePath)
|
||||
| #GenDistError(r) => Error(r)
|
||||
| _ => Error(Unreachable)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ let rec run = (extra, fnName: operation): outputType => {
|
|||
dist->GenericDist.toPointSet(xyPointLength)->E.R2.fmap(r => #Dist(#PointSet(r)))->fromResult
|
||||
| #toDist(#toSampleSet(n)) =>
|
||||
dist->GenericDist.sampleN(n)->E.R2.fmap(r => #Dist(#SampleSet(r)))->fromResult
|
||||
| #toDistCombination(#Algebraic, _, #Float(_)) => #Error(NotYetImplemented)
|
||||
| #toDistCombination(#Algebraic, _, #Float(_)) => #GenDistError(NotYetImplemented)
|
||||
| #toDistCombination(#Algebraic, operation, #Dist(dist2)) =>
|
||||
dist
|
||||
->GenericDist.algebraicCombination(toPointSet, toSampleSet, operation, dist2)
|
||||
|
@ -143,7 +143,7 @@ let fmap = (
|
|||
let newFnCall: result<operation, error> = switch (fn, input) {
|
||||
| (#fromDist(fromDist), #Dist(o)) => Ok(#fromDist(fromDist, o))
|
||||
| (#fromFloat(fromDist), #Float(o)) => Ok(#fromFloat(fromDist, o))
|
||||
| (_, #Error(r)) => Error(r)
|
||||
| (_, #GenDistError(r)) => Error(r)
|
||||
| (#fromDist(_), _) => Error(Other("Expected dist, got something else"))
|
||||
| (#fromFloat(_), _) => Error(Other("Expected float, got something else"))
|
||||
}
|
||||
|
|
|
@ -5,12 +5,12 @@ type params = {
|
|||
|
||||
type outputType = [
|
||||
| #Dist(GenericDist_Types.genericDist)
|
||||
| #Error(GenericDist_Types.error)
|
||||
| #GenDistError(GenericDist_Types.error)
|
||||
| #Float(float)
|
||||
| #String(string)
|
||||
]
|
||||
|
||||
let run: (params, GenericDist_Types.Operation.genericFunctionCall) => outputType
|
||||
let run: (params, GenericDist_Types.Operation.genericFunctionCallInfo) => outputType
|
||||
let runFromDist: (
|
||||
params,
|
||||
GenericDist_Types.Operation.fromDist,
|
||||
|
|
|
@ -6,7 +6,7 @@ type genericDist = [
|
|||
|
||||
type error =
|
||||
| NotYetImplemented
|
||||
| ImpossiblePath
|
||||
| Unreachable
|
||||
| DistributionVerticalShiftIsInvalid
|
||||
| Other(string)
|
||||
|
||||
|
@ -67,12 +67,13 @@ module Operation = {
|
|||
| #fromFloat(fromDist)
|
||||
]
|
||||
|
||||
type genericFunctionCall = [
|
||||
type genericFunctionCallInfo = [
|
||||
| #fromDist(fromDist, genericDist)
|
||||
| #fromFloat(fromDist, float)
|
||||
| #mixture(array<(genericDist, float)>)
|
||||
]
|
||||
|
||||
//TODO: Should support all genericFunctionCallInfo types
|
||||
let toString = (distFunction: fromDist): string =>
|
||||
switch distFunction {
|
||||
| #toFloat(#Cdf(r)) => `cdf(${E.Float.toFixed(r)})`
|
||||
|
|
Loading…
Reference in New Issue
Block a user