distToDist and distToFloat
This commit is contained in:
parent
ea5dd219b6
commit
0ded4a404f
|
@ -196,7 +196,7 @@ let sampleNRendered = (n, dist) => {
|
||||||
let operate = (distToFloatOp: Operation.distToFloatOperation, s): float =>
|
let operate = (distToFloatOp: Operation.distToFloatOperation, s): float =>
|
||||||
switch distToFloatOp {
|
switch distToFloatOp {
|
||||||
| #Pdf(f) => pdf(f, s)
|
| #Pdf(f) => pdf(f, s)
|
||||||
| #Cdf(f) => pdf(f, s)
|
| #Cdf(f) => cdf(f, s)
|
||||||
| #Inv(f) => inv(f, s)
|
| #Inv(f) => inv(f, s)
|
||||||
| #Sample => sample(s)
|
| #Sample => sample(s)
|
||||||
| #Mean => T.mean(s)
|
| #Mean => T.mean(s)
|
||||||
|
|
|
@ -1,19 +1,13 @@
|
||||||
type symboliDist = SymbolicDistTypes.symbolicDist;
|
type symboliDist = SymbolicDistTypes.symbolicDist
|
||||||
|
|
||||||
type genericDist = [
|
type genericDist = [
|
||||||
| #XYContinuous(PointSetTypes.continuousShape)
|
| #XYShape(PointSetTypes.pointSetDist)
|
||||||
| #XYDiscrete(Discrete.t)
|
|
||||||
| #SampleSet(array<float>)
|
| #SampleSet(array<float>)
|
||||||
| #Symbolic(symboliDist)
|
| #Symbolic(symboliDist)
|
||||||
| #Error(string)
|
| #Error(string)
|
||||||
|
| #Float(float)
|
||||||
]
|
]
|
||||||
|
|
||||||
let isSymbolic = (r: genericDist) =>
|
|
||||||
switch r {
|
|
||||||
| #Symbolic(_) => true
|
|
||||||
| _ => false
|
|
||||||
}
|
|
||||||
|
|
||||||
type params = {
|
type params = {
|
||||||
sampleCount: int,
|
sampleCount: int,
|
||||||
xyPointLength: int,
|
xyPointLength: int,
|
||||||
|
@ -28,35 +22,58 @@ type wrapped = (genericDist, params)
|
||||||
|
|
||||||
let wrapWithParams = (g: genericDist, f: params): wrapped => (g, f)
|
let wrapWithParams = (g: genericDist, f: params): wrapped => (g, f)
|
||||||
|
|
||||||
let exampleDist: genericDist = #XYDiscrete(
|
let exampleDist: genericDist = #XYShape(
|
||||||
Discrete.make(~integralSumCache=Some(1.0), {xs: [3.0], ys: [1.0]}),
|
Discrete(Discrete.make(~integralSumCache=Some(1.0), {xs: [3.0], ys: [1.0]})),
|
||||||
)
|
)
|
||||||
|
|
||||||
let rec isFunctionPossible = (wrapped: wrapped, fnName): bool => {
|
let defaultSamplingInputs: SamplingInputs.samplingInputs = {
|
||||||
let (v, _) = wrapped
|
sampleCount: 10000,
|
||||||
switch (fnName, v) {
|
outputXYPoints: 10000,
|
||||||
| (#truncateLeft(_), #XYContinuous(_)) => true
|
pointSetDistLength: 1000,
|
||||||
| (#truncateRight(_), #XYContinuous(_)) => true
|
kernelWidth: None,
|
||||||
| _ => false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let rec doFunction = (wrapped: wrapped, fnName): wrapped => {
|
let distToFloat = (wrapped: wrapped, fnName) => {
|
||||||
let (v, extra) = wrapped
|
let (v, extra) = wrapped
|
||||||
let newVal = switch (fnName, v) {
|
let newVal = switch (fnName, v) {
|
||||||
| (#truncateLeft(f), #XYContinuous(r)) => #XYContinuous(Continuous.T.truncate(Some(f), None, r))
|
| (operation, #XYShape(r)) => #Float(PointSetDist.operate(operation, r))
|
||||||
| (#truncateRight(f), #XYContinuous(r)) => #XYContinuous(Continuous.T.truncate(None, Some(f), r))
|
| (operation, #Symbolic(r)) => switch(SymbolicDist.T.operate(operation, r)){
|
||||||
| (#toPointSet, #XYContinuous(r)) => v
|
| Ok(r) => #SymbolicDist(r)
|
||||||
| (#toPointSet, #XYDiscrete(r)) => v
|
| Error(r) => #Error(r)
|
||||||
| (#toPointSet, #Symbolic(#Float(f))) => #XYDiscrete(Discrete.make(~integralSumCache=Some(1.0), {xs: [f], ys: [1.0]}));
|
|
||||||
| (#toPointSet, #Symbolic(r)) => {
|
|
||||||
let xs = SymbolicDist.T.interpolateXs(~xSelection=#ByWeight, r, 1000)
|
|
||||||
let ys = xs |> E.A.fmap(x => SymbolicDist.T.pdf(x, r))
|
|
||||||
#XYContinuous(Continuous.make(~integralSumCache=Some(1.0), {xs: xs, ys: ys}))
|
|
||||||
}
|
}
|
||||||
| _ => #Error("No Match")
|
| _ => #Error("No Match")
|
||||||
}
|
}
|
||||||
(newVal, extra)
|
(newVal, extra)
|
||||||
}
|
}
|
||||||
|
|
||||||
let foo = exampleDist->wrapWithParams(genericParams)->doFunction(#truncateLeft(3.0))
|
let distToDist = (wrapped: wrapped, fnName): wrapped => {
|
||||||
|
let (v, extra) = wrapped
|
||||||
|
let newVal = switch (fnName, v) {
|
||||||
|
| (#normalize, #XYShape(r)) => #XYShape(PointSetDist.T.normalize(r))
|
||||||
|
| (#normalize, #Symbolic(_)) => v
|
||||||
|
| (#normalize, #SampleSet(_)) => v
|
||||||
|
| (#toPointSet, #XYShape(_)) => v
|
||||||
|
| (#toPointSet, #Symbolic(r)) => #XYShape(SymbolicDist.T.toPointSetDist(1000, r))
|
||||||
|
| (#toPointSet, #SampleSet(r)) => {
|
||||||
|
let response = SampleSet.toPointSetDist(
|
||||||
|
~samples=r,
|
||||||
|
~samplingInputs=defaultSamplingInputs,
|
||||||
|
(),
|
||||||
|
).pointSetDist
|
||||||
|
switch response {
|
||||||
|
| Some(r) => #XYShape(r)
|
||||||
|
| None => #Error("Failed to convert sample into shape")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| _ => #Error("No Match")
|
||||||
|
}
|
||||||
|
(newVal, extra)
|
||||||
|
}
|
||||||
|
// | (#truncateLeft(f), #XYContinuous(r)) => #XYContinuous(Continuous.T.truncate(Some(f), None, r))
|
||||||
|
// | (#truncateRight(f), #XYContinuous(r)) => #XYContinuous(Continuous.T.truncate(None, Some(f), r))
|
||||||
|
|
||||||
|
let foo =
|
||||||
|
exampleDist
|
||||||
|
->wrapWithParams(genericParams)
|
||||||
|
->distToDist(#truncateLeft(3.0))
|
||||||
|
->distToDist(#trunctateRight(5.0))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user