Merged recommendedLenght to samplingParams

This commit is contained in:
Ozzie Gooen 2020-07-30 19:27:35 +01:00
parent 79d91bc69a
commit 67828cf789
8 changed files with 20 additions and 40 deletions

View File

@ -149,9 +149,9 @@ module DemoDist = {
sampleCount: Some(options.sampleCount),
outputXYPoints: Some(options.outputXYPoints),
kernelWidth: options.kernelWidth,
shapeLength: Some(options.downsampleTo |> E.O.default(1000))
},
~distPlusIngredients,
~recommendedLength=options.downsampleTo |> E.O.default(1000),
~inputVariables=
[|("p", `SymbolicDist(`Float(1.0)))|]
->Belt.Map.String.fromArray,

View File

@ -392,8 +392,7 @@ module Draw = {
let normal: SymbolicTypes.symbolicDist = `Normal({mean, stdev});
let normalShape =
ExpressionTree.toShape(
numSamples,
{sampleCount: 10000, outputXYPoints: 10000, kernelWidth: None},
{sampleCount: 10000, outputXYPoints: 10000, kernelWidth: None, shapeLength:numSamples},
`SymbolicDist(normal),
) |> E.R.toExn;
let xyShape: Types.xyShape =

View File

@ -1,18 +1,17 @@
open ExpressionTypes.ExpressionTree;
let toLeaf = (intendedShapeLength: int, samplingInputs, node: node) => {
let toLeaf = (samplingInputs, node: node) => {
node
|> ExpressionTreeEvaluator.toLeaf({
samplingInputs,
intendedShapeLength,
evaluateNode: ExpressionTreeEvaluator.toLeaf,
});
};
let toShape = (intendedShapeLength: int, samplingInputs, node: node) => {
let toShape = (samplingInputs, node: node) => {
let renderResult =
`Render(`Normalize(node))
|> toLeaf(intendedShapeLength, samplingInputs);
|> toLeaf(samplingInputs);
switch (renderResult) {
| Ok(`RenderedDist(shape)) => Ok(shape)

View File

@ -279,7 +279,7 @@ module Render = {
| `SymbolicDist(d) =>
Ok(
`RenderedDist(
SymbolicDist.T.toShape(evaluationParams.intendedShapeLength, d),
SymbolicDist.T.toShape(1234, d),
),
)
| `RenderedDist(_) as t => Ok(t) // already a rendered shape, we're done here

View File

@ -28,11 +28,11 @@ module ExpressionTree = {
sampleCount: int,
outputXYPoints: int,
kernelWidth: option(float),
shapeLength: int
};
type evaluationParams = {
samplingInputs,
intendedShapeLength: int,
evaluateNode: (evaluationParams, node) => Belt.Result.t(node, string),
};

View File

@ -1,5 +1,13 @@
// TODO: This setup is more confusing than it should be, there's more work to do in cleanup here.
module Inputs = {
module SamplingInputs = {
type t = {
sampleCount: option(int),
outputXYPoints: option(int),
kernelWidth: option(float),
shapeLength: option(int),
};
};
let defaultRecommendedLength = 10000;
let defaultShouldDownsample = true;
@ -25,20 +33,19 @@ module Inputs = {
};
type inputs = {
distPlusIngredients: ingredients,
samplingInputs: RenderTypes.ShapeRenderer.Sampling.inputs,
recommendedLength: int,
samplingInputs: SamplingInputs.t,
inputVariables: Belt.Map.String.t(ExpressionTypes.ExpressionTree.node),
};
let empty: RenderTypes.ShapeRenderer.Sampling.inputs = {
let empty: SamplingInputs.t = {
sampleCount: None,
outputXYPoints: None,
kernelWidth: None,
shapeLength: None
};
let make =
(
~samplingInputs=empty,
~recommendedLength=defaultRecommendedLength,
~distPlusIngredients,
~inputVariables=[||]->Belt.Map.String.fromArray,
(),
@ -46,15 +53,13 @@ module Inputs = {
: inputs => {
distPlusIngredients,
samplingInputs,
recommendedLength,
inputVariables,
};
};
module Internals = {
type inputs = {
samplingInputs: RenderTypes.ShapeRenderer.Sampling.inputs,
symbolicInputs: RenderTypes.ShapeRenderer.Symbolic.inputs,
samplingInputs: Inputs.SamplingInputs.t,
guesstimatorString: string,
inputVariables: Belt.Map.String.t(ExpressionTypes.ExpressionTree.node),
};
@ -64,9 +69,6 @@ module Internals = {
samplingInputs: inputs.samplingInputs,
guesstimatorString: inputs.distPlusIngredients.guesstimatorString,
inputVariables: inputs.inputVariables,
symbolicInputs: {
length: inputs.recommendedLength,
},
};
};
@ -80,13 +82,13 @@ module Internals = {
MathJsParser.fromString(inputs.guesstimatorString, inputs.inputVariables)
|> E.R.bind(_, g =>
ExpressionTree.toShape(
inputs.symbolicInputs.length,
{
sampleCount:
inputs.samplingInputs.sampleCount |> E.O.default(10000),
outputXYPoints:
inputs.samplingInputs.outputXYPoints |> E.O.default(10000),
kernelWidth: inputs.samplingInputs.kernelWidth,
shapeLength: inputs.samplingInputs.shapeLength |> E.O.default(10000)
},
g,
)

View File

@ -1,19 +0,0 @@
module ShapeRenderer = {
module Sampling = {
type inputs = {
sampleCount: option(int),
outputXYPoints: option(int),
kernelWidth: option(float),
};
let defaults = {
sampleCount: Some(10000),
outputXYPoints: Some(1000),
kernelWidth: None
}
};
module Symbolic = {
type inputs = {length: int};
};
};

View File

@ -21,7 +21,6 @@ let propValue = (t: Prop.Value.t) => {
let newDistribution =
DistPlusRenderer.Inputs.make(
~distPlusIngredients=r,
~recommendedLength=10000,
(),
)
|> DistPlusRenderer.run;