Added lognormal fn definitions
This commit is contained in:
parent
88ae0e25b4
commit
76bbfb2ef1
|
@ -95,13 +95,9 @@ module FnDefinition = {
|
|||
if E.A.length(f.inputs) !== E.A.length(args) {
|
||||
None
|
||||
} else {
|
||||
let foo = E.A.zip(inputTypes, args)
|
||||
->(e => {Js.log2("Here", e); e})
|
||||
E.A.zip(inputTypes, args)
|
||||
->E.A2.fmap(((input, arg)) => matchInput(input, arg))
|
||||
->(e => {Js.log2("Here2", e); e})
|
||||
->E.A.O.openIfAllSome
|
||||
->(e => {Js.log2("Here3", e); e});
|
||||
foo
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,9 +117,7 @@ module FnDefinition = {
|
|||
}
|
||||
|
||||
let run = (f: fnDefinition, args: array<expressionValue>) => {
|
||||
Js.log3("Run", f, args)
|
||||
let argValues = getArgValues(f, args)
|
||||
Js.log2("RunArgValues", argValues)
|
||||
switch argValues {
|
||||
| Some(values) => f.run(values)
|
||||
| None => Error("Impossible")
|
||||
|
@ -233,7 +227,8 @@ module Registry = {
|
|||
|
||||
let matchAndRun = (r: registry, fnName: string, args: array<expressionValue>) => {
|
||||
switch findMatches(r, fnName, args) {
|
||||
| Match.FullMatch(m) => fullMatchToDef(r, m)->E.O2.fmap(r => {
|
||||
| Match.FullMatch(m) =>
|
||||
fullMatchToDef(r, m)->E.O2.fmap(r => {
|
||||
FnDefinition.run(r, args)
|
||||
})
|
||||
| _ => None
|
||||
|
@ -241,8 +236,7 @@ module Registry = {
|
|||
}
|
||||
}
|
||||
|
||||
let twoNumberInputs = (inputs: array<value>) =>{
|
||||
Js.log2("HII",inputs);
|
||||
let twoNumberInputs = (inputs: array<value>) => {
|
||||
switch inputs {
|
||||
| [Number(n1), Number(n2)] => Ok(n1, n2)
|
||||
| _ => Error("Wrong inputs / Logically impossible")
|
||||
|
@ -279,9 +273,36 @@ let normal = Function.make(
|
|||
),
|
||||
),
|
||||
Function.makeDefinition("normal", [I_Record([("p5", I_Numeric), ("p95", I_Numeric)])], inputs =>
|
||||
twoNumberInputsRecord("p5", "p95", inputs)->E.R.bind(((mean, stdev)) =>
|
||||
Ok(p5and95(mean, stdev))
|
||||
)
|
||||
twoNumberInputsRecord("p5", "p95", inputs)->E.R.bind(((v1, v2)) => Ok(p5and95(v1, v2)))
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
let logNormal = Function.make(
|
||||
"Lognormal",
|
||||
[
|
||||
Function.makeDefinition("lognormal", [I_Numeric, I_Numeric], inputs =>
|
||||
twoNumberInputs(inputs)->E.R.bind(((mu, sigma)) =>
|
||||
SymbolicDist.Lognormal.make(mu, sigma)->E.R2.fmap(contain)
|
||||
)
|
||||
),
|
||||
Function.makeDefinition(
|
||||
"lognormal",
|
||||
[I_Record([("p5", I_Numeric), ("p95", I_Numeric)])],
|
||||
inputs =>
|
||||
twoNumberInputsRecord("p5", "p95", inputs)->E.R.bind(((p5, p95)) => Ok(
|
||||
contain(SymbolicDist.Lognormal.from90PercentCI(p5, p95)),
|
||||
)),
|
||||
),
|
||||
Function.makeDefinition(
|
||||
"lognormal",
|
||||
[I_Record([("mean", I_Numeric), ("stdev", I_Numeric)])],
|
||||
inputs =>
|
||||
twoNumberInputsRecord("mean", "stdev", inputs)->E.R.bind(((mean, stdev)) =>
|
||||
SymbolicDist.Lognormal.fromMeanAndStdev(mean, stdev)->E.R2.fmap(contain)
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
let allFunctions = [normal, logNormal]
|
||||
|
|
|
@ -227,8 +227,7 @@ let dispatchToGenericOutput = (
|
|||
| ("delta", [EvNumber(f)]) =>
|
||||
SymbolicDist.Float.makeSafe(f)->SymbolicConstructors.symbolicResultToOutput
|
||||
| (
|
||||
(
|
||||
"uniform"
|
||||
("uniform"
|
||||
| "beta"
|
||||
| "lognormal"
|
||||
| "cauchy"
|
||||
|
@ -386,18 +385,19 @@ let genericOutputToReducerValue = (o: DistributionOperation.outputType): result<
|
|||
| GenDistError(err) => Error(REDistributionError(err))
|
||||
}
|
||||
|
||||
let registered = [FunctionRegistry.normal]
|
||||
let registered = FunctionRegistry.allFunctions
|
||||
|
||||
let tryRegistry = (call:ExpressionValue.functionCall) => {
|
||||
let (fnName, args) = call;
|
||||
let tryRegistry = (call: ExpressionValue.functionCall) => {
|
||||
let (fnName, args) = call
|
||||
let response = FunctionRegistry.Registry.matchAndRun(registered, fnName, args)
|
||||
let foo = response -> E.O2.fmap(r => r->E.R2.errMap(s => Reducer_ErrorValue.RETodo(s)))
|
||||
let foo = response->E.O2.fmap(r => r->E.R2.errMap(s => Reducer_ErrorValue.RETodo(s)))
|
||||
foo
|
||||
}
|
||||
|
||||
let dispatch = (call:ExpressionValue.functionCall, environment) => {
|
||||
let regularDispatch = dispatchToGenericOutput(call, environment)->E.O2.fmap(genericOutputToReducerValue)
|
||||
switch(regularDispatch){
|
||||
let dispatch = (call: ExpressionValue.functionCall, environment) => {
|
||||
let regularDispatch =
|
||||
dispatchToGenericOutput(call, environment)->E.O2.fmap(genericOutputToReducerValue)
|
||||
switch regularDispatch {
|
||||
| Some(x) => Some(x)
|
||||
| None => tryRegistry(call)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user