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