Trying to fix things, but breaking a lot of tests.

This commit is contained in:
Ozzie Gooen 2022-07-19 21:32:11 -07:00
parent 35cd9f37d1
commit 90d3f89c0a
4 changed files with 49 additions and 15 deletions

View File

@ -18,7 +18,7 @@ describe("builtin", () => {
testEval("2>1", "Ok(true)") testEval("2>1", "Ok(true)")
testEval("concat('a','b')", "Ok('ab')") testEval("concat('a','b')", "Ok('ab')")
testEval( testEval(
"addOne(t)=t+1; toList(mapSamples(fromSamples([1,2,3,4,5,6]), addOne))", "addOne(t)=t+1; toList(Sampleset.map(fromSamples([1,2,3,4,5,6]), addOne))",
"Ok([2,3,4,5,6,7])", "Ok([2,3,4,5,6,7])",
) )
testEval( testEval(

View File

@ -41,12 +41,6 @@ describe("eval on distribution functions", () => {
describe("normalize", () => { describe("normalize", () => {
testEval("normalize(normal(5,2))", "Ok(Normal(5,2))") testEval("normalize(normal(5,2))", "Ok(Normal(5,2))")
}) })
describe("toPointSet", () => {
testEval("toPointSet(normal(5,2))", "Ok(Point Set Distribution)")
})
describe("toSampleSet", () => {
testEval("toSampleSet(normal(5,2), 100)", "Ok(Sample Set Distribution)")
})
describe("add", () => { describe("add", () => {
testEval("add(normal(5,2), normal(10,2))", "Ok(Normal(15,2.8284271247461903))") testEval("add(normal(5,2), normal(10,2))", "Ok(Normal(15,2.8284271247461903))")
testEval("add(normal(5,2), lognormal(10,2))", "Ok(Sample Set Distribution)") testEval("add(normal(5,2), lognormal(10,2))", "Ok(Sample Set Distribution)")

View File

@ -90,14 +90,57 @@ let library = [
(), (),
), ),
Function.make( Function.make(
~name="map", ~name="fromLlist",
~nameSpace, ~nameSpace,
~requiresNamespace, ~requiresNamespace=true,
~examples=[`Sampleset.map(Sampleset.maker(normal(5,2)), {|x| x + 1})`], ~examples=[`Sampleset.fromLlist([3,5,2,3,5,2,3,5,2,3,3,5,3,2,3,1,1,3])`],
~output=ReducerInterface_InternalExpressionValue.EvtDistribution, ~output=ReducerInterface_InternalExpressionValue.EvtDistribution,
~definitions=[ ~definitions=[
FnDefinition.make( FnDefinition.make(
~name="map", ~name="fromLlist",
~inputs=[FRTypeArray(FRTypeNumber)],
~run=(_, inputs, _, _) => {
let sampleSet =
Prepare.ToTypedArray.numbers(inputs) |> E.R2.bind(r =>
SampleSetDist.make(r)->E.R2.errMap(_ => "")
)
sampleSet->E.R2.fmap(Wrappers.sampleSet)->E.R2.fmap(Wrappers.evDistribution)
},
(),
),
],
(),
),
Function.make(
~name="toLlist",
~nameSpace,
~requiresNamespace=false,
~examples=[`Sampleset.toLlist(Sampleset.maker(normal(5,2))`],
~output=ReducerInterface_InternalExpressionValue.EvtArray,
~definitions=[
FnDefinition.make(
~name="toLlist",
~inputs=[FRTypeDist],
~run=(inputs, _, _, _) =>
switch inputs {
| [IEvDistribution(SampleSet(dist))] =>
dist->E.A2.fmap(Wrappers.evNumber)->Wrappers.evArray->Ok
| _ => Error(impossibleError)
},
(),
),
],
(),
),
Function.make(
~name="mapp",
~nameSpace,
~requiresNamespace,
~examples=[`Sampleset.mapp(Sampleset.maker(normal(5,2)), {|x| x + 1})`],
~output=ReducerInterface_InternalExpressionValue.EvtDistribution,
~definitions=[
FnDefinition.make(
~name="mapp",
~inputs=[FRTypeDist, FRTypeLambda], ~inputs=[FRTypeDist, FRTypeLambda],
~run=(inputs, _, env, reducer) => ~run=(inputs, _, env, reducer) =>
switch inputs { switch inputs {
@ -123,7 +166,6 @@ let library = [
~name="map2", ~name="map2",
~inputs=[FRTypeDist, FRTypeDist, FRTypeLambda], ~inputs=[FRTypeDist, FRTypeDist, FRTypeLambda],
~run=(inputs, _, env, reducer) => { ~run=(inputs, _, env, reducer) => {
Js.log2("WHY DIDNT IT MATCH", inputs)
switch inputs { switch inputs {
| [ | [
IEvDistribution(SampleSet(dist1)), IEvDistribution(SampleSet(dist1)),
@ -182,7 +224,7 @@ let library = [
~run=(inputs, _, env, reducer) => ~run=(inputs, _, env, reducer) =>
switch inputs { switch inputs {
| [IEvArray(dists), IEvLambda(lambda)] => | [IEvArray(dists), IEvLambda(lambda)] =>
Internal.mapN(dists, lambda, env, reducer)->E.R2.errMap(_ => "") Internal.mapN(dists, lambda, env, reducer)->E.R2.errMap(e => {Js.log2("HI", e); "AHHH doesn't work"})
| _ => Error(impossibleError) | _ => Error(impossibleError)
}, },
(), (),

View File

@ -34,8 +34,6 @@ PointSet.makeContinuous([
### makeDiscrete ### makeDiscrete
Converts a set of x-y coordinates directly into a discrete distribution.
``` ```
PointSet.makeDiscrete: (list<{x: number, y: number}>) => pointSetDist PointSet.makeDiscrete: (list<{x: number, y: number}>) => pointSetDist
``` ```