EvDist -> EvDistribution

This commit is contained in:
Ozzie Gooen 2022-03-31 20:28:48 -04:00
parent 47a574ba8a
commit 28eba9fa74
2 changed files with 18 additions and 18 deletions

View File

@ -12,7 +12,7 @@ type rec expressionValue =
| EvSymbol(string) | EvSymbol(string)
| EvArray(array<expressionValue>) | EvArray(array<expressionValue>)
| EvRecord(Js.Dict.t<expressionValue>) | EvRecord(Js.Dict.t<expressionValue>)
| EvDist(GenericDist_Types.genericDist) | EvDistribution(GenericDist_Types.genericDist)
type functionCall = (string, array<expressionValue>) type functionCall = (string, array<expressionValue>)
@ -36,7 +36,7 @@ let rec toString = aValue =>
->Js.String.concatMany("") ->Js.String.concatMany("")
`{${pairs}}` `{${pairs}}`
} }
| EvDist(dist) => `${GenericDist.toString(dist)}` | EvDistribution(dist) => `${GenericDist.toString(dist)}`
} }
let toStringWithType = aValue => let toStringWithType = aValue =>
@ -47,7 +47,7 @@ let toStringWithType = aValue =>
| EvSymbol(_) => `Symbol::${toString(aValue)}` | EvSymbol(_) => `Symbol::${toString(aValue)}`
| EvArray(_) => `Array::${toString(aValue)}` | EvArray(_) => `Array::${toString(aValue)}`
| EvRecord(_) => `Record::${toString(aValue)}` | EvRecord(_) => `Record::${toString(aValue)}`
| EvDist(_) => `Distribution::${toString(aValue)}` | EvDistribution(_) => `Distribution::${toString(aValue)}`
} }
let argsToString = (args: array<expressionValue>): string => { let argsToString = (args: array<expressionValue>): string => {

View File

@ -30,9 +30,9 @@ let catchAndConvertTwoArgsToDists = (args: array<expressionValue>): option<(
GenericDist_Types.genericDist, GenericDist_Types.genericDist,
)> => { )> => {
switch args { switch args {
| [EvDist(a), EvDist(b)] => Some((a, b)) | [EvDistribution(a), EvDistribution(b)] => Some((a, b))
| [EvNumber(a), EvDist(b)] => Some((GenericDist.fromFloat(a), b)) | [EvNumber(a), EvDistribution(b)] => Some((GenericDist.fromFloat(a), b))
| [EvDist(a), EvNumber(b)] => Some((a, GenericDist.fromFloat(b))) | [EvDistribution(a), EvNumber(b)] => Some((a, GenericDist.fromFloat(b)))
| _ => None | _ => None
} }
} }
@ -64,7 +64,7 @@ let genericOutputToReducerValue = (o: GenericDist_GenericOperation.outputType):
Reducer_ErrorValue.errorValue, Reducer_ErrorValue.errorValue,
> => > =>
switch o { switch o {
| Dist(d) => Ok(ReducerInterface_ExpressionValue.EvDist(d)) | Dist(d) => Ok(ReducerInterface_ExpressionValue.EvDistribution(d))
| Float(d) => Ok(EvNumber(d)) | Float(d) => Ok(EvNumber(d))
| String(d) => Ok(EvString(d)) | String(d) => Ok(EvString(d))
| GenDistError(NotYetImplemented) => Error(RETodo("Function not yet implemented")) | GenDistError(NotYetImplemented) => Error(RETodo("Function not yet implemented"))
@ -79,19 +79,19 @@ let dispatchToGenericOutput = (call: ExpressionValue.functionCall): option<
> => { > => {
let (fnName, args) = call let (fnName, args) = call
switch (fnName, args) { switch (fnName, args) {
| ("sample", [EvDist(dist)]) => toFloatFn(#Sample, dist) | ("sample", [EvDistribution(dist)]) => toFloatFn(#Sample, dist)
| ("mean", [EvDist(dist)]) => toFloatFn(#Mean, dist) | ("mean", [EvDistribution(dist)]) => toFloatFn(#Mean, dist)
| ("normalize", [EvDist(dist)]) => toDistFn(Normalize, dist) | ("normalize", [EvDistribution(dist)]) => toDistFn(Normalize, dist)
| ("toPointSet", [EvDist(dist)]) => toDistFn(ToPointSet, dist) | ("toPointSet", [EvDistribution(dist)]) => toDistFn(ToPointSet, dist)
| ("cdf", [EvDist(dist), EvNumber(float)]) => toFloatFn(#Cdf(float), dist) | ("cdf", [EvDistribution(dist), EvNumber(float)]) => toFloatFn(#Cdf(float), dist)
| ("pdf", [EvDist(dist), EvNumber(float)]) => toFloatFn(#Pdf(float), dist) | ("pdf", [EvDistribution(dist), EvNumber(float)]) => toFloatFn(#Pdf(float), dist)
| ("inv", [EvDist(dist), EvNumber(float)]) => toFloatFn(#Inv(float), dist) | ("inv", [EvDistribution(dist), EvNumber(float)]) => toFloatFn(#Inv(float), dist)
| ("toSampleSet", [EvDist(dist), EvNumber(float)]) => | ("toSampleSet", [EvDistribution(dist), EvNumber(float)]) =>
toDistFn(ToSampleSet(Belt.Int.fromFloat(float)), dist) toDistFn(ToSampleSet(Belt.Int.fromFloat(float)), dist)
| ("truncateLeft", [EvDist(dist), EvNumber(float)]) => toDistFn(Truncate(Some(float), None), dist) | ("truncateLeft", [EvDistribution(dist), EvNumber(float)]) => toDistFn(Truncate(Some(float), None), dist)
| ("truncateRight", [EvDist(dist), EvNumber(float)]) => | ("truncateRight", [EvDistribution(dist), EvNumber(float)]) =>
toDistFn(Truncate(None, Some(float)), dist) toDistFn(Truncate(None, Some(float)), dist)
| ("truncate", [EvDist(dist), EvNumber(float1), EvNumber(float2)]) => | ("truncate", [EvDistribution(dist), EvNumber(float1), EvNumber(float2)]) =>
toDistFn(Truncate(Some(float1), Some(float2)), dist) toDistFn(Truncate(Some(float1), Some(float2)), dist)
| (("add" | "multiply" | "subtract" | "divide" | "exponentiate") as arithmetic, [a, b] as args) => | (("add" | "multiply" | "subtract" | "divide" | "exponentiate") as arithmetic, [a, b] as args) =>
catchAndConvertTwoArgsToDists(args) -> E.O2.fmap(((fst, snd)) => catchAndConvertTwoArgsToDists(args) -> E.O2.fmap(((fst, snd)) =>