Moved out distToFloatOps to better places
This commit is contained in:
parent
101824e500
commit
4663700f67
|
@ -333,12 +333,7 @@ module Continuous = {
|
|||
};
|
||||
|
||||
let combineAlgebraically =
|
||||
(
|
||||
~downsample=false,
|
||||
op: SymbolicTypes.algebraicOperation,
|
||||
t1: t,
|
||||
t2: t,
|
||||
) => {
|
||||
(~downsample=false, op: SymbolicTypes.algebraicOperation, t1: t, t2: t) => {
|
||||
let s1 = t1 |> getShape;
|
||||
let s2 = t2 |> getShape;
|
||||
let t1n = s1 |> XYShape.T.length;
|
||||
|
@ -845,12 +840,7 @@ module Mixed = {
|
|||
});
|
||||
|
||||
let combineAlgebraically =
|
||||
(
|
||||
~downsample=false,
|
||||
op: SymbolicTypes.algebraicOperation,
|
||||
t1: t,
|
||||
t2: t,
|
||||
)
|
||||
(~downsample=false, op: SymbolicTypes.algebraicOperation, t1: t, t2: t)
|
||||
: t => {
|
||||
// Discrete convolution can cause a huge increase in the number of samples,
|
||||
// so we'll first downsample.
|
||||
|
@ -1105,6 +1095,14 @@ module Shape = {
|
|||
| Continuous(m) => Continuous.T.variance(m)
|
||||
};
|
||||
});
|
||||
|
||||
let operate = (distToFloatOp: SymbolicTypes.distToFloatOperation, s) =>
|
||||
switch (distToFloatOp) {
|
||||
| `Pdf(f) => pdf(f, s)
|
||||
| `Inv(f) => inv(f, s)
|
||||
| `Sample => sample(s)
|
||||
| `Mean => T.mean(s)
|
||||
};
|
||||
};
|
||||
|
||||
module DistPlus = {
|
||||
|
|
|
@ -246,6 +246,14 @@ module T = {
|
|||
| `Uniform(n) => Uniform.mean(n)
|
||||
| `Float(n) => Float.mean(n);
|
||||
|
||||
let operate = (distToFloatOp: distToFloatOperation, s) =>
|
||||
switch (distToFloatOp) {
|
||||
| `Pdf(f) => Ok(pdf(f, s))
|
||||
| `Inv(f) => Ok(inv(f, s))
|
||||
| `Sample => Ok(sample(s))
|
||||
| `Mean => mean(s)
|
||||
};
|
||||
|
||||
let interpolateXs =
|
||||
(~xSelection: [ | `Linear | `ByWeight]=`Linear, dist: symbolicDist, n) => {
|
||||
switch (xSelection, dist) {
|
||||
|
|
|
@ -48,6 +48,7 @@ type symbolicDist = [
|
|||
| `Float(float) // Dirac delta at x. Practically useful only in the context of multimodals.
|
||||
];
|
||||
|
||||
// todo: These operations are really applicable for all dists
|
||||
type algebraicOperation = [ | `Add | `Multiply | `Subtract | `Divide];
|
||||
type pointwiseOperation = [ | `Add | `Multiply];
|
||||
type scaleOperation = [ | `Multiply | `Exponentiate | `Log];
|
||||
|
|
|
@ -266,26 +266,14 @@ module TreeNode = {
|
|||
|
||||
module FloatFromDist = {
|
||||
let evaluateFromSymbolic = (distToFloatOp: distToFloatOperation, s) => {
|
||||
let value =
|
||||
switch (distToFloatOp) {
|
||||
| `Pdf(f) => Ok(SymbolicDist.T.pdf(f, s))
|
||||
| `Inv(f) => Ok(SymbolicDist.T.inv(f, s))
|
||||
| `Sample => Ok(SymbolicDist.T.sample(s))
|
||||
| `Mean => SymbolicDist.T.mean(s)
|
||||
};
|
||||
E.R.bind(value, v => Ok(`Leaf(`SymbolicDist(`Float(v)))));
|
||||
SymbolicDist.T.operate(distToFloatOp, s)
|
||||
|> E.R.bind(_, v => Ok(`Leaf(`SymbolicDist(`Float(v)))));
|
||||
};
|
||||
let evaluateFromRenderedDist =
|
||||
(distToFloatOp: distToFloatOperation, rs: DistTypes.shape)
|
||||
: result(treeNode, string) => {
|
||||
let value =
|
||||
switch (distToFloatOp) {
|
||||
| `Pdf(f) => Ok(Distributions.Shape.pdf(f, rs))
|
||||
| `Inv(f) => Ok(Distributions.Shape.inv(f, rs)) // TODO: this is tricky for discrete distributions, because they have a stepwise CDF
|
||||
| `Sample => Ok(Distributions.Shape.sample(rs))
|
||||
| `Mean => Ok(Distributions.Shape.T.mean(rs))
|
||||
};
|
||||
E.R.bind(value, v => Ok(`Leaf(`SymbolicDist(`Float(v)))));
|
||||
Distributions.Shape.operate(distToFloatOp, rs)
|
||||
|> (v => Ok(`Leaf(`SymbolicDist(`Float(v)))));
|
||||
};
|
||||
let rec evaluateToLeaf =
|
||||
(
|
||||
|
|
Loading…
Reference in New Issue
Block a user