2022-07-16 21:01:00 +00:00
|
|
|
open FunctionRegistry_Core
|
|
|
|
open FunctionRegistry_Helpers
|
|
|
|
|
2022-07-21 15:54:41 +00:00
|
|
|
let nameSpace = "PointSet"
|
2022-07-16 21:01:00 +00:00
|
|
|
let requiresNamespace = true
|
|
|
|
|
|
|
|
let inputsTodist = (inputs: array<FunctionRegistry_Core.frValue>, makeDist) => {
|
|
|
|
let array = inputs->getOrError(0)->E.R.bind(Prepare.ToValueArray.Array.openA)
|
|
|
|
let xyCoords =
|
|
|
|
array->E.R.bind(xyCoords =>
|
|
|
|
xyCoords
|
|
|
|
->E.A2.fmap(xyCoord =>
|
|
|
|
[xyCoord]->Prepare.ToValueArray.Record.twoArgs->E.R.bind(Prepare.ToValueTuple.twoNumbers)
|
|
|
|
)
|
|
|
|
->E.A.R.firstErrorOrOpen
|
|
|
|
)
|
|
|
|
let expressionValue =
|
|
|
|
xyCoords
|
|
|
|
->E.R.bind(r => r->XYShape.T.makeFromZipped->E.R2.errMap(XYShape.Error.toString))
|
|
|
|
->E.R2.fmap(r => ReducerInterface_InternalExpressionValue.IEvDistribution(
|
|
|
|
PointSet(makeDist(r)),
|
|
|
|
))
|
|
|
|
expressionValue
|
|
|
|
}
|
|
|
|
|
|
|
|
let library = [
|
2022-07-21 15:54:41 +00:00
|
|
|
Function.make(
|
|
|
|
~name="fromDist",
|
|
|
|
~nameSpace,
|
|
|
|
~requiresNamespace=true,
|
|
|
|
~examples=[`PointSet.fromDist(normal(5,2))`],
|
|
|
|
~output=ReducerInterface_InternalExpressionValue.EvtDistribution,
|
|
|
|
~definitions=[
|
|
|
|
FnDefinition.make(
|
|
|
|
~name="fromDist",
|
|
|
|
~inputs=[FRTypeDist],
|
2022-07-25 14:34:33 +00:00
|
|
|
~run=(_, inputs, accessors, _) =>
|
2022-07-21 15:54:41 +00:00
|
|
|
switch inputs {
|
|
|
|
| [FRValueDist(dist)] =>
|
|
|
|
GenericDist.toPointSet(
|
|
|
|
dist,
|
2022-07-25 14:34:33 +00:00
|
|
|
~xyPointLength=accessors.environment.xyPointLength,
|
|
|
|
~sampleCount=accessors.environment.sampleCount,
|
2022-07-21 15:54:41 +00:00
|
|
|
(),
|
|
|
|
)
|
|
|
|
->E.R2.fmap(Wrappers.pointSet)
|
|
|
|
->E.R2.fmap(Wrappers.evDistribution)
|
|
|
|
->E.R2.errMap(_ => "")
|
|
|
|
| _ => Error(impossibleError)
|
|
|
|
},
|
|
|
|
(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
(),
|
|
|
|
),
|
2022-07-16 21:01:00 +00:00
|
|
|
Function.make(
|
|
|
|
~name="makeContinuous",
|
|
|
|
~nameSpace,
|
2022-07-17 01:11:38 +00:00
|
|
|
~requiresNamespace,
|
2022-07-18 15:24:11 +00:00
|
|
|
~examples=[
|
2022-07-21 15:54:41 +00:00
|
|
|
`PointSet.makeContinuous([
|
2022-07-18 15:24:11 +00:00
|
|
|
{x: 0, y: 0.2},
|
|
|
|
{x: 1, y: 0.7},
|
|
|
|
{x: 2, y: 0.8},
|
|
|
|
{x: 3, y: 0.2}
|
|
|
|
])`,
|
|
|
|
],
|
|
|
|
~output=ReducerInterface_InternalExpressionValue.EvtDistribution,
|
2022-07-16 21:01:00 +00:00
|
|
|
~definitions=[
|
|
|
|
FnDefinition.make(
|
|
|
|
~name="makeContinuous",
|
|
|
|
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
|
2022-07-19 15:42:08 +00:00
|
|
|
~run=(_, inputs, _, _) => inputsTodist(inputs, r => Continuous(Continuous.make(r))),
|
2022-07-16 21:01:00 +00:00
|
|
|
(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
(),
|
|
|
|
),
|
|
|
|
Function.make(
|
|
|
|
~name="makeDiscrete",
|
|
|
|
~nameSpace,
|
2022-07-17 01:11:38 +00:00
|
|
|
~requiresNamespace,
|
2022-07-18 15:24:11 +00:00
|
|
|
~examples=[
|
2022-07-21 15:54:41 +00:00
|
|
|
`PointSet.makeDiscrete([
|
2022-07-18 15:24:11 +00:00
|
|
|
{x: 0, y: 0.2},
|
|
|
|
{x: 1, y: 0.7},
|
|
|
|
{x: 2, y: 0.8},
|
|
|
|
{x: 3, y: 0.2}
|
|
|
|
])`,
|
|
|
|
],
|
|
|
|
~output=ReducerInterface_InternalExpressionValue.EvtDistribution,
|
2022-07-16 21:01:00 +00:00
|
|
|
~definitions=[
|
|
|
|
FnDefinition.make(
|
|
|
|
~name="makeDiscrete",
|
|
|
|
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
|
2022-07-19 15:42:08 +00:00
|
|
|
~run=(_, inputs, _, _) => inputsTodist(inputs, r => Discrete(Discrete.make(r))),
|
2022-07-16 21:01:00 +00:00
|
|
|
(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
(),
|
|
|
|
),
|
|
|
|
]
|