Added examples to most items in function registry library

This commit is contained in:
Ozzie Gooen 2022-07-15 19:47:57 -07:00
parent 9d5aaf43a8
commit e3ef7a3048

View File

@ -120,6 +120,12 @@ module Functionn = {
module DistributionCreation = { module DistributionCreation = {
let nameSpace = "Dist" let nameSpace = "Dist"
let output = ReducerInterface_InternalExpressionValue.EvtDistribution
let fnMake = (~name, ~examples, ~definitions) => {
Function.make(~name, ~nameSpace, ~output, ~examples, ~definitions, ())
}
module TwoArgDist = { module TwoArgDist = {
let process = (~fn, ~env, r) => let process = (~fn, ~env, r) =>
r r
@ -176,9 +182,8 @@ module DistributionCreation = {
} }
let library = [ let library = [
Function.make( fnMake(
~name="normal", ~name="normal",
~nameSpace,
~examples=["normal(5,1)", "normal({p5: 4, p95: 10})", "normal({mean: 5, stdev: 2})"], ~examples=["normal(5,1)", "normal({p5: 4, p95: 10})", "normal({mean: 5, stdev: 2})"],
~definitions=[ ~definitions=[
TwoArgDist.make("normal", twoArgs(SymbolicDist.Normal.make)), TwoArgDist.make("normal", twoArgs(SymbolicDist.Normal.make)),
@ -187,11 +192,9 @@ module DistributionCreation = {
), ),
TwoArgDist.makeRecordMeanStdev("normal", twoArgs(SymbolicDist.Normal.make)), TwoArgDist.makeRecordMeanStdev("normal", twoArgs(SymbolicDist.Normal.make)),
], ],
(),
), ),
Function.make( fnMake(
~name="lognormal", ~name="lognormal",
~nameSpace,
~examples=[ ~examples=[
"lognormal(0.5, 0.8)", "lognormal(0.5, 0.8)",
"lognormal({p5: 4, p95: 10})", "lognormal({p5: 4, p95: 10})",
@ -207,49 +210,37 @@ module DistributionCreation = {
twoArgs(SymbolicDist.Lognormal.fromMeanAndStdev), twoArgs(SymbolicDist.Lognormal.fromMeanAndStdev),
), ),
], ],
(),
), ),
Function.make( fnMake(
~name="uniform", ~name="uniform",
~nameSpace,
~examples=[`uniform(10, 12)`], ~examples=[`uniform(10, 12)`],
~definitions=[TwoArgDist.make("uniform", twoArgs(SymbolicDist.Uniform.make))], ~definitions=[TwoArgDist.make("uniform", twoArgs(SymbolicDist.Uniform.make))],
(),
), ),
Function.make( fnMake(
~name="beta", ~name="beta",
~nameSpace,
~examples=[`beta(20, 25)`, `beta({mean: 0.39, stdev: 0.1})`], ~examples=[`beta(20, 25)`, `beta({mean: 0.39, stdev: 0.1})`],
~definitions=[ ~definitions=[
TwoArgDist.make("beta", twoArgs(SymbolicDist.Beta.make)), TwoArgDist.make("beta", twoArgs(SymbolicDist.Beta.make)),
TwoArgDist.makeRecordMeanStdev("beta", twoArgs(SymbolicDist.Beta.fromMeanAndStdev)), TwoArgDist.makeRecordMeanStdev("beta", twoArgs(SymbolicDist.Beta.fromMeanAndStdev)),
], ],
(),
), ),
Function.make( fnMake(
~name="cauchy", ~name="cauchy",
~nameSpace,
~examples=[`cauchy(5, 1)`], ~examples=[`cauchy(5, 1)`],
~definitions=[TwoArgDist.make("cauchy", twoArgs(SymbolicDist.Cauchy.make))], ~definitions=[TwoArgDist.make("cauchy", twoArgs(SymbolicDist.Cauchy.make))],
(),
), ),
Function.make( fnMake(
~name="gamma", ~name="gamma",
~nameSpace,
~examples=[`gamma(5, 1)`], ~examples=[`gamma(5, 1)`],
~definitions=[TwoArgDist.make("gamma", twoArgs(SymbolicDist.Gamma.make))], ~definitions=[TwoArgDist.make("gamma", twoArgs(SymbolicDist.Gamma.make))],
(),
), ),
Function.make( fnMake(
~name="logistic", ~name="logistic",
~nameSpace,
~examples=[`logistic(5, 1)`], ~examples=[`logistic(5, 1)`],
~definitions=[TwoArgDist.make("logistic", twoArgs(SymbolicDist.Logistic.make))], ~definitions=[TwoArgDist.make("logistic", twoArgs(SymbolicDist.Logistic.make))],
(),
), ),
Function.make( fnMake(
~name="to (distribution)", ~name="to (distribution)",
~nameSpace,
~examples=[`5 to 10`, `to(5,10)`, `-5 to 5`], ~examples=[`5 to 10`, `to(5,10)`, `-5 to 5`],
~definitions=[ ~definitions=[
TwoArgDist.make("to", twoArgs(SymbolicDist.From90thPercentile.make)), TwoArgDist.make("to", twoArgs(SymbolicDist.From90thPercentile.make)),
@ -258,28 +249,21 @@ module DistributionCreation = {
twoArgs(SymbolicDist.From90thPercentile.make), twoArgs(SymbolicDist.From90thPercentile.make),
), ),
], ],
(),
), ),
Function.make( fnMake(
~name="exponential", ~name="exponential",
~nameSpace,
~examples=[`exponential(2)`], ~examples=[`exponential(2)`],
~definitions=[OneArgDist.make("exponential", SymbolicDist.Exponential.make)], ~definitions=[OneArgDist.make("exponential", SymbolicDist.Exponential.make)],
(),
), ),
Function.make( fnMake(
~name="bernoulli", ~name="bernoulli",
~nameSpace,
~examples=[`bernoulli(0.5)`], ~examples=[`bernoulli(0.5)`],
~definitions=[OneArgDist.make("bernoulli", SymbolicDist.Bernoulli.make)], ~definitions=[OneArgDist.make("bernoulli", SymbolicDist.Bernoulli.make)],
(),
), ),
Function.make( fnMake(
~name="pointMass", ~name="pointMass",
~nameSpace,
~examples=[`pointMass(0.5)`], ~examples=[`pointMass(0.5)`],
~definitions=[OneArgDist.make("pointMass", SymbolicDist.Float.makeSafe)], ~definitions=[OneArgDist.make("pointMass", SymbolicDist.Float.makeSafe)],
(),
), ),
] ]
} }
@ -335,60 +319,80 @@ module Number = {
Function.make( Function.make(
~name="floor", ~name="floor",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`floor(3.5)`],
~definitions=[NumberToNumber.make("floor", Js.Math.floor_float)], ~definitions=[NumberToNumber.make("floor", Js.Math.floor_float)],
(), (),
), ),
Function.make( Function.make(
~name="ceiling", ~name="ceiling",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`ceiling(3.5)`],
~definitions=[NumberToNumber.make("ceil", Js.Math.ceil_float)], ~definitions=[NumberToNumber.make("ceil", Js.Math.ceil_float)],
(), (),
), ),
Function.make( Function.make(
~name="absolute value", ~name="absolute value",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`abs(3.5)`],
~definitions=[NumberToNumber.make("abs", Js.Math.abs_float)], ~definitions=[NumberToNumber.make("abs", Js.Math.abs_float)],
(), (),
), ),
Function.make( Function.make(
~name="exponent", ~name="exponent",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`exp(3.5)`],
~definitions=[NumberToNumber.make("exp", Js.Math.exp)], ~definitions=[NumberToNumber.make("exp", Js.Math.exp)],
(), (),
), ),
Function.make( Function.make(
~name="log", ~name="log",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`log(3.5)`],
~definitions=[NumberToNumber.make("log", Js.Math.log)], ~definitions=[NumberToNumber.make("log", Js.Math.log)],
(), (),
), ),
Function.make( Function.make(
~name="log base 10", ~name="log base 10",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`log10(3.5)`],
~definitions=[NumberToNumber.make("log10", Js.Math.log10)], ~definitions=[NumberToNumber.make("log10", Js.Math.log10)],
(), (),
), ),
Function.make( Function.make(
~name="log base 2", ~name="log base 2",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`log2(3.5)`],
~definitions=[NumberToNumber.make("log2", Js.Math.log2)], ~definitions=[NumberToNumber.make("log2", Js.Math.log2)],
(), (),
), ),
Function.make( Function.make(
~name="round", ~name="round",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`round(3.5)`],
~definitions=[NumberToNumber.make("round", Js.Math.round)], ~definitions=[NumberToNumber.make("round", Js.Math.round)],
(), (),
), ),
Function.make( Function.make(
~name="sum", ~name="sum",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`sum([3,5,2])`],
~definitions=[ArrayNumberDist.make("sum", r => r->E.A.Floats.sum->Wrappers.evNumber->Ok)], ~definitions=[ArrayNumberDist.make("sum", r => r->E.A.Floats.sum->Wrappers.evNumber->Ok)],
(), (),
), ),
Function.make( Function.make(
~name="product", ~name="product",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`product([3,5,2])`],
~definitions=[ ~definitions=[
ArrayNumberDist.make("product", r => r->E.A.Floats.product->Wrappers.evNumber->Ok), ArrayNumberDist.make("product", r => r->E.A.Floats.product->Wrappers.evNumber->Ok),
], ],
@ -397,24 +401,32 @@ module Number = {
Function.make( Function.make(
~name="min", ~name="min",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`min([3,5,2])`],
~definitions=[ArrayNumberDist.make("min", r => r->E.A.Floats.min->Wrappers.evNumber->Ok)], ~definitions=[ArrayNumberDist.make("min", r => r->E.A.Floats.min->Wrappers.evNumber->Ok)],
(), (),
), ),
Function.make( Function.make(
~name="max", ~name="max",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`max([3,5,2])`],
~definitions=[ArrayNumberDist.make("max", r => r->E.A.Floats.max->Wrappers.evNumber->Ok)], ~definitions=[ArrayNumberDist.make("max", r => r->E.A.Floats.max->Wrappers.evNumber->Ok)],
(), (),
), ),
Function.make( Function.make(
~name="mean", ~name="mean",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`mean([3,5,2])`],
~definitions=[ArrayNumberDist.make("mean", r => r->E.A.Floats.mean->Wrappers.evNumber->Ok)], ~definitions=[ArrayNumberDist.make("mean", r => r->E.A.Floats.mean->Wrappers.evNumber->Ok)],
(), (),
), ),
Function.make( Function.make(
~name="geometric mean", ~name="geometric mean",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`geomean([3,5,2])`],
~definitions=[ ~definitions=[
ArrayNumberDist.make("geomean", r => r->E.A.Floats.geomean->Wrappers.evNumber->Ok), ArrayNumberDist.make("geomean", r => r->E.A.Floats.geomean->Wrappers.evNumber->Ok),
], ],
@ -423,12 +435,16 @@ module Number = {
Function.make( Function.make(
~name="standard deviation", ~name="standard deviation",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`stdev([3,5,2,3,5])`],
~definitions=[ArrayNumberDist.make("stdev", r => r->E.A.Floats.stdev->Wrappers.evNumber->Ok)], ~definitions=[ArrayNumberDist.make("stdev", r => r->E.A.Floats.stdev->Wrappers.evNumber->Ok)],
(), (),
), ),
Function.make( Function.make(
~name="variance", ~name="variance",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[`variance([3,5,2,3,5])`],
~definitions=[ ~definitions=[
ArrayNumberDist.make("variance", r => r->E.A.Floats.stdev->Wrappers.evNumber->Ok), ArrayNumberDist.make("variance", r => r->E.A.Floats.stdev->Wrappers.evNumber->Ok),
], ],
@ -437,6 +453,8 @@ module Number = {
Function.make( Function.make(
~name="sort", ~name="sort",
~nameSpace, ~nameSpace,
~output=EvtArray,
~examples=[`sort([3,5,2,3,5])`],
~definitions=[ ~definitions=[
ArrayNumberDist.make("sort", r => ArrayNumberDist.make("sort", r =>
r->E.A.Floats.sort->E.A2.fmap(Wrappers.evNumber)->Wrappers.evArray->Ok r->E.A.Floats.sort->E.A2.fmap(Wrappers.evNumber)->Wrappers.evArray->Ok
@ -447,6 +465,8 @@ module Number = {
Function.make( Function.make(
~name="cumulative sum", ~name="cumulative sum",
~nameSpace, ~nameSpace,
~output=EvtArray,
~examples=[`cumsum([3,5,2,3,5])`],
~definitions=[ ~definitions=[
ArrayNumberDist.make("cumsum", r => ArrayNumberDist.make("cumsum", r =>
r->E.A.Floats.cumsum->E.A2.fmap(Wrappers.evNumber)->Wrappers.evArray->Ok r->E.A.Floats.cumsum->E.A2.fmap(Wrappers.evNumber)->Wrappers.evArray->Ok
@ -457,6 +477,8 @@ module Number = {
Function.make( Function.make(
~name="cumulative prod", ~name="cumulative prod",
~nameSpace, ~nameSpace,
~output=EvtArray,
~examples=[`cumprod([3,5,2,3,5])`],
~definitions=[ ~definitions=[
ArrayNumberDist.make("cumprod", r => ArrayNumberDist.make("cumprod", r =>
r->E.A.Floats.cumsum->E.A2.fmap(Wrappers.evNumber)->Wrappers.evArray->Ok r->E.A.Floats.cumsum->E.A2.fmap(Wrappers.evNumber)->Wrappers.evArray->Ok
@ -467,6 +489,8 @@ module Number = {
Function.make( Function.make(
~name="diff", ~name="diff",
~nameSpace, ~nameSpace,
~output=EvtArray,
~examples=[`diff([3,5,2,3,5])`],
~definitions=[ ~definitions=[
ArrayNumberDist.make("diff", r => ArrayNumberDist.make("diff", r =>
r->E.A.Floats.diff->E.A2.fmap(Wrappers.evNumber)->Wrappers.evArray->Ok r->E.A.Floats.diff->E.A2.fmap(Wrappers.evNumber)->Wrappers.evArray->Ok
@ -524,6 +548,8 @@ module Dict = {
Function.make( Function.make(
~name="merge", ~name="merge",
~nameSpace, ~nameSpace,
~output=EvtRecord,
~examples=[`Dict.merge({a: 1, b: 2}, {c: 3, d: 4})`],
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~requiresNamespace=true, ~requiresNamespace=true,
@ -544,6 +570,8 @@ module Dict = {
Function.make( Function.make(
~name="mergeMany", ~name="mergeMany",
~nameSpace, ~nameSpace,
~output=EvtRecord,
~examples=[`Dict.mergeMany([{a: 1, b: 2}, {c: 3, d: 4}])`],
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~requiresNamespace=true, ~requiresNamespace=true,
@ -564,6 +592,8 @@ module Dict = {
Function.make( Function.make(
~name="keys", ~name="keys",
~nameSpace, ~nameSpace,
~output=EvtArray,
~examples=[`Dict.keys({a: 1, b: 2})`],
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~requiresNamespace=true, ~requiresNamespace=true,
@ -582,6 +612,8 @@ module Dict = {
Function.make( Function.make(
~name="values", ~name="values",
~nameSpace, ~nameSpace,
~output=EvtArray,
~examples=[`Dict.values({a: 1, b: 2})`],
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~requiresNamespace=true, ~requiresNamespace=true,
@ -600,6 +632,8 @@ module Dict = {
Function.make( Function.make(
~name="toList", ~name="toList",
~nameSpace, ~nameSpace,
~output=EvtArray,
~examples=[`Dict.toList({a: 1, b: 2})`],
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~requiresNamespace=true, ~requiresNamespace=true,
@ -618,6 +652,8 @@ module Dict = {
Function.make( Function.make(
~name="fromList", ~name="fromList",
~nameSpace, ~nameSpace,
~output=EvtRecord,
~examples=[`Dict.fromList({a: 1, b: 2})`],
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~requiresNamespace=true, ~requiresNamespace=true,
@ -667,6 +703,8 @@ module List = {
Function.make( Function.make(
~name="make", ~name="make",
~nameSpace, ~nameSpace,
~output=EvtArray,
~examples=[`List.make(2, "testValue")`],
~definitions=[ ~definitions=[
//Todo: If the second item is a function with no args, it could be nice to run this function and return the result. //Todo: If the second item is a function with no args, it could be nice to run this function and return the result.
FnDefinition.make( FnDefinition.make(
@ -687,6 +725,8 @@ module List = {
Function.make( Function.make(
~name="upTo", ~name="upTo",
~nameSpace, ~nameSpace,
~output=EvtArray,
~examples=[`List.upTo(1,4)`],
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~requiresNamespace, ~requiresNamespace,
@ -704,6 +744,7 @@ module List = {
Function.make( Function.make(
~name="first", ~name="first",
~nameSpace, ~nameSpace,
~examples=[`List.first([1,4,5])`],
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~requiresNamespace, ~requiresNamespace,
@ -722,6 +763,7 @@ module List = {
Function.make( Function.make(
~name="last", ~name="last",
~nameSpace, ~nameSpace,
~examples=[`List.last([1,4,5])`],
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~requiresNamespace=false, ~requiresNamespace=false,
@ -740,6 +782,8 @@ module List = {
Function.make( Function.make(
~name="reverse", ~name="reverse",
~nameSpace, ~nameSpace,
~output=EvtArray,
~examples=[`List.reverse([1,4,5])`],
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~requiresNamespace=false, ~requiresNamespace=false,
@ -772,6 +816,12 @@ module Scoring = {
Function.make( Function.make(
~name="logScore", ~name="logScore",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[
"Dist.logScore({estimate: normal(5,2), answer: normal(5.2,1)}, prior: normal(5.5,3)})",
"Dist.logScore({estimate: normal(5,2), answer: normal(5.2,1)}})",
"Dist.logScore({estimate: normal(5,2), answer: 4.5})",
],
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~requiresNamespace, ~requiresNamespace,
@ -825,6 +875,10 @@ module Scoring = {
Function.make( Function.make(
~name="klDivergence", ~name="klDivergence",
~nameSpace, ~nameSpace,
~output=EvtNumber,
~examples=[
"Dist.klDivergence(normal(5,2), normal(5,1.5)",
],
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~name="klDivergence", ~name="klDivergence",