Removed continuousShape from SymbolicDist
This commit is contained in:
parent
366523ce80
commit
892f0a0b25
|
@ -231,7 +231,7 @@ module T =
|
||||||
Continuous.T.Integral.sum(~cache=None, continuous);
|
Continuous.T.Integral.sum(~cache=None, continuous);
|
||||||
let totalIntegralSum = discreteIntegralSum +. continuousIntegralSum;
|
let totalIntegralSum = discreteIntegralSum +. continuousIntegralSum;
|
||||||
|
|
||||||
let getMeanOfSquares = ({discrete, continuous} as t: t) => {
|
let getMeanOfSquares = ({discrete, continuous}: t) => {
|
||||||
let discreteMean =
|
let discreteMean =
|
||||||
discrete
|
discrete
|
||||||
|> Discrete.shapeMap(XYShape.Analysis.squareXYShape)
|
|> Discrete.shapeMap(XYShape.Analysis.squareXYShape)
|
||||||
|
|
|
@ -204,32 +204,32 @@ module MathAdtToDistDst = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
let arrayParser =
|
// let arrayParser =
|
||||||
(args: array(arg))
|
// (args: array(arg))
|
||||||
: result(ExpressionTypes.ExpressionTree.node, string) => {
|
// : result(ExpressionTypes.ExpressionTree.node, string) => {
|
||||||
let samples =
|
// let samples =
|
||||||
args
|
// args
|
||||||
|> E.A.fmap(
|
// |> E.A.fmap(
|
||||||
fun
|
// fun
|
||||||
| Value(n) => Some(n)
|
// | Value(n) => Some(n)
|
||||||
| _ => None,
|
// | _ => None,
|
||||||
)
|
// )
|
||||||
|> E.A.O.concatSomes;
|
// |> E.A.O.concatSomes;
|
||||||
let outputs = Samples.T.fromSamples(samples);
|
// let outputs = Samples.T.fromSamples(samples);
|
||||||
let pdf =
|
// let pdf =
|
||||||
outputs.shape |> E.O.bind(_, Shape.T.toContinuous);
|
// outputs.shape |> E.O.bind(_, Shape.T.toContinuous);
|
||||||
let shape =
|
// let shape =
|
||||||
pdf
|
// pdf
|
||||||
|> E.O.fmap(pdf => {
|
// |> E.O.fmap(pdf => {
|
||||||
let _pdf = Continuous.T.normalize(pdf);
|
// let _pdf = Continuous.T.normalize(pdf);
|
||||||
let cdf = Continuous.T.integral(~cache=None, _pdf);
|
// let cdf = Continuous.T.integral(~cache=None, _pdf);
|
||||||
SymbolicDist.ContinuousShape.make(_pdf, cdf);
|
// SymbolicDist.ContinuousShape.make(_pdf, cdf);
|
||||||
});
|
// });
|
||||||
switch (shape) {
|
// switch (shape) {
|
||||||
| Some(s) => Ok(`SymbolicDist(`ContinuousShape(s)))
|
// | Some(s) => Ok(`SymbolicDist(`ContinuousShape(s)))
|
||||||
| None => Error("Rendering did not work")
|
// | None => Error("Rendering did not work")
|
||||||
};
|
// };
|
||||||
};
|
// };
|
||||||
|
|
||||||
let operationParser =
|
let operationParser =
|
||||||
(
|
(
|
||||||
|
@ -335,9 +335,9 @@ module MathAdtToDistDst = {
|
||||||
|
|
||||||
let topLevel =
|
let topLevel =
|
||||||
fun
|
fun
|
||||||
| Array(r) => arrayParser(r)
|
|
||||||
| Value(_) as r => nodeParser(r)
|
| Value(_) as r => nodeParser(r)
|
||||||
| Fn(_) as r => nodeParser(r)
|
| Fn(_) as r => nodeParser(r)
|
||||||
|
| Array(_) => Error("Array not valid as top level")
|
||||||
| Symbol(_) => Error("Symbol not valid as top level")
|
| Symbol(_) => Error("Symbol not valid as top level")
|
||||||
| Object(_) => Error("Object not valid as top level");
|
| Object(_) => Error("Object not valid as top level");
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,5 @@
|
||||||
open SymbolicTypes;
|
open SymbolicTypes;
|
||||||
|
|
||||||
module ContinuousShape = {
|
|
||||||
type t = continuousShape;
|
|
||||||
let make = (pdf, cdf): t => {pdf, cdf};
|
|
||||||
let pdf = (x, t: t) =>
|
|
||||||
Continuous.T.xToY(x, t.pdf).continuous;
|
|
||||||
// TODO: pdf and inv are currently the same, this seems broken.
|
|
||||||
let inv = (p, t: t) =>
|
|
||||||
Continuous.T.xToY(p, t.pdf).continuous;
|
|
||||||
// TODO: Fix the sampling, to have it work correctly.
|
|
||||||
let sample = (t: t) => 3.0;
|
|
||||||
// TODO: Fix the mean, to have it work correctly.
|
|
||||||
let mean = (t: t) => Ok(0.0);
|
|
||||||
let toString = t => {j|CustomContinuousShape|j};
|
|
||||||
};
|
|
||||||
|
|
||||||
module Exponential = {
|
module Exponential = {
|
||||||
type t = exponential;
|
type t = exponential;
|
||||||
let pdf = (x, t: t) => Jstat.exponential##pdf(x, t.rate);
|
let pdf = (x, t: t) => Jstat.exponential##pdf(x, t.rate);
|
||||||
|
@ -170,7 +155,6 @@ module T = {
|
||||||
| `Uniform(n) => Uniform.pdf(x, n)
|
| `Uniform(n) => Uniform.pdf(x, n)
|
||||||
| `Beta(n) => Beta.pdf(x, n)
|
| `Beta(n) => Beta.pdf(x, n)
|
||||||
| `Float(n) => Float.pdf(x, n)
|
| `Float(n) => Float.pdf(x, n)
|
||||||
| `ContinuousShape(n) => ContinuousShape.pdf(x, n)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let inv = (x, dist) =>
|
let inv = (x, dist) =>
|
||||||
|
@ -183,7 +167,6 @@ module T = {
|
||||||
| `Uniform(n) => Uniform.inv(x, n)
|
| `Uniform(n) => Uniform.inv(x, n)
|
||||||
| `Beta(n) => Beta.inv(x, n)
|
| `Beta(n) => Beta.inv(x, n)
|
||||||
| `Float(n) => Float.inv(x, n)
|
| `Float(n) => Float.inv(x, n)
|
||||||
| `ContinuousShape(n) => ContinuousShape.inv(x, n)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let sample: symbolicDist => float =
|
let sample: symbolicDist => float =
|
||||||
|
@ -196,7 +179,6 @@ module T = {
|
||||||
| `Uniform(n) => Uniform.sample(n)
|
| `Uniform(n) => Uniform.sample(n)
|
||||||
| `Beta(n) => Beta.sample(n)
|
| `Beta(n) => Beta.sample(n)
|
||||||
| `Float(n) => Float.sample(n)
|
| `Float(n) => Float.sample(n)
|
||||||
| `ContinuousShape(n) => ContinuousShape.sample(n);
|
|
||||||
|
|
||||||
let toString: symbolicDist => string =
|
let toString: symbolicDist => string =
|
||||||
fun
|
fun
|
||||||
|
@ -208,7 +190,6 @@ module T = {
|
||||||
| `Uniform(n) => Uniform.toString(n)
|
| `Uniform(n) => Uniform.toString(n)
|
||||||
| `Beta(n) => Beta.toString(n)
|
| `Beta(n) => Beta.toString(n)
|
||||||
| `Float(n) => Float.toString(n)
|
| `Float(n) => Float.toString(n)
|
||||||
| `ContinuousShape(n) => ContinuousShape.toString(n);
|
|
||||||
|
|
||||||
let min: symbolicDist => float =
|
let min: symbolicDist => float =
|
||||||
fun
|
fun
|
||||||
|
@ -219,7 +200,6 @@ module T = {
|
||||||
| `Lognormal(n) => Lognormal.inv(minCdfValue, n)
|
| `Lognormal(n) => Lognormal.inv(minCdfValue, n)
|
||||||
| `Uniform({low}) => low
|
| `Uniform({low}) => low
|
||||||
| `Beta(n) => Beta.inv(minCdfValue, n)
|
| `Beta(n) => Beta.inv(minCdfValue, n)
|
||||||
| `ContinuousShape(n) => ContinuousShape.inv(minCdfValue, n)
|
|
||||||
| `Float(n) => n;
|
| `Float(n) => n;
|
||||||
|
|
||||||
let max: symbolicDist => float =
|
let max: symbolicDist => float =
|
||||||
|
@ -230,7 +210,6 @@ module T = {
|
||||||
| `Normal(n) => Normal.inv(maxCdfValue, n)
|
| `Normal(n) => Normal.inv(maxCdfValue, n)
|
||||||
| `Lognormal(n) => Lognormal.inv(maxCdfValue, n)
|
| `Lognormal(n) => Lognormal.inv(maxCdfValue, n)
|
||||||
| `Beta(n) => Beta.inv(maxCdfValue, n)
|
| `Beta(n) => Beta.inv(maxCdfValue, n)
|
||||||
| `ContinuousShape(n) => ContinuousShape.inv(maxCdfValue, n)
|
|
||||||
| `Uniform({high}) => high
|
| `Uniform({high}) => high
|
||||||
| `Float(n) => n;
|
| `Float(n) => n;
|
||||||
|
|
||||||
|
@ -242,7 +221,6 @@ module T = {
|
||||||
| `Normal(n) => Normal.mean(n)
|
| `Normal(n) => Normal.mean(n)
|
||||||
| `Lognormal(n) => Lognormal.mean(n)
|
| `Lognormal(n) => Lognormal.mean(n)
|
||||||
| `Beta(n) => Beta.mean(n)
|
| `Beta(n) => Beta.mean(n)
|
||||||
| `ContinuousShape(n) => ContinuousShape.mean(n)
|
|
||||||
| `Uniform(n) => Uniform.mean(n)
|
| `Uniform(n) => Uniform.mean(n)
|
||||||
| `Float(n) => Float.mean(n);
|
| `Float(n) => Float.mean(n);
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,6 @@ type triangular = {
|
||||||
high: float,
|
high: float,
|
||||||
};
|
};
|
||||||
|
|
||||||
type continuousShape = {
|
|
||||||
pdf: DistTypes.continuousShape,
|
|
||||||
cdf: DistTypes.continuousShape,
|
|
||||||
};
|
|
||||||
|
|
||||||
type symbolicDist = [
|
type symbolicDist = [
|
||||||
| `Normal(normal)
|
| `Normal(normal)
|
||||||
| `Beta(beta)
|
| `Beta(beta)
|
||||||
|
@ -44,7 +39,6 @@ type symbolicDist = [
|
||||||
| `Exponential(exponential)
|
| `Exponential(exponential)
|
||||||
| `Cauchy(cauchy)
|
| `Cauchy(cauchy)
|
||||||
| `Triangular(triangular)
|
| `Triangular(triangular)
|
||||||
| `ContinuousShape(continuousShape)
|
|
||||||
| `Float(float) // Dirac delta at x. Practically useful only in the context of multimodals.
|
| `Float(float) // Dirac delta at x. Practically useful only in the context of multimodals.
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user