2022-06-24 10:15:38 +00:00
|
|
|
module IEV = ReducerInterface_InternalExpressionValue
|
|
|
|
type internalExpressionValue = IEV.t
|
2022-04-01 00:24:59 +00:00
|
|
|
|
2022-04-01 19:41:11 +00:00
|
|
|
module Helpers = {
|
|
|
|
let arithmeticMap = r =>
|
|
|
|
switch r {
|
|
|
|
| "add" => #Add
|
2022-04-02 20:25:41 +00:00
|
|
|
| "dotAdd" => #Add
|
2022-04-01 19:41:11 +00:00
|
|
|
| "subtract" => #Subtract
|
2022-04-02 20:25:41 +00:00
|
|
|
| "dotSubtract" => #Subtract
|
2022-04-01 19:41:11 +00:00
|
|
|
| "divide" => #Divide
|
2022-04-02 20:25:41 +00:00
|
|
|
| "log" => #Logarithm
|
|
|
|
| "dotDivide" => #Divide
|
2022-04-09 16:37:26 +00:00
|
|
|
| "pow" => #Power
|
|
|
|
| "dotPow" => #Power
|
2022-04-01 19:41:11 +00:00
|
|
|
| "multiply" => #Multiply
|
2022-04-02 20:25:41 +00:00
|
|
|
| "dotMultiply" => #Multiply
|
2022-04-01 19:41:11 +00:00
|
|
|
| _ => #Multiply
|
|
|
|
}
|
2022-04-01 00:24:59 +00:00
|
|
|
|
2022-06-24 10:15:38 +00:00
|
|
|
let catchAndConvertTwoArgsToDists = (args: array<internalExpressionValue>): option<(
|
2022-04-22 20:27:17 +00:00
|
|
|
DistributionTypes.genericDist,
|
|
|
|
DistributionTypes.genericDist,
|
2022-04-29 18:42:34 +00:00
|
|
|
)> =>
|
2022-04-01 19:41:11 +00:00
|
|
|
switch args {
|
2022-06-23 18:38:07 +00:00
|
|
|
| [IEvDistribution(a), IEvDistribution(b)] => Some((a, b))
|
|
|
|
| [IEvNumber(a), IEvDistribution(b)] => Some((GenericDist.fromFloat(a), b))
|
|
|
|
| [IEvDistribution(a), IEvNumber(b)] => Some((a, GenericDist.fromFloat(b)))
|
2022-04-01 19:41:11 +00:00
|
|
|
| _ => None
|
|
|
|
}
|
2022-04-01 00:24:59 +00:00
|
|
|
|
2022-04-01 19:41:11 +00:00
|
|
|
let toFloatFn = (
|
2022-04-23 18:09:06 +00:00
|
|
|
fnCall: DistributionTypes.DistributionOperation.toFloat,
|
2022-04-22 20:27:17 +00:00
|
|
|
dist: DistributionTypes.genericDist,
|
2022-07-13 16:37:39 +00:00
|
|
|
~env: GenericDist.env,
|
2022-04-01 19:41:11 +00:00
|
|
|
) => {
|
2022-07-04 15:24:30 +00:00
|
|
|
FromDist(#ToFloat(fnCall), dist)->DistributionOperation.run(~env)->Some
|
2022-04-01 00:24:59 +00:00
|
|
|
}
|
|
|
|
|
2022-04-08 13:08:49 +00:00
|
|
|
let toStringFn = (
|
2022-04-22 20:27:17 +00:00
|
|
|
fnCall: DistributionTypes.DistributionOperation.toString,
|
|
|
|
dist: DistributionTypes.genericDist,
|
2022-07-13 16:37:39 +00:00
|
|
|
~env: GenericDist.env,
|
2022-04-08 13:08:49 +00:00
|
|
|
) => {
|
2022-07-04 15:24:30 +00:00
|
|
|
FromDist(#ToString(fnCall), dist)->DistributionOperation.run(~env)->Some
|
2022-04-08 13:08:49 +00:00
|
|
|
}
|
|
|
|
|
2022-04-15 17:58:00 +00:00
|
|
|
let toBoolFn = (
|
2022-04-22 20:27:17 +00:00
|
|
|
fnCall: DistributionTypes.DistributionOperation.toBool,
|
|
|
|
dist: DistributionTypes.genericDist,
|
2022-07-13 16:37:39 +00:00
|
|
|
~env: GenericDist.env,
|
2022-04-15 17:58:00 +00:00
|
|
|
) => {
|
2022-07-04 15:24:30 +00:00
|
|
|
FromDist(#ToBool(fnCall), dist)->DistributionOperation.run(~env)->Some
|
2022-04-15 17:58:00 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 20:16:52 +00:00
|
|
|
let toDistFn = (
|
|
|
|
fnCall: DistributionTypes.DistributionOperation.toDist,
|
|
|
|
dist,
|
2022-07-13 16:37:39 +00:00
|
|
|
~env: GenericDist.env,
|
2022-05-13 20:16:52 +00:00
|
|
|
) => {
|
2022-07-04 15:24:30 +00:00
|
|
|
FromDist(#ToDist(fnCall), dist)->DistributionOperation.run(~env)->Some
|
2022-04-01 19:41:11 +00:00
|
|
|
}
|
2022-04-01 00:24:59 +00:00
|
|
|
|
2022-07-13 16:37:39 +00:00
|
|
|
let twoDiststoDistFn = (direction, arithmetic, dist1, dist2, ~env: GenericDist.env) => {
|
2022-04-01 19:41:11 +00:00
|
|
|
FromDist(
|
2022-07-04 15:24:30 +00:00
|
|
|
#ToDistCombination(direction, arithmeticMap(arithmetic), #Dist(dist2)),
|
2022-04-01 19:41:11 +00:00
|
|
|
dist1,
|
2022-05-13 20:16:52 +00:00
|
|
|
)->DistributionOperation.run(~env)
|
2022-04-01 00:24:59 +00:00
|
|
|
}
|
2022-04-29 00:24:13 +00:00
|
|
|
|
2022-06-24 10:15:38 +00:00
|
|
|
let parseNumber = (args: internalExpressionValue): Belt.Result.t<float, string> =>
|
2022-04-12 07:39:38 +00:00
|
|
|
switch args {
|
2022-06-23 18:38:07 +00:00
|
|
|
| IEvNumber(x) => Ok(x)
|
2022-04-12 07:39:38 +00:00
|
|
|
| _ => Error("Not a number")
|
|
|
|
}
|
|
|
|
|
2022-06-24 10:15:38 +00:00
|
|
|
let parseNumberArray = (ags: array<internalExpressionValue>): Belt.Result.t<
|
|
|
|
array<float>,
|
|
|
|
string,
|
|
|
|
> => E.A.fmap(parseNumber, ags) |> E.A.R.firstErrorOrOpen
|
2022-04-12 07:39:38 +00:00
|
|
|
|
2022-06-24 10:15:38 +00:00
|
|
|
let parseDist = (args: internalExpressionValue): Belt.Result.t<
|
|
|
|
DistributionTypes.genericDist,
|
|
|
|
string,
|
|
|
|
> =>
|
2022-04-12 07:39:38 +00:00
|
|
|
switch args {
|
2022-06-23 18:38:07 +00:00
|
|
|
| IEvDistribution(x) => Ok(x)
|
|
|
|
| IEvNumber(x) => Ok(GenericDist.fromFloat(x))
|
2022-04-12 07:39:38 +00:00
|
|
|
| _ => Error("Not a distribution")
|
|
|
|
}
|
|
|
|
|
2022-06-24 10:15:38 +00:00
|
|
|
let parseDistributionArray = (ags: array<internalExpressionValue>): Belt.Result.t<
|
2022-04-22 20:27:17 +00:00
|
|
|
array<DistributionTypes.genericDist>,
|
2022-04-13 02:03:04 +00:00
|
|
|
string,
|
|
|
|
> => E.A.fmap(parseDist, ags) |> E.A.R.firstErrorOrOpen
|
2022-04-12 07:39:38 +00:00
|
|
|
|
2022-04-13 02:03:04 +00:00
|
|
|
let mixtureWithGivenWeights = (
|
2022-04-22 20:27:17 +00:00
|
|
|
distributions: array<DistributionTypes.genericDist>,
|
2022-04-13 02:03:04 +00:00
|
|
|
weights: array<float>,
|
2022-07-13 16:37:39 +00:00
|
|
|
~env: GenericDist.env,
|
2022-04-13 02:03:04 +00:00
|
|
|
): DistributionOperation.outputType =>
|
|
|
|
E.A.length(distributions) == E.A.length(weights)
|
2022-05-13 20:16:52 +00:00
|
|
|
? Mixture(Belt.Array.zip(distributions, weights))->DistributionOperation.run(~env)
|
2022-04-13 02:03:04 +00:00
|
|
|
: GenDistError(
|
|
|
|
ArgumentError("Error, mixture call has different number of distributions and weights"),
|
|
|
|
)
|
|
|
|
|
|
|
|
let mixtureWithDefaultWeights = (
|
2022-04-22 20:27:17 +00:00
|
|
|
distributions: array<DistributionTypes.genericDist>,
|
2022-07-13 16:37:39 +00:00
|
|
|
~env: GenericDist.env,
|
2022-04-13 02:03:04 +00:00
|
|
|
): DistributionOperation.outputType => {
|
|
|
|
let length = E.A.length(distributions)
|
|
|
|
let weights = Belt.Array.make(length, 1.0 /. Belt.Int.toFloat(length))
|
2022-05-13 20:16:52 +00:00
|
|
|
mixtureWithGivenWeights(distributions, weights, ~env)
|
2022-04-13 02:03:04 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 20:16:52 +00:00
|
|
|
let mixture = (
|
2022-06-24 10:15:38 +00:00
|
|
|
args: array<internalExpressionValue>,
|
2022-07-13 16:37:39 +00:00
|
|
|
~env: GenericDist.env,
|
2022-05-13 20:16:52 +00:00
|
|
|
): DistributionOperation.outputType => {
|
2022-05-10 20:34:03 +00:00
|
|
|
let error = (err: string): DistributionOperation.outputType =>
|
|
|
|
err->DistributionTypes.ArgumentError->GenDistError
|
2022-05-09 19:19:56 +00:00
|
|
|
switch args {
|
2022-06-23 18:38:07 +00:00
|
|
|
| [IEvArray(distributions)] =>
|
2022-05-09 19:19:56 +00:00
|
|
|
switch parseDistributionArray(distributions) {
|
2022-05-13 20:16:52 +00:00
|
|
|
| Ok(distrs) => mixtureWithDefaultWeights(distrs, ~env)
|
2022-05-09 19:24:46 +00:00
|
|
|
| Error(err) => error(err)
|
2022-05-09 19:19:56 +00:00
|
|
|
}
|
2022-06-23 18:38:07 +00:00
|
|
|
| [IEvArray(distributions), IEvArray(weights)] =>
|
2022-05-09 19:19:56 +00:00
|
|
|
switch (parseDistributionArray(distributions), parseNumberArray(weights)) {
|
2022-05-13 20:16:52 +00:00
|
|
|
| (Ok(distrs), Ok(wghts)) => mixtureWithGivenWeights(distrs, wghts, ~env)
|
2022-05-09 19:24:46 +00:00
|
|
|
| (Error(err), Ok(_)) => error(err)
|
|
|
|
| (Ok(_), Error(err)) => error(err)
|
|
|
|
| (Error(err1), Error(err2)) => error(`${err1}|${err2}`)
|
2022-05-09 19:19:56 +00:00
|
|
|
}
|
|
|
|
| _ =>
|
|
|
|
switch E.A.last(args) {
|
2022-06-23 18:38:07 +00:00
|
|
|
| Some(IEvArray(b)) => {
|
2022-05-09 19:19:56 +00:00
|
|
|
let weights = parseNumberArray(b)
|
|
|
|
let distributions = parseDistributionArray(
|
|
|
|
Belt.Array.slice(args, ~offset=0, ~len=E.A.length(args) - 1),
|
|
|
|
)
|
|
|
|
switch E.R.merge(distributions, weights) {
|
2022-05-13 20:16:52 +00:00
|
|
|
| Ok(d, w) => mixtureWithGivenWeights(d, w, ~env)
|
2022-05-09 19:24:46 +00:00
|
|
|
| Error(err) => error(err)
|
2022-05-09 19:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-23 18:38:07 +00:00
|
|
|
| Some(IEvNumber(_))
|
|
|
|
| Some(IEvDistribution(_)) =>
|
2022-05-09 19:19:56 +00:00
|
|
|
switch parseDistributionArray(args) {
|
2022-05-13 20:16:52 +00:00
|
|
|
| Ok(distributions) => mixtureWithDefaultWeights(distributions, ~env)
|
2022-05-09 19:24:46 +00:00
|
|
|
| Error(err) => error(err)
|
2022-04-12 07:39:38 +00:00
|
|
|
}
|
2022-05-09 19:24:46 +00:00
|
|
|
| _ => error("Last argument of mx must be array or distribution")
|
2022-04-13 02:03:04 +00:00
|
|
|
}
|
2022-04-12 07:39:38 +00:00
|
|
|
}
|
2022-05-09 19:24:46 +00:00
|
|
|
}
|
2022-04-01 19:41:11 +00:00
|
|
|
}
|
2022-04-01 00:24:59 +00:00
|
|
|
|
2022-04-01 19:41:11 +00:00
|
|
|
module SymbolicConstructors = {
|
2022-04-01 17:21:24 +00:00
|
|
|
let threeFloat = name =>
|
|
|
|
switch name {
|
|
|
|
| "triangular" => Ok(SymbolicDist.Triangular.make)
|
2022-04-02 15:01:53 +00:00
|
|
|
| _ => Error("Unreachable state")
|
2022-04-01 17:21:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let symbolicResultToOutput = (
|
|
|
|
symbolicResult: result<SymbolicDistTypes.symbolicDist, string>,
|
2022-04-04 15:59:14 +00:00
|
|
|
): option<DistributionOperation.outputType> =>
|
2022-04-01 17:21:24 +00:00
|
|
|
switch symbolicResult {
|
|
|
|
| Ok(r) => Some(Dist(Symbolic(r)))
|
2022-04-23 18:13:38 +00:00
|
|
|
| Error(r) => Some(GenDistError(OtherError(r)))
|
2022-04-01 17:21:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-13 16:37:39 +00:00
|
|
|
let dispatchToGenericOutput = (call: IEV.functionCall, env: GenericDist.env): option<
|
2022-06-24 10:15:38 +00:00
|
|
|
DistributionOperation.outputType,
|
|
|
|
> => {
|
2022-04-01 00:24:59 +00:00
|
|
|
let (fnName, args) = call
|
|
|
|
switch (fnName, args) {
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("triangular" as fnName, [IEvNumber(f1), IEvNumber(f2), IEvNumber(f3)]) =>
|
2022-04-01 19:41:11 +00:00
|
|
|
SymbolicConstructors.threeFloat(fnName)
|
2022-04-01 17:21:24 +00:00
|
|
|
->E.R.bind(r => r(f1, f2, f3))
|
2022-04-01 19:41:11 +00:00
|
|
|
->SymbolicConstructors.symbolicResultToOutput
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("sample", [IEvDistribution(dist)]) => Helpers.toFloatFn(#Sample, dist, ~env)
|
|
|
|
| ("sampleN", [IEvDistribution(dist), IEvNumber(n)]) =>
|
2022-05-15 14:58:29 +00:00
|
|
|
Some(FloatArray(GenericDist.sampleN(dist, Belt.Int.fromFloat(n))))
|
2022-06-23 18:38:07 +00:00
|
|
|
| (("mean" | "stdev" | "variance" | "min" | "max" | "mode") as op, [IEvDistribution(dist)]) => {
|
2022-06-06 19:08:00 +00:00
|
|
|
let fn = switch op {
|
|
|
|
| "mean" => #Mean
|
|
|
|
| "stdev" => #Stdev
|
|
|
|
| "variance" => #Variance
|
|
|
|
| "min" => #Min
|
|
|
|
| "max" => #Max
|
|
|
|
| "mode" => #Mode
|
|
|
|
| _ => #Mean
|
|
|
|
}
|
|
|
|
Helpers.toFloatFn(fn, dist, ~env)
|
|
|
|
}
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("integralSum", [IEvDistribution(dist)]) => Helpers.toFloatFn(#IntegralSum, dist, ~env)
|
|
|
|
| ("toString", [IEvDistribution(dist)]) => Helpers.toStringFn(ToString, dist, ~env)
|
|
|
|
| ("sparkline", [IEvDistribution(dist)]) =>
|
2022-05-16 16:03:37 +00:00
|
|
|
Helpers.toStringFn(ToSparkline(MagicNumbers.Environment.sparklineLength), dist, ~env)
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("sparkline", [IEvDistribution(dist), IEvNumber(n)]) =>
|
2022-05-13 20:16:52 +00:00
|
|
|
Helpers.toStringFn(ToSparkline(Belt.Float.toInt(n)), dist, ~env)
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("exp", [IEvDistribution(a)]) =>
|
2022-04-02 20:25:41 +00:00
|
|
|
// https://mathjs.org/docs/reference/functions/exp.html
|
2022-04-27 17:59:33 +00:00
|
|
|
Helpers.twoDiststoDistFn(
|
|
|
|
Algebraic(AsDefault),
|
|
|
|
"pow",
|
|
|
|
GenericDist.fromFloat(MagicNumbers.Math.e),
|
|
|
|
a,
|
2022-05-13 20:16:52 +00:00
|
|
|
~env,
|
2022-04-27 17:59:33 +00:00
|
|
|
)->Some
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("normalize", [IEvDistribution(dist)]) => Helpers.toDistFn(Normalize, dist, ~env)
|
|
|
|
| ("isNormalized", [IEvDistribution(dist)]) => Helpers.toBoolFn(IsNormalized, dist, ~env)
|
|
|
|
| ("toPointSet", [IEvDistribution(dist)]) => Helpers.toDistFn(ToPointSet, dist, ~env)
|
|
|
|
| ("scaleLog", [IEvDistribution(dist)]) =>
|
2022-05-13 20:16:52 +00:00
|
|
|
Helpers.toDistFn(Scale(#Logarithm, MagicNumbers.Math.e), dist, ~env)
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("scaleLog10", [IEvDistribution(dist)]) => Helpers.toDistFn(Scale(#Logarithm, 10.0), dist, ~env)
|
|
|
|
| ("scaleLog", [IEvDistribution(dist), IEvNumber(float)]) =>
|
2022-05-13 20:16:52 +00:00
|
|
|
Helpers.toDistFn(Scale(#Logarithm, float), dist, ~env)
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("scaleLogWithThreshold", [IEvDistribution(dist), IEvNumber(base), IEvNumber(eps)]) =>
|
2022-05-13 20:16:52 +00:00
|
|
|
Helpers.toDistFn(Scale(#LogarithmWithThreshold(eps), base), dist, ~env)
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("scaleMultiply", [IEvDistribution(dist), IEvNumber(float)]) =>
|
2022-06-17 13:44:06 +00:00
|
|
|
Helpers.toDistFn(Scale(#Multiply, float), dist, ~env)
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("scalePow", [IEvDistribution(dist), IEvNumber(float)]) =>
|
2022-05-13 20:16:52 +00:00
|
|
|
Helpers.toDistFn(Scale(#Power, float), dist, ~env)
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("scaleExp", [IEvDistribution(dist)]) =>
|
2022-05-13 20:16:52 +00:00
|
|
|
Helpers.toDistFn(Scale(#Power, MagicNumbers.Math.e), dist, ~env)
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("cdf", [IEvDistribution(dist), IEvNumber(float)]) => Helpers.toFloatFn(#Cdf(float), dist, ~env)
|
|
|
|
| ("pdf", [IEvDistribution(dist), IEvNumber(float)]) => Helpers.toFloatFn(#Pdf(float), dist, ~env)
|
|
|
|
| ("inv", [IEvDistribution(dist), IEvNumber(float)]) => Helpers.toFloatFn(#Inv(float), dist, ~env)
|
|
|
|
| ("quantile", [IEvDistribution(dist), IEvNumber(float)]) =>
|
2022-06-13 19:10:24 +00:00
|
|
|
Helpers.toFloatFn(#Inv(float), dist, ~env)
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("inspect", [IEvDistribution(dist)]) => Helpers.toDistFn(Inspect, dist, ~env)
|
|
|
|
| ("truncateLeft", [IEvDistribution(dist), IEvNumber(float)]) =>
|
2022-05-13 20:16:52 +00:00
|
|
|
Helpers.toDistFn(Truncate(Some(float), None), dist, ~env)
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("truncateRight", [IEvDistribution(dist), IEvNumber(float)]) =>
|
2022-05-13 20:16:52 +00:00
|
|
|
Helpers.toDistFn(Truncate(None, Some(float)), dist, ~env)
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("truncate", [IEvDistribution(dist), IEvNumber(float1), IEvNumber(float2)]) =>
|
2022-05-13 20:16:52 +00:00
|
|
|
Helpers.toDistFn(Truncate(Some(float1), Some(float2)), dist, ~env)
|
|
|
|
| ("mx" | "mixture", args) => Helpers.mixture(args, ~env)->Some
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("log", [IEvDistribution(a)]) =>
|
2022-04-27 17:59:33 +00:00
|
|
|
Helpers.twoDiststoDistFn(
|
|
|
|
Algebraic(AsDefault),
|
|
|
|
"log",
|
|
|
|
a,
|
|
|
|
GenericDist.fromFloat(MagicNumbers.Math.e),
|
2022-05-13 20:16:52 +00:00
|
|
|
~env,
|
2022-04-27 17:59:33 +00:00
|
|
|
)->Some
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("log10", [IEvDistribution(a)]) =>
|
2022-05-13 20:16:52 +00:00
|
|
|
Helpers.twoDiststoDistFn(
|
|
|
|
Algebraic(AsDefault),
|
|
|
|
"log",
|
|
|
|
a,
|
|
|
|
GenericDist.fromFloat(10.0),
|
|
|
|
~env,
|
|
|
|
)->Some
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("unaryMinus", [IEvDistribution(a)]) =>
|
2022-05-13 20:16:52 +00:00
|
|
|
Helpers.twoDiststoDistFn(
|
|
|
|
Algebraic(AsDefault),
|
|
|
|
"multiply",
|
|
|
|
a,
|
|
|
|
GenericDist.fromFloat(-1.0),
|
|
|
|
~env,
|
|
|
|
)->Some
|
2022-04-21 22:09:06 +00:00
|
|
|
| (("add" | "multiply" | "subtract" | "divide" | "pow" | "log") as arithmetic, [_, _] as args) =>
|
2022-04-01 19:41:11 +00:00
|
|
|
Helpers.catchAndConvertTwoArgsToDists(args)->E.O2.fmap(((fst, snd)) =>
|
2022-05-13 20:16:52 +00:00
|
|
|
Helpers.twoDiststoDistFn(Algebraic(AsDefault), arithmetic, fst, snd, ~env)
|
2022-04-01 00:24:59 +00:00
|
|
|
)
|
|
|
|
| (
|
2022-04-02 20:25:41 +00:00
|
|
|
("dotAdd"
|
|
|
|
| "dotMultiply"
|
|
|
|
| "dotSubtract"
|
|
|
|
| "dotDivide"
|
2022-04-23 18:09:06 +00:00
|
|
|
| "dotPow") as arithmetic,
|
2022-04-21 22:09:06 +00:00
|
|
|
[_, _] as args,
|
2022-04-01 00:24:59 +00:00
|
|
|
) =>
|
2022-04-01 19:41:11 +00:00
|
|
|
Helpers.catchAndConvertTwoArgsToDists(args)->E.O2.fmap(((fst, snd)) =>
|
2022-05-13 20:16:52 +00:00
|
|
|
Helpers.twoDiststoDistFn(Pointwise, arithmetic, fst, snd, ~env)
|
2022-04-01 00:24:59 +00:00
|
|
|
)
|
2022-06-23 18:38:07 +00:00
|
|
|
| ("dotExp", [IEvDistribution(a)]) =>
|
2022-04-27 17:59:33 +00:00
|
|
|
Helpers.twoDiststoDistFn(
|
|
|
|
Pointwise,
|
|
|
|
"dotPow",
|
|
|
|
GenericDist.fromFloat(MagicNumbers.Math.e),
|
|
|
|
a,
|
2022-05-13 20:16:52 +00:00
|
|
|
~env,
|
2022-04-27 17:59:33 +00:00
|
|
|
)->Some
|
2022-04-01 00:24:59 +00:00
|
|
|
| _ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-04 15:59:14 +00:00
|
|
|
let genericOutputToReducerValue = (o: DistributionOperation.outputType): result<
|
2022-06-24 10:15:38 +00:00
|
|
|
internalExpressionValue,
|
2022-04-01 19:41:11 +00:00
|
|
|
Reducer_ErrorValue.errorValue,
|
|
|
|
> =>
|
|
|
|
switch o {
|
2022-06-23 18:38:07 +00:00
|
|
|
| Dist(d) => Ok(ReducerInterface_InternalExpressionValue.IEvDistribution(d))
|
|
|
|
| Float(d) => Ok(IEvNumber(d))
|
|
|
|
| String(d) => Ok(IEvString(d))
|
|
|
|
| Bool(d) => Ok(IEvBool(d))
|
2022-06-16 12:08:59 +00:00
|
|
|
| FloatArray(d) =>
|
2022-06-23 18:38:07 +00:00
|
|
|
Ok(IEvArray(d |> E.A.fmap(r => ReducerInterface_InternalExpressionValue.IEvNumber(r))))
|
2022-04-22 20:27:17 +00:00
|
|
|
| GenDistError(err) => Error(REDistributionError(err))
|
2022-04-01 19:41:11 +00:00
|
|
|
}
|
|
|
|
|
2022-06-24 10:15:38 +00:00
|
|
|
let dispatch = (call: IEV.functionCall, environment) =>
|
2022-06-06 21:42:49 +00:00
|
|
|
dispatchToGenericOutput(call, environment)->E.O2.fmap(genericOutputToReducerValue)
|