Start of refactor for toPointSetDist
This commit is contained in:
parent
61aaca3e2f
commit
fa3d874a4e
|
@ -64,22 +64,17 @@ let toPointSet = (
|
||||||
switch (t: t) {
|
switch (t: t) {
|
||||||
| PointSet(pointSet) => Ok(pointSet)
|
| PointSet(pointSet) => Ok(pointSet)
|
||||||
| Symbolic(r) => Ok(SymbolicDist.T.toPointSetDist(~xSelection, xyPointLength, r))
|
| Symbolic(r) => Ok(SymbolicDist.T.toPointSetDist(~xSelection, xyPointLength, r))
|
||||||
| SampleSet(r) => {
|
| SampleSet(r) =>
|
||||||
let response = SampleSetDist.toPointSetDist(
|
SampleSetDist.toPointSetDist2(
|
||||||
~samples=r,
|
~samples=r,
|
||||||
~samplingInputs={
|
~samplingInputs={
|
||||||
sampleCount: sampleCount,
|
sampleCount: sampleCount,
|
||||||
outputXYPoints: xyPointLength,
|
outputXYPoints: xyPointLength,
|
||||||
pointSetDistLength: xyPointLength,
|
pointSetDistLength: xyPointLength,
|
||||||
kernelWidth: None,
|
kernelWidth: None,
|
||||||
},
|
},
|
||||||
(),
|
(),
|
||||||
).pointSetDist
|
)->mapStringErrors
|
||||||
switch response {
|
|
||||||
| Some(r) => Ok(r)
|
|
||||||
| None => Error(Other("Converting sampleSet to pointSet failed"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,8 +165,7 @@ module AlgebraicCombination = {
|
||||||
) => {
|
) => {
|
||||||
let arithmeticOperation = Operation.Algebraic.toFn(arithmeticOperation)
|
let arithmeticOperation = Operation.Algebraic.toFn(arithmeticOperation)
|
||||||
E.R.merge(toSampleSet(t1), toSampleSet(t2))->E.R.bind(((a, b)) => {
|
E.R.merge(toSampleSet(t1), toSampleSet(t2))->E.R.bind(((a, b)) => {
|
||||||
SampleSetDist.runMonteCarlo(arithmeticOperation, a, b)
|
SampleSetDist.map2(~fn=arithmeticOperation, ~t1=a, ~t2=b)->mapStringErrors
|
||||||
->mapStringErrors
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,15 @@ module T: {
|
||||||
|
|
||||||
include T
|
include T
|
||||||
|
|
||||||
// TODO: Refactor to raise correct error when not enough samples
|
let length = (t:t) => get(t) |> E.A.length;
|
||||||
|
|
||||||
|
// TODO: Refactor to raise correct error when not enough samples
|
||||||
let toPointSetDist = (~samples: t, ~samplingInputs: SamplingInputs.samplingInputs, ()) =>
|
let toPointSetDist = (~samples: t, ~samplingInputs: SamplingInputs.samplingInputs, ()) =>
|
||||||
SampleSetDist_ToPointSet.toPointSetDist(~samples=get(samples), ~samplingInputs, ())
|
SampleSetDist_ToPointSet.toPointSetDist(~samples=get(samples), ~samplingInputs, ())
|
||||||
|
|
||||||
|
let toPointSetDist2 = (~samples: t, ~samplingInputs: SamplingInputs.samplingInputs, ()) =>
|
||||||
|
SampleSetDist_ToPointSet.toPointSetDist(~samples=get(samples), ~samplingInputs, ()).pointSetDist |> E.O.toResult("Failed to convert to PointSetDist")
|
||||||
|
|
||||||
//Randomly get one sample from the distribution
|
//Randomly get one sample from the distribution
|
||||||
let sample = (t: t): float => {
|
let sample = (t: t): float => {
|
||||||
let i = E.Int.random(~min=0, ~max=E.A.length(get(t)) - 1)
|
let i = E.Int.random(~min=0, ~max=E.A.length(get(t)) - 1)
|
||||||
|
@ -42,7 +46,8 @@ let sampleN = (t: t, n) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let runMonteCarlo = (fn: (float, float) => float, t1: t, t2: t) => {
|
//TODO: Figure out what to do if distributions are different lengths. ``zip`` is kind of inelegant for this.
|
||||||
|
let map2 = (~fn: (float, float) => float, ~t1: t, ~t2: t) => {
|
||||||
let samples = Belt.Array.zip(get(t1), get(t2))->E.A2.fmap(((a, b)) => fn(a, b))
|
let samples = Belt.Array.zip(get(t1), get(t2))->E.A2.fmap(((a, b)) => fn(a, b))
|
||||||
make(samples)
|
make(samples)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user