Merge pull request #599 from quantified-uncertainty/toPointSet-fn
This commit is contained in:
commit
793c42ce20
|
@ -33,6 +33,7 @@
|
|||
"from": {
|
||||
"data": "con"
|
||||
},
|
||||
"interpolate": "linear",
|
||||
"encode": {
|
||||
"update": {
|
||||
"x": {
|
||||
|
@ -51,7 +52,7 @@
|
|||
"value": "#4C78A8"
|
||||
},
|
||||
"interpolate": {
|
||||
"value": "monotone"
|
||||
"value": "linear"
|
||||
},
|
||||
"fillOpacity": {
|
||||
"value": 1
|
||||
|
|
|
@ -231,9 +231,8 @@ let doN = (n, fn) => {
|
|||
}
|
||||
|
||||
let sample = (t: t): float => {
|
||||
let randomItem = Random.float(1.)
|
||||
let bar = t |> T.Integral.yToX(randomItem)
|
||||
bar
|
||||
let randomItem = Random.float(1.0)
|
||||
t |> T.Integral.yToX(randomItem)
|
||||
}
|
||||
|
||||
let isFloat = (t: t) =>
|
||||
|
|
|
@ -9,6 +9,7 @@ module Wrappers = {
|
|||
}
|
||||
|
||||
module Prepare = {
|
||||
type t = frValue
|
||||
type ts = array<frValue>
|
||||
type err = string
|
||||
|
||||
|
@ -26,6 +27,14 @@ module Prepare = {
|
|||
| _ => Error(impossibleError)
|
||||
}
|
||||
}
|
||||
|
||||
module Array = {
|
||||
let openA = (inputs: t): result<ts, err> =>
|
||||
switch inputs {
|
||||
| FRValueArray(n) => Ok(n)
|
||||
| _ => Error(impossibleError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module ToValueTuple = {
|
||||
|
@ -55,6 +64,19 @@ module Prepare = {
|
|||
values->ToValueArray.Record.twoArgs->E.R.bind(twoDistOrNumber)
|
||||
}
|
||||
}
|
||||
|
||||
module ToArrayRecordPairs = {
|
||||
let twoArgs = (input: t): result<array<ts>, err> => {
|
||||
let array = input->ToValueArray.Array.openA
|
||||
let pairs =
|
||||
array->E.R.bind(pairs =>
|
||||
pairs
|
||||
->E.A2.fmap(xyCoord => [xyCoord]->ToValueArray.Record.twoArgs)
|
||||
->E.A.R.firstErrorOrOpen
|
||||
)
|
||||
pairs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module Process = {
|
||||
|
|
|
@ -30,9 +30,46 @@ module Declaration = {
|
|||
}
|
||||
}
|
||||
|
||||
let inputsTodist = (inputs: array<FunctionRegistry_Core.frValue>, makeDist) => {
|
||||
let array = inputs->E.A.unsafe_get(0)->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_ExpressionValue.EvDistribution(PointSet(makeDist(r))))
|
||||
expressionValue
|
||||
}
|
||||
|
||||
let registry = [
|
||||
Function.make(
|
||||
~name="FnMake",
|
||||
~name="toContinuousPointSet",
|
||||
~definitions=[
|
||||
FnDefinition.make(
|
||||
~name="toContinuousPointSet",
|
||||
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
|
||||
~run=(inputs, _) => inputsTodist(inputs, r => Continuous(Continuous.make(r))),
|
||||
),
|
||||
],
|
||||
),
|
||||
Function.make(
|
||||
~name="toDiscretePointSet",
|
||||
~definitions=[
|
||||
FnDefinition.make(
|
||||
~name="toDiscretePointSet",
|
||||
~inputs=[FRTypeArray(FRTypeRecord([("x", FRTypeNumeric), ("y", FRTypeNumeric)]))],
|
||||
~run=(inputs, _) => inputsTodist(inputs, r => Discrete(Discrete.make(r))),
|
||||
),
|
||||
],
|
||||
),
|
||||
Function.make(
|
||||
~name="Declaration",
|
||||
~definitions=[
|
||||
FnDefinition.make(~name="declareFn", ~inputs=[Declaration.frType], ~run=(inputs, _) => {
|
||||
inputs->E.A.unsafe_get(0)->Declaration.fromExpressionValue
|
||||
|
|
|
@ -571,6 +571,7 @@ module A = {
|
|||
let tail = Belt.Array.sliceToEnd(_, 1)
|
||||
|
||||
let zip = Belt.Array.zip
|
||||
let unzip = Belt.Array.unzip
|
||||
let zip3 = (a, b, c) =>
|
||||
Belt.Array.zip(a, b)->Belt.Array.zip(c)->Belt.Array.map((((v1, v2), v3)) => (v1, v2, v3))
|
||||
// This zips while taking the longest elements of each array.
|
||||
|
|
|
@ -148,6 +148,11 @@ module T = {
|
|||
| None => Ok(attempt)
|
||||
}
|
||||
}
|
||||
|
||||
let makeFromZipped = (values: array<(float, float)>) => {
|
||||
let (xs, ys) = E.A.unzip(values)
|
||||
make(~xs, ~ys)
|
||||
}
|
||||
}
|
||||
|
||||
module Ts = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user