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) {
|
if E.A.length(f.inputs) !== E.A.length(args) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let foo = E.A.zip(inputTypes, args)
|
E.A.zip(inputTypes, args)
|
||||||
->(e => {Js.log2("Here", e); e})
|
|
||||||
->E.A2.fmap(((input, arg)) => matchInput(input, arg))
|
->E.A2.fmap(((input, arg)) => matchInput(input, arg))
|
||||||
->(e => {Js.log2("Here2", e); e})
|
|
||||||
->E.A.O.openIfAllSome
|
->E.A.O.openIfAllSome
|
||||||
->(e => {Js.log2("Here3", e); e});
|
|
||||||
foo
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,9 +117,7 @@ module FnDefinition = {
|
||||||
}
|
}
|
||||||
|
|
||||||
let run = (f: fnDefinition, args: array<expressionValue>) => {
|
let run = (f: fnDefinition, args: array<expressionValue>) => {
|
||||||
Js.log3("Run", f, args)
|
|
||||||
let argValues = getArgValues(f, args)
|
let argValues = getArgValues(f, args)
|
||||||
Js.log2("RunArgValues", argValues)
|
|
||||||
switch argValues {
|
switch argValues {
|
||||||
| Some(values) => f.run(values)
|
| Some(values) => f.run(values)
|
||||||
| None => Error("Impossible")
|
| None => Error("Impossible")
|
||||||
|
@ -233,16 +227,16 @@ module Registry = {
|
||||||
|
|
||||||
let matchAndRun = (r: registry, fnName: string, args: array<expressionValue>) => {
|
let matchAndRun = (r: registry, fnName: string, args: array<expressionValue>) => {
|
||||||
switch findMatches(r, fnName, args) {
|
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)
|
FnDefinition.run(r, args)
|
||||||
})
|
})
|
||||||
| _ => None
|
| _ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let twoNumberInputs = (inputs: array<value>) =>{
|
let twoNumberInputs = (inputs: array<value>) => {
|
||||||
Js.log2("HII",inputs);
|
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [Number(n1), Number(n2)] => Ok(n1, n2)
|
| [Number(n1), Number(n2)] => Ok(n1, n2)
|
||||||
| _ => Error("Wrong inputs / Logically impossible")
|
| _ => 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 =>
|
Function.makeDefinition("normal", [I_Record([("p5", I_Numeric), ("p95", I_Numeric)])], inputs =>
|
||||||
twoNumberInputsRecord("p5", "p95", inputs)->E.R.bind(((mean, stdev)) =>
|
twoNumberInputsRecord("p5", "p95", inputs)->E.R.bind(((v1, v2)) => Ok(p5and95(v1, v2)))
|
||||||
Ok(p5and95(mean, stdev))
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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)]) =>
|
| ("delta", [EvNumber(f)]) =>
|
||||||
SymbolicDist.Float.makeSafe(f)->SymbolicConstructors.symbolicResultToOutput
|
SymbolicDist.Float.makeSafe(f)->SymbolicConstructors.symbolicResultToOutput
|
||||||
| (
|
| (
|
||||||
(
|
("uniform"
|
||||||
"uniform"
|
|
||||||
| "beta"
|
| "beta"
|
||||||
| "lognormal"
|
| "lognormal"
|
||||||
| "cauchy"
|
| "cauchy"
|
||||||
|
@ -386,19 +385,20 @@ let genericOutputToReducerValue = (o: DistributionOperation.outputType): result<
|
||||||
| GenDistError(err) => Error(REDistributionError(err))
|
| GenDistError(err) => Error(REDistributionError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
let registered = [FunctionRegistry.normal]
|
let registered = FunctionRegistry.allFunctions
|
||||||
|
|
||||||
let tryRegistry = (call:ExpressionValue.functionCall) => {
|
let tryRegistry = (call: ExpressionValue.functionCall) => {
|
||||||
let (fnName, args) = call;
|
let (fnName, args) = call
|
||||||
let response = FunctionRegistry.Registry.matchAndRun(registered, fnName, args)
|
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
|
foo
|
||||||
}
|
}
|
||||||
|
|
||||||
let dispatch = (call:ExpressionValue.functionCall, environment) => {
|
let dispatch = (call: ExpressionValue.functionCall, environment) => {
|
||||||
let regularDispatch = dispatchToGenericOutput(call, environment)->E.O2.fmap(genericOutputToReducerValue)
|
let regularDispatch =
|
||||||
switch(regularDispatch){
|
dispatchToGenericOutput(call, environment)->E.O2.fmap(genericOutputToReducerValue)
|
||||||
| Some(x) => Some(x)
|
switch regularDispatch {
|
||||||
| None => tryRegistry(call)
|
| Some(x) => Some(x)
|
||||||
|
| None => tryRegistry(call)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user