Story cleanup
This commit is contained in:
parent
acebaa517b
commit
47f1be0702
|
@ -68,7 +68,7 @@ describe("FunctionRegistry Library", () => {
|
|||
"Ok([2,3,4,5,6,7])",
|
||||
)
|
||||
testEvalToBe(
|
||||
"toList(SampleSet.mapN([SampleSet.fromList([1,2,3,4,5,6]), SampleSet.fromList([6, 5, 4, 3, 2, 1])], {|x| x[0] > x[1] ? x[0] : x[1]}))",
|
||||
"SampleSet.toList(SampleSet.mapN([SampleSet.fromList([1,2,3,4,5,6]), SampleSet.fromList([6, 5, 4, 3, 2, 1])], {|x| x[0] > x[1] ? x[0] : x[1]}))",
|
||||
"Ok([6,5,4,4,5,6])",
|
||||
)
|
||||
})
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
"test:reducer": "jest __tests__/Reducer*/",
|
||||
"benchmark": "ts-node benchmark/conversion_tests.ts",
|
||||
"test": "jest",
|
||||
"test:lib": "jest __tests__/SquiggleLibrary/SquiggleLibrary_FunctionRegistryLibrary_test.bs.js",
|
||||
"test:ts": "jest __tests__/TS/",
|
||||
"test:rescript": "jest --modulePathIgnorePatterns=__tests__/TS/*",
|
||||
"test:watch": "jest --watchAll",
|
||||
"test:fnRegistry": "jest __tests__/SquiggleLibrary/SquiggleLibrary_FunctionRegistryLibrary_test.bs.js",
|
||||
"coverage:rescript": "rm -f *.coverage && yarn clean && BISECT_ENABLE=yes yarn build && yarn test:rescript && bisect-ppx-report html",
|
||||
"coverage:ts": "yarn clean && yarn build && nyc --reporter=lcov yarn test:ts",
|
||||
"coverage:rescript:ci": "yarn clean && BISECT_ENABLE=yes yarn build:rescript && yarn test:rescript && bisect-ppx-report send-to Codecov",
|
||||
|
|
|
@ -170,7 +170,6 @@ module FRType = {
|
|||
inputs: array<t>,
|
||||
args: array<internalExpressionValue>,
|
||||
): option<array<frValue>> => {
|
||||
// Js.log3("Matching", inputs, args)
|
||||
let isSameLength = E.A.length(inputs) == E.A.length(args)
|
||||
if !isSameLength {
|
||||
None
|
||||
|
@ -186,6 +185,9 @@ module FRType = {
|
|||
This module, Matcher, is fairly lengthy. However, only two functions from it
|
||||
are meant to be used outside of it. These are findMatches and matchToDef in Matches.Registry.
|
||||
The rest of it is just called from those two functions.
|
||||
|
||||
Update: This really should be completely re-done sometime, and tested. It works, but it's pretty messy. I'm sure
|
||||
there are internal bugs, but the end functionality works, so I'm not too worried.
|
||||
*/
|
||||
module Matcher = {
|
||||
module MatchSimple = {
|
||||
|
@ -243,11 +245,11 @@ module Matcher = {
|
|||
|
||||
let match = (
|
||||
f: function,
|
||||
namespace: option<string>,
|
||||
nameSpace: option<string>,
|
||||
fnName: string,
|
||||
args: array<internalExpressionValue>,
|
||||
): match => {
|
||||
switch namespace {
|
||||
switch nameSpace {
|
||||
| Some(ns) if ns !== f.nameSpace => Match.DifferentName
|
||||
| _ => {
|
||||
let matchedDefinition = () =>
|
||||
|
@ -280,12 +282,12 @@ module Matcher = {
|
|||
|
||||
module RegistryMatch = {
|
||||
type match = {
|
||||
namespace: string,
|
||||
nameSpace: string,
|
||||
fnName: string,
|
||||
inputIndex: int,
|
||||
}
|
||||
let makeMatch = (namespace: string, fnName: string, inputIndex: int) => {
|
||||
namespace: namespace,
|
||||
let makeMatch = (nameSpace: string, fnName: string, inputIndex: int) => {
|
||||
nameSpace: nameSpace,
|
||||
fnName: fnName,
|
||||
inputIndex: inputIndex,
|
||||
}
|
||||
|
@ -294,12 +296,12 @@ module Matcher = {
|
|||
module Registry = {
|
||||
let _findExactMatches = (
|
||||
r: registry,
|
||||
namespace: option<string>,
|
||||
nameSpace: option<string>,
|
||||
fnName: string,
|
||||
args: array<internalExpressionValue>,
|
||||
) => {
|
||||
let functionMatchPairs =
|
||||
r.functions->E.A2.fmap(l => (l, Function.match(l, namespace, fnName, args)))
|
||||
r.functions->E.A2.fmap(l => (l, Function.match(l, nameSpace, fnName, args)))
|
||||
let fullMatch = functionMatchPairs->E.A.getBy(((_, match)) => Match.isFullMatch(match))
|
||||
fullMatch->E.O.bind(((fn, match)) =>
|
||||
switch match {
|
||||
|
@ -311,12 +313,12 @@ module Matcher = {
|
|||
|
||||
let _findNameMatches = (
|
||||
r: registry,
|
||||
namespace: option<string>,
|
||||
nameSpace: option<string>,
|
||||
fnName: string,
|
||||
args: array<internalExpressionValue>,
|
||||
) => {
|
||||
let functionMatchPairs =
|
||||
r.functions->E.A2.fmap(l => (l, Function.match(l, namespace, fnName, args)))
|
||||
r.functions->E.A2.fmap(l => (l, Function.match(l, nameSpace, fnName, args)))
|
||||
let getNameMatches =
|
||||
functionMatchPairs
|
||||
->E.A2.fmap(((fn, match)) => Match.isNameMatchOnly(match) ? Some((fn, match)) : None)
|
||||
|
@ -351,11 +353,11 @@ module Matcher = {
|
|||
|
||||
let matchToDef = (
|
||||
registry: registry,
|
||||
{namespace, fnName, inputIndex}: RegistryMatch.match,
|
||||
{nameSpace, fnName, inputIndex}: RegistryMatch.match,
|
||||
): option<fnDefinition> =>
|
||||
registry.functions
|
||||
->E.A.getBy(fn => {
|
||||
namespace === fn.nameSpace && fnName === fn.name
|
||||
nameSpace === fn.nameSpace && fnName === fn.name
|
||||
})
|
||||
->E.O.bind(fn => E.A.get(fn.definitions, inputIndex))
|
||||
}
|
||||
|
@ -508,8 +510,6 @@ module Registry = {
|
|||
`There are function matches for ${fnName}(), but with different arguments: ${defs}`
|
||||
}
|
||||
|
||||
// let match = Matcher.Registry.findMatches(modified, fnName, args); Js.log2("Match", match)
|
||||
|
||||
switch Matcher.Registry.findMatches(modified, fnName, args) {
|
||||
| Matcher.Match.FullMatch(match) =>
|
||||
match->matchToDef->E.O2.fmap(FnDefinition.run(_, args, env, reducer))
|
||||
|
|
|
@ -156,7 +156,7 @@ let library = [
|
|||
FnDefinition.make(
|
||||
~name="fromList",
|
||||
~inputs=[FRTypeArray(FRTypeArray(FRTypeAny))],
|
||||
~run=(inputs, _, _, _) =>{
|
||||
~run=(inputs, _, _, _) => {
|
||||
switch inputs {
|
||||
| [IEvArray(items)] => Internals.fromList(items)
|
||||
| _ => Error(impossibleError)
|
||||
|
|
|
@ -28,8 +28,8 @@ module Internal = {
|
|||
reducer,
|
||||
) => {
|
||||
let sampleCount = env.sampleCount
|
||||
let fn = (r) => doLambdaCall(aLambdaValue, list{IEvNumber(r)}, env, reducer)
|
||||
Belt_Array.makeBy(sampleCount, (r) => fn(r->Js.Int.toFloat))->E.A.R.firstErrorOrOpen
|
||||
let fn = r => doLambdaCall(aLambdaValue, list{IEvNumber(r)}, env, reducer)
|
||||
Belt_Array.makeBy(sampleCount, r => fn(r->Js.Int.toFloat))->E.A.R.firstErrorOrOpen
|
||||
}
|
||||
|
||||
let map1 = (sampleSetDist: t, aLambdaValue, env, reducer) => {
|
||||
|
@ -125,7 +125,7 @@ let library = [
|
|||
Function.make(
|
||||
~name="toList",
|
||||
~nameSpace,
|
||||
~requiresNamespace=false,
|
||||
~requiresNamespace=true,
|
||||
~examples=[`SampleSet.toList(SampleSet.fromDist(normal(5,2)))`],
|
||||
~output=ReducerInterface_InternalExpressionValue.EvtArray,
|
||||
~definitions=[
|
||||
|
@ -146,9 +146,9 @@ let library = [
|
|||
Function.make(
|
||||
~name="fromFn",
|
||||
~nameSpace,
|
||||
~requiresNamespace=false,
|
||||
~examples=[`SampleSet.fromFn(sample(normal(5,2)))`],
|
||||
~output=ReducerInterface_InternalExpressionValue.EvtArray,
|
||||
~requiresNamespace=true,
|
||||
~examples=[`SampleSet.fromFn({|| sample(normal(5,2))})`],
|
||||
~output=ReducerInterface_InternalExpressionValue.EvtDistribution,
|
||||
~definitions=[
|
||||
FnDefinition.make(
|
||||
~name="fromFn",
|
||||
|
|
|
@ -96,7 +96,6 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
|
|||
let doExportBindings = (bindings: nameSpace) => bindings->Bindings.toExpressionValue->Ok
|
||||
|
||||
module SampleMap = {
|
||||
type t = SampleSetDist.t
|
||||
let doLambdaCall = (aLambdaValue, list) =>
|
||||
switch Lambda.doLambdaCall(aLambdaValue, list, environment, reducer) {
|
||||
| Ok(IEvNumber(f)) => Ok(f)
|
||||
|
|
|
@ -233,19 +233,6 @@ let dispatchToGenericOutput = (call: IEV.functionCall, env: GenericDist.env): op
|
|||
| ("inv", [IEvDistribution(dist), IEvNumber(float)]) => Helpers.toFloatFn(#Inv(float), dist, ~env)
|
||||
| ("quantile", [IEvDistribution(dist), IEvNumber(float)]) =>
|
||||
Helpers.toFloatFn(#Inv(float), dist, ~env)
|
||||
| ("toSampleSet", [IEvDistribution(dist), IEvNumber(float)]) =>
|
||||
Helpers.toDistFn(ToSampleSet(Belt.Int.fromFloat(float)), dist, ~env)
|
||||
| ("toSampleSet", [IEvDistribution(dist)]) =>
|
||||
Helpers.toDistFn(ToSampleSet(env.sampleCount), dist, ~env)
|
||||
| ("toList", [IEvDistribution(SampleSet(dist))]) => Some(FloatArray(SampleSetDist.T.get(dist)))
|
||||
| ("fromSamples", [IEvArray(inputArray)]) => {
|
||||
let _wrapInputErrors = x => SampleSetDist.NonNumericInput(x)
|
||||
let parsedArray = Helpers.parseNumberArray(inputArray)->E.R2.errMap(_wrapInputErrors)
|
||||
switch parsedArray {
|
||||
| Ok(array) => DistributionOperation.run(FromSamples(array), ~env)
|
||||
| Error(e) => GenDistError(SampleSetError(e))
|
||||
}->Some
|
||||
}
|
||||
| ("inspect", [IEvDistribution(dist)]) => Helpers.toDistFn(Inspect, dist, ~env)
|
||||
| ("truncateLeft", [IEvDistribution(dist), IEvNumber(float)]) =>
|
||||
Helpers.toDistFn(Truncate(Some(float), None), dist, ~env)
|
||||
|
|
|
@ -3,10 +3,6 @@ sidebar_position: 5
|
|||
title: Sample Set Distribution
|
||||
---
|
||||
|
||||
:::danger
|
||||
These functions aren't yet implemented with these specific names. This should be added soon.
|
||||
:::
|
||||
|
||||
Sample set distributions are one of the three distribution formats. Internally, they are stored as a list of numbers. It's useful to distinguish point set distributions from arbitrary lists of numbers to make it clear which functions are applicable.
|
||||
|
||||
Monte Carlo calculations typically result in sample set distributions.
|
||||
|
@ -25,9 +21,8 @@ Sampleset.fromList: (list<number>) => sampleSet
|
|||
|
||||
### fromFn
|
||||
|
||||
(Not yet implemented)
|
||||
```
|
||||
Sampleset.fromFn: (() => number) => sampleSet
|
||||
Sampleset.fromFn: ((float) => number) => sampleSet
|
||||
```
|
||||
|
||||
### toList
|
||||
|
@ -61,3 +56,9 @@ Sampleset.map2: (sampleSet, sampleSet, ((number, number) => number)) => sampleSe
|
|||
```
|
||||
Sampleset.map3: (sampleSet, sampleSet, sampleSet, ((number, number, number) => number)) => sampleSet
|
||||
```
|
||||
|
||||
### mapN
|
||||
|
||||
```
|
||||
Sampleset.mapN: (list<sampleSet>, (list<sampleSet> => number)) => sampleSet
|
||||
```
|
Loading…
Reference in New Issue
Block a user