Added main distributions
This commit is contained in:
parent
2c0dc75403
commit
d9cbe37a5a
|
@ -89,3 +89,30 @@ module Process = {
|
||||||
twoDistsOrNumbersToDist(~fn=r => r->fn->E.R2.fmap(Wrappers.symbolic), ~values)
|
twoDistsOrNumbersToDist(~fn=r => r->fn->E.R2.fmap(Wrappers.symbolic), ~values)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module TwoArgDist = {
|
||||||
|
let process = (~fn, r) =>
|
||||||
|
r->E.R.bind(Process.twoDistsOrNumbersToDistUsingSymbolicDist(~fn, ~values=_))
|
||||||
|
|
||||||
|
let mkRegular = (name, fn) => {
|
||||||
|
Function.makeDefinition(~name, ~inputs=[I_DistOrNumber, I_DistOrNumber], ~run=inputs =>
|
||||||
|
inputs->Prepare.twoDistOrNumber->process(~fn)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let mkDef90th = (name, fn) => {
|
||||||
|
Function.makeDefinition(
|
||||||
|
~name,
|
||||||
|
~inputs=[I_Record([("p5", I_DistOrNumber), ("p95", I_DistOrNumber)])],
|
||||||
|
~run=inputs => inputs->Prepare.twoDistOrNumberFromRecord->process(~fn),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let mkDefMeanStdev = (name, fn) => {
|
||||||
|
Function.makeDefinition(
|
||||||
|
~name,
|
||||||
|
~inputs=[I_Record([("mean", I_DistOrNumber), ("stdev", I_DistOrNumber)])],
|
||||||
|
~run=inputs => inputs->Prepare.twoDistOrNumberFromRecord->process(~fn),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,65 +3,57 @@ open FunctionRegistry_Helpers
|
||||||
|
|
||||||
let twoArgs = (fn, (a1, a2)) => fn(a1, a2)
|
let twoArgs = (fn, (a1, a2)) => fn(a1, a2)
|
||||||
|
|
||||||
let process = (~fn, r) =>
|
|
||||||
r->E.R.bind(Process.twoDistsOrNumbersToDistUsingSymbolicDist(~fn, ~values=_))
|
|
||||||
|
|
||||||
module NormalFn = {
|
module NormalFn = {
|
||||||
let fnName = "normal"
|
let fnName = "normal"
|
||||||
let mainInputType = I_DistOrNumber
|
|
||||||
|
|
||||||
let toFn = Function.make(
|
let toFn = Function.make(
|
||||||
~name="Normal",
|
~name="Normal",
|
||||||
~definitions=[
|
~definitions=[
|
||||||
Function.makeDefinition(~name=fnName, ~inputs=[mainInputType, mainInputType], ~run=inputs => {
|
TwoArgDist.mkRegular(fnName, twoArgs(SymbolicDist.Normal.make)),
|
||||||
inputs->Prepare.twoDistOrNumber->process(~fn=twoArgs(SymbolicDist.Normal.make))
|
TwoArgDist.mkDef90th(fnName, r => twoArgs(SymbolicDist.Normal.from90PercentCI, r)->Ok),
|
||||||
}),
|
TwoArgDist.mkDefMeanStdev(fnName, twoArgs(SymbolicDist.Normal.make)),
|
||||||
Function.makeDefinition(
|
|
||||||
~name=fnName,
|
|
||||||
~inputs=[I_Record([("mean", mainInputType), ("stdev", mainInputType)])],
|
|
||||||
~run=inputs =>
|
|
||||||
inputs->Prepare.twoDistOrNumberFromRecord->process(~fn=twoArgs(SymbolicDist.Normal.make)),
|
|
||||||
),
|
|
||||||
Function.makeDefinition(
|
|
||||||
~name=fnName,
|
|
||||||
~inputs=[I_Record([("p5", mainInputType), ("p95", mainInputType)])],
|
|
||||||
~run=inputs =>
|
|
||||||
inputs
|
|
||||||
->Prepare.twoDistOrNumberFromRecord
|
|
||||||
->process(~fn=r => twoArgs(SymbolicDist.Normal.from90PercentCI, r)->Ok),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
module LognormalFn = {
|
module LognormalFn = {
|
||||||
let fnName = "lognormal"
|
let fnName = "lognormal"
|
||||||
let mainInputType = I_DistOrNumber
|
|
||||||
|
|
||||||
let toFn = Function.make(
|
let toFn = Function.make(
|
||||||
~name="Lognormal",
|
~name="Lognormal",
|
||||||
~definitions=[
|
~definitions=[
|
||||||
Function.makeDefinition(~name=fnName, ~inputs=[mainInputType, mainInputType], ~run=inputs =>
|
TwoArgDist.mkRegular(fnName, twoArgs(SymbolicDist.Lognormal.make)),
|
||||||
inputs->Prepare.twoDistOrNumber->process(~fn=twoArgs(SymbolicDist.Lognormal.make))
|
TwoArgDist.mkDef90th(fnName, r => twoArgs(SymbolicDist.Lognormal.from90PercentCI, r)->Ok),
|
||||||
),
|
TwoArgDist.mkDefMeanStdev(fnName, twoArgs(SymbolicDist.Lognormal.fromMeanAndStdev)),
|
||||||
Function.makeDefinition(
|
|
||||||
~name=fnName,
|
|
||||||
~inputs=[I_Record([("p5", mainInputType), ("p95", mainInputType)])],
|
|
||||||
~run=inputs =>
|
|
||||||
inputs
|
|
||||||
->Prepare.twoDistOrNumberFromRecord
|
|
||||||
->process(~fn=r => twoArgs(SymbolicDist.Lognormal.from90PercentCI, r)->Ok),
|
|
||||||
),
|
|
||||||
Function.makeDefinition(
|
|
||||||
~name=fnName,
|
|
||||||
~inputs=[I_Record([("mean", mainInputType), ("stdev", mainInputType)])],
|
|
||||||
~run=inputs =>
|
|
||||||
inputs
|
|
||||||
->Prepare.twoDistOrNumberFromRecord
|
|
||||||
->process(~fn=twoArgs(SymbolicDist.Lognormal.fromMeanAndStdev)),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let more = [
|
||||||
|
Function.make(
|
||||||
|
~name="Uniform",
|
||||||
|
~definitions=[TwoArgDist.mkRegular("uniform", twoArgs(SymbolicDist.Uniform.make))],
|
||||||
|
),
|
||||||
|
Function.make(
|
||||||
|
~name="Beta",
|
||||||
|
~definitions=[TwoArgDist.mkRegular("beta", twoArgs(SymbolicDist.Beta.make))],
|
||||||
|
),
|
||||||
|
Function.make(
|
||||||
|
~name="Cauchy",
|
||||||
|
~definitions=[TwoArgDist.mkRegular("cauchy", twoArgs(SymbolicDist.Cauchy.make))],
|
||||||
|
),
|
||||||
|
Function.make(
|
||||||
|
~name="Gamma",
|
||||||
|
~definitions=[TwoArgDist.mkRegular("gamma", twoArgs(SymbolicDist.Gamma.make))],
|
||||||
|
),
|
||||||
|
Function.make(
|
||||||
|
~name="Logistic",
|
||||||
|
~definitions=[TwoArgDist.mkRegular("logistic", twoArgs(SymbolicDist.Logistic.make))],
|
||||||
|
),
|
||||||
|
Function.make(
|
||||||
|
~name="To",
|
||||||
|
~definitions=[TwoArgDist.mkRegular("cauchy", twoArgs(SymbolicDist.From90thPercentile.make))],
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
let allFunctions = [NormalFn.toFn, LognormalFn.toFn]
|
let allFunctions = [NormalFn.toFn, LognormalFn.toFn]
|
||||||
|
|
|
@ -186,19 +186,6 @@ module SymbolicConstructors = {
|
||||||
| _ => Error("Unreachable state")
|
| _ => Error("Unreachable state")
|
||||||
}
|
}
|
||||||
|
|
||||||
let twoFloat = name =>
|
|
||||||
switch name {
|
|
||||||
| "normal" => Ok(SymbolicDist.Normal.make)
|
|
||||||
| "uniform" => Ok(SymbolicDist.Uniform.make)
|
|
||||||
| "beta" => Ok(SymbolicDist.Beta.make)
|
|
||||||
| "lognormal" => Ok(SymbolicDist.Lognormal.make)
|
|
||||||
| "logistic" => Ok(SymbolicDist.Logistic.make)
|
|
||||||
| "cauchy" => Ok(SymbolicDist.Cauchy.make)
|
|
||||||
| "gamma" => Ok(SymbolicDist.Gamma.make)
|
|
||||||
| "to" => Ok(SymbolicDist.From90thPercentile.make)
|
|
||||||
| _ => Error("Unreachable state")
|
|
||||||
}
|
|
||||||
|
|
||||||
let threeFloat = name =>
|
let threeFloat = name =>
|
||||||
switch name {
|
switch name {
|
||||||
| "triangular" => Ok(SymbolicDist.Triangular.make)
|
| "triangular" => Ok(SymbolicDist.Triangular.make)
|
||||||
|
@ -226,19 +213,6 @@ let dispatchToGenericOutput = (
|
||||||
->SymbolicConstructors.symbolicResultToOutput
|
->SymbolicConstructors.symbolicResultToOutput
|
||||||
| ("delta", [EvNumber(f)]) =>
|
| ("delta", [EvNumber(f)]) =>
|
||||||
SymbolicDist.Float.makeSafe(f)->SymbolicConstructors.symbolicResultToOutput
|
SymbolicDist.Float.makeSafe(f)->SymbolicConstructors.symbolicResultToOutput
|
||||||
| (
|
|
||||||
("uniform"
|
|
||||||
| "beta"
|
|
||||||
| "lognormal"
|
|
||||||
| "cauchy"
|
|
||||||
| "gamma"
|
|
||||||
| "to"
|
|
||||||
| "logistic") as fnName,
|
|
||||||
[EvNumber(f1), EvNumber(f2)],
|
|
||||||
) =>
|
|
||||||
SymbolicConstructors.twoFloat(fnName)
|
|
||||||
->E.R.bind(r => r(f1, f2))
|
|
||||||
->SymbolicConstructors.symbolicResultToOutput
|
|
||||||
| ("triangular" as fnName, [EvNumber(f1), EvNumber(f2), EvNumber(f3)]) =>
|
| ("triangular" as fnName, [EvNumber(f1), EvNumber(f2), EvNumber(f3)]) =>
|
||||||
SymbolicConstructors.threeFloat(fnName)
|
SymbolicConstructors.threeFloat(fnName)
|
||||||
->E.R.bind(r => r(f1, f2, f3))
|
->E.R.bind(r => r(f1, f2, f3))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user