Fixing lint and tests
This commit is contained in:
parent
faf4718f4d
commit
003b320acb
|
@ -133,8 +133,6 @@ module Matcher = {
|
||||||
}
|
}
|
||||||
|
|
||||||
module FnDefinition = {
|
module FnDefinition = {
|
||||||
type definitionMatch = MatchSimple.t
|
|
||||||
|
|
||||||
let matchAssumingSameName = (f: fnDefinition, args: array<expressionValue>) => {
|
let matchAssumingSameName = (f: fnDefinition, args: array<expressionValue>) => {
|
||||||
switch FRType.matchWithExpressionValueArray(f.inputs, args) {
|
switch FRType.matchWithExpressionValueArray(f.inputs, args) {
|
||||||
| Some(_) => MatchSimple.FullMatch
|
| Some(_) => MatchSimple.FullMatch
|
||||||
|
@ -185,7 +183,6 @@ module Matcher = {
|
||||||
fnName: string,
|
fnName: string,
|
||||||
inputIndex: int,
|
inputIndex: int,
|
||||||
}
|
}
|
||||||
type t = Match.t<array<match>, match>
|
|
||||||
let makeMatch = (fnName: string, inputIndex: int) => {fnName: fnName, inputIndex: inputIndex}
|
let makeMatch = (fnName: string, inputIndex: int) => {fnName: fnName, inputIndex: inputIndex}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ type function = {
|
||||||
|
|
||||||
type registry = array<function>
|
type registry = array<function>
|
||||||
|
|
||||||
|
|
||||||
// Note: The function "name" is just used for documentation purposes
|
// Note: The function "name" is just used for documentation purposes
|
||||||
module Function: {
|
module Function: {
|
||||||
type t = function
|
type t = function
|
||||||
|
|
|
@ -5,7 +5,7 @@ let impossibleError = "Wrong inputs / Logically impossible"
|
||||||
module Wrappers = {
|
module Wrappers = {
|
||||||
let symbolic = r => DistributionTypes.Symbolic(r)
|
let symbolic = r => DistributionTypes.Symbolic(r)
|
||||||
let evDistribution = r => ReducerInterface_ExpressionValue.EvDistribution(r)
|
let evDistribution = r => ReducerInterface_ExpressionValue.EvDistribution(r)
|
||||||
let symbolicEvDistribution = r => r->Symbolic->evDistribution
|
let symbolicEvDistribution = r => r->DistributionTypes.Symbolic->evDistribution
|
||||||
}
|
}
|
||||||
|
|
||||||
module Prepare = {
|
module Prepare = {
|
||||||
|
@ -30,6 +30,13 @@ module Prepare = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let oneDistOrNumber = (values: ts): result<frValueDistOrNumber, err> => {
|
||||||
|
switch values {
|
||||||
|
| [FRValueDistOrNumber(a1)] => Ok(a1)
|
||||||
|
| _ => Error(impossibleError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module Record = {
|
module Record = {
|
||||||
let twoDistOrNumber = (values: ts): result<(frValueDistOrNumber, frValueDistOrNumber), err> =>
|
let twoDistOrNumber = (values: ts): result<(frValueDistOrNumber, frValueDistOrNumber), err> =>
|
||||||
values->ToValueArray.Record.twoArgs->E.R.bind(twoDistOrNumber)
|
values->ToValueArray.Record.twoArgs->E.R.bind(twoDistOrNumber)
|
||||||
|
@ -38,20 +45,21 @@ module Prepare = {
|
||||||
}
|
}
|
||||||
|
|
||||||
module Process = {
|
module Process = {
|
||||||
let twoDistsOrNumbersToDist = (
|
module DistOrNumberToDist = {
|
||||||
~fn: ((float, float)) => result<DistributionTypes.genericDist, string>,
|
module Helpers = {
|
||||||
~values: (frValueDistOrNumber, frValueDistOrNumber),
|
let toSampleSet = (r, env: DistributionOperation.env) =>
|
||||||
~env: DistributionOperation.env,
|
GenericDist.toSampleSetDist(r, env.sampleCount)
|
||||||
): result<DistributionTypes.genericDist, string> => {
|
|
||||||
let toSampleSet = r => GenericDist.toSampleSetDist(r, env.sampleCount)
|
|
||||||
let mapFnResult = r =>
|
let mapFnResult = r =>
|
||||||
switch r {
|
switch r {
|
||||||
| Ok(r) => Ok(GenericDist.sample(r))
|
| Ok(r) => Ok(GenericDist.sample(r))
|
||||||
| Error(r) => Error(Operation.Other(r))
|
| Error(r) => Error(Operation.Other(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
let singleVarSample = (dist, fn) => {
|
let wrapSymbolic = (fn, r) => r->fn->E.R2.fmap(Wrappers.symbolic)
|
||||||
switch toSampleSet(dist) {
|
|
||||||
|
let singleVarSample = (dist, fn, env) => {
|
||||||
|
switch toSampleSet(dist, env) {
|
||||||
| Ok(dist) =>
|
| Ok(dist) =>
|
||||||
switch SampleSetDist.samplesMap(~fn=f => fn(f)->mapFnResult, dist) {
|
switch SampleSetDist.samplesMap(~fn=f => fn(f)->mapFnResult, dist) {
|
||||||
| Ok(r) => Ok(DistributionTypes.SampleSet(r))
|
| Ok(r) => Ok(DistributionTypes.SampleSet(r))
|
||||||
|
@ -61,9 +69,9 @@ module Process = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let twoVarSample = (dist1, dist2, fn) => {
|
let twoVarSample = (dist1, dist2, fn, env) => {
|
||||||
let altFn = (a, b) => fn((a, b))->mapFnResult
|
let altFn = (a, b) => fn((a, b))->mapFnResult
|
||||||
switch E.R.merge(toSampleSet(dist1), toSampleSet(dist2)) {
|
switch E.R.merge(toSampleSet(dist1, env), toSampleSet(dist2, env)) {
|
||||||
| Ok((t1, t2)) =>
|
| Ok((t1, t2)) =>
|
||||||
switch SampleSetDist.map2(~fn=altFn, ~t1, ~t2) {
|
switch SampleSetDist.map2(~fn=altFn, ~t1, ~t2) {
|
||||||
| Ok(r) => Ok(DistributionTypes.SampleSet(r))
|
| Ok(r) => Ok(DistributionTypes.SampleSet(r))
|
||||||
|
@ -72,28 +80,43 @@ module Process = {
|
||||||
| Error(r) => Error(DistributionTypes.Error.toString(r))
|
| Error(r) => Error(DistributionTypes.Error.toString(r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let oneValue = (
|
||||||
|
~fn: float => result<DistributionTypes.genericDist, string>,
|
||||||
|
~value: frValueDistOrNumber,
|
||||||
|
~env: DistributionOperation.env,
|
||||||
|
): result<DistributionTypes.genericDist, string> => {
|
||||||
|
switch value {
|
||||||
|
| FRValueNumber(a1) => fn(a1)
|
||||||
|
| FRValueDist(a1) => Helpers.singleVarSample(a1, r => fn(r), env)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let oneValueUsingSymbolicDist = (~fn, ~value) => oneValue(~fn=Helpers.wrapSymbolic(fn), ~value)
|
||||||
|
|
||||||
|
let twoValues = (
|
||||||
|
~fn: ((float, float)) => result<DistributionTypes.genericDist, string>,
|
||||||
|
~values: (frValueDistOrNumber, frValueDistOrNumber),
|
||||||
|
~env: DistributionOperation.env,
|
||||||
|
): result<DistributionTypes.genericDist, string> => {
|
||||||
switch values {
|
switch values {
|
||||||
| (FRValueNumber(a1), FRValueNumber(a2)) => fn((a1, a2))
|
| (FRValueNumber(a1), FRValueNumber(a2)) => fn((a1, a2))
|
||||||
| (FRValueDist(a1), FRValueNumber(a2)) => singleVarSample(a1, r => fn((r, a2)))
|
| (FRValueDist(a1), FRValueNumber(a2)) => Helpers.singleVarSample(a1, r => fn((r, a2)), env)
|
||||||
| (FRValueNumber(a1), FRValueDist(a2)) => singleVarSample(a2, r => fn((a1, r)))
|
| (FRValueNumber(a1), FRValueDist(a2)) => Helpers.singleVarSample(a2, r => fn((a1, r)), env)
|
||||||
| (FRValueDist(a1), FRValueDist(a2)) => twoVarSample(a1, a2, fn)
|
| (FRValueDist(a1), FRValueDist(a2)) => Helpers.twoVarSample(a1, a2, fn, env)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let twoDistsOrNumbersToDistUsingSymbolicDist = (
|
let twoValuesUsingSymbolicDist = (~fn, ~values) =>
|
||||||
~fn: ((float, float)) => result<SymbolicDistTypes.symbolicDist, string>,
|
twoValues(~fn=Helpers.wrapSymbolic(fn), ~values)
|
||||||
~values,
|
|
||||||
) => {
|
|
||||||
let newFn = r => fn(r)->E.R2.fmap(Wrappers.symbolic)
|
|
||||||
twoDistsOrNumbersToDist(~fn=newFn, ~values)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module TwoArgDist = {
|
module TwoArgDist = {
|
||||||
let process = (~fn, ~env, r) =>
|
let process = (~fn, ~env, r) =>
|
||||||
r
|
r
|
||||||
->E.R.bind(Process.twoDistsOrNumbersToDistUsingSymbolicDist(~fn, ~values=_, ~env))
|
->E.R.bind(Process.DistOrNumberToDist.twoValuesUsingSymbolicDist(~fn, ~values=_, ~env))
|
||||||
->E.R2.fmap(Wrappers.evDistribution)
|
->E.R2.fmap(Wrappers.evDistribution)
|
||||||
|
|
||||||
let make = (name, fn) => {
|
let make = (name, fn) => {
|
||||||
|
@ -117,5 +140,17 @@ module TwoArgDist = {
|
||||||
~run=(inputs, env) => inputs->Prepare.ToValueTuple.Record.twoDistOrNumber->process(~fn, ~env),
|
~run=(inputs, env) => inputs->Prepare.ToValueTuple.Record.twoDistOrNumber->process(~fn, ~env),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module OneArgDist = {
|
||||||
|
let process = (~fn, ~env, r) =>
|
||||||
|
r
|
||||||
|
->E.R.bind(Process.DistOrNumberToDist.oneValueUsingSymbolicDist(~fn, ~value=_, ~env))
|
||||||
|
->E.R2.fmap(Wrappers.evDistribution)
|
||||||
|
|
||||||
|
let make = (name, fn) => {
|
||||||
|
FnDefinition.make(~name, ~inputs=[FRTypeDistOrNumber], ~run=(inputs, env) =>
|
||||||
|
inputs->Prepare.ToValueTuple.oneDistOrNumber->process(~fn, ~env)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,9 @@ let registry = [
|
||||||
~name="Normal",
|
~name="Normal",
|
||||||
~definitions=[
|
~definitions=[
|
||||||
TwoArgDist.make("normal", twoArgs(SymbolicDist.Normal.make)),
|
TwoArgDist.make("normal", twoArgs(SymbolicDist.Normal.make)),
|
||||||
TwoArgDist.makeRecordP5P95("normal", r => twoArgs(SymbolicDist.Normal.from90PercentCI, r)->Ok),
|
TwoArgDist.makeRecordP5P95("normal", r =>
|
||||||
|
twoArgs(SymbolicDist.Normal.from90PercentCI, r)->Ok
|
||||||
|
),
|
||||||
TwoArgDist.makeRecordMeanStdev("normal", twoArgs(SymbolicDist.Normal.make)),
|
TwoArgDist.makeRecordMeanStdev("normal", twoArgs(SymbolicDist.Normal.make)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -44,9 +46,20 @@ let registry = [
|
||||||
),
|
),
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="To",
|
~name="To",
|
||||||
~definitions=[TwoArgDist.make("to", twoArgs(SymbolicDist.From90thPercentile.make)),
|
~definitions=[
|
||||||
TwoArgDist.make("credibleIntervalToDistribution", twoArgs(SymbolicDist.From90thPercentile.make))
|
TwoArgDist.make("to", twoArgs(SymbolicDist.From90thPercentile.make)),
|
||||||
|
TwoArgDist.make(
|
||||||
|
"credibleIntervalToDistribution",
|
||||||
|
twoArgs(SymbolicDist.From90thPercentile.make),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
|
Function.make(
|
||||||
|
~name="Exponential",
|
||||||
|
~definitions=[OneArgDist.make("exponential", SymbolicDist.Exponential.make)],
|
||||||
|
),
|
||||||
|
Function.make(
|
||||||
|
~name="Bernoulli",
|
||||||
|
~definitions=[OneArgDist.make("bernoulli", SymbolicDist.Bernoulli.make)],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -37,7 +37,7 @@ The Function name is just there for future documentation. The function defintion
|
||||||
## Key Files
|
## Key Files
|
||||||
|
|
||||||
**FunctionRegistry_Core**
|
**FunctionRegistry_Core**
|
||||||
Key types, internal functionality, and a ``Registry`` module with a ``matchAndRun`` function to call function definitions.
|
Key types, internal functionality, and a `Registry` module with a `matchAndRun` function to call function definitions.
|
||||||
|
|
||||||
**FunctionRegistry_Library**
|
**FunctionRegistry_Library**
|
||||||
A list of all the Functions defined in the Function Registry.
|
A list of all the Functions defined in the Function Registry.
|
||||||
|
|
|
@ -179,13 +179,6 @@ module Helpers = {
|
||||||
}
|
}
|
||||||
|
|
||||||
module SymbolicConstructors = {
|
module SymbolicConstructors = {
|
||||||
let oneFloat = name =>
|
|
||||||
switch name {
|
|
||||||
| "exponential" => Ok(SymbolicDist.Exponential.make)
|
|
||||||
| "bernoulli" => Ok(SymbolicDist.Bernoulli.make)
|
|
||||||
| _ => Error("Unreachable state")
|
|
||||||
}
|
|
||||||
|
|
||||||
let threeFloat = name =>
|
let threeFloat = name =>
|
||||||
switch name {
|
switch name {
|
||||||
| "triangular" => Ok(SymbolicDist.Triangular.make)
|
| "triangular" => Ok(SymbolicDist.Triangular.make)
|
||||||
|
@ -207,10 +200,6 @@ let dispatchToGenericOutput = (
|
||||||
): option<DistributionOperation.outputType> => {
|
): option<DistributionOperation.outputType> => {
|
||||||
let (fnName, args) = call
|
let (fnName, args) = call
|
||||||
switch (fnName, args) {
|
switch (fnName, args) {
|
||||||
| (("exponential" | "bernoulli") as fnName, [EvNumber(f)]) =>
|
|
||||||
SymbolicConstructors.oneFloat(fnName)
|
|
||||||
->E.R.bind(r => r(f))
|
|
||||||
->SymbolicConstructors.symbolicResultToOutput
|
|
||||||
| ("delta", [EvNumber(f)]) =>
|
| ("delta", [EvNumber(f)]) =>
|
||||||
SymbolicDist.Float.makeSafe(f)->SymbolicConstructors.symbolicResultToOutput
|
SymbolicDist.Float.makeSafe(f)->SymbolicConstructors.symbolicResultToOutput
|
||||||
| ("triangular" as fnName, [EvNumber(f1), EvNumber(f2), EvNumber(f3)]) =>
|
| ("triangular" as fnName, [EvNumber(f1), EvNumber(f2), EvNumber(f3)]) =>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user