Clean up types from Samples.re

This commit is contained in:
Ozzie Gooen 2020-07-30 18:54:31 +01:00
parent d2a17f9f1a
commit 9b7f2f246d
4 changed files with 21 additions and 70 deletions

View File

@ -61,16 +61,10 @@ let combineShapesUsingSampling =
samples
|> E.O.fmap(
Samples.T.fromSamples(
~samplingInputs={
sampleCount:
Some(evaluationParams.samplingInputs.sampleCount),
outputXYPoints:
Some(evaluationParams.samplingInputs.outputXYPoints),
kernelWidth: evaluationParams.samplingInputs.kernelWidth,
},
~samplingInputs=evaluationParams.samplingInputs,
),
)
|> E.O.bind(_, (r) => r.shape)
|> E.O.bind(_, r => r.shape)
|> E.O.toResult("No response");
shape |> E.R.fmap(r => `Normalize(`RenderedDist(r)));
},

View File

@ -1,5 +1,4 @@
// TODO: This setup is more confusing than it should be, there's more work to do in cleanup here.
module Inputs = {
let defaultRecommendedLength = 10000;
let defaultShouldDownsample = true;
@ -30,9 +29,15 @@ module Inputs = {
recommendedLength: int,
inputVariables: Belt.Map.String.t(ExpressionTypes.ExpressionTree.node),
};
let empty: RenderTypes.ShapeRenderer.Sampling.inputs = {
sampleCount: None,
outputXYPoints: None,
kernelWidth: None,
};
let make =
(
~samplingInputs=RenderTypes.ShapeRenderer.Sampling.Inputs.empty,
~samplingInputs=empty,
~recommendedLength=defaultRecommendedLength,
~distPlusIngredients,
~inputVariables=[||]->Belt.Map.String.fromArray,

View File

@ -1,5 +1,3 @@
module MS = Belt.Map.String;
module ShapeRenderer = {
module Sampling = {
type inputs = {
@ -7,27 +5,12 @@ module ShapeRenderer = {
outputXYPoints: option(int),
kernelWidth: option(float),
};
module Inputs = {
let defaultSampleCount = 10000;
let defaultOutputXYPoints = 10000;
let empty = {
sampleCount: None,
outputXYPoints: None,
kernelWidth: None,
};
type fInputs = {
sampleCount: int,
outputXYPoints: int,
kernelWidth: option(float),
};
let toF = (i: inputs): fInputs => {
sampleCount: i.sampleCount |> E.O.default(defaultSampleCount),
outputXYPoints:
i.outputXYPoints |> E.O.default(defaultOutputXYPoints),
kernelWidth: i.kernelWidth,
};
};
let defaults = {
sampleCount: Some(10000),
outputXYPoints: Some(1000),
kernelWidth: None
}
};
module Symbolic = {

View File

@ -1,13 +1,4 @@
module Types = {
let defaultSampleCount = 5000;
let defaultOutputXYPoints = 10000;
type inputs = {
sampleCount: option(int),
outputXYPoints: option(int),
kernelWidth: option(float),
};
type samplingStats = {
sampleCount: int,
outputXYPoints: int,
@ -21,20 +12,6 @@ module Types = {
continuousParseParams: option(samplingStats),
shape: option(DistTypes.shape),
};
let empty = {sampleCount: None, outputXYPoints: None, kernelWidth: None};
type fInputs = {
sampleCount: int,
outputXYPoints: int,
kernelWidth: option(float),
};
let toF = (i: inputs): fInputs => {
sampleCount: i.sampleCount |> E.O.default(defaultSampleCount),
outputXYPoints: i.outputXYPoints |> E.O.default(defaultOutputXYPoints),
kernelWidth: i.kernelWidth,
};
};
module JS = {
@ -112,12 +89,7 @@ module T = {
KDE.normalSampling(samples, outputXYPoints, width);
};
let toShape =
(
~samples: t,
~samplingInputs: Types.fInputs,
(),
) => {
let toShape = (~samples: t, ~samplingInputs: ExpressionTypes.ExpressionTree.samplingInputs, ()) => {
Array.fast_sort(compare, samples);
let (continuousPart, discretePart) = E.A.Sorted.Floats.split(samples);
let length = samples |> E.A.length |> float_of_int;
@ -143,7 +115,7 @@ module T = {
samplingInputs.outputXYPoints,
usedWidth,
);
let foo: Types.samplingStats = {
let samplingStats: Types.samplingStats = {
sampleCount: samplingInputs.sampleCount,
outputXYPoints: samplingInputs.outputXYPoints,
bandwidthXSuggested: _suggestedXWidth,
@ -158,28 +130,25 @@ module T = {
formatUnitWidth(usedUnitWidth),
)
|> Continuous.make
|> (r => Some((r, foo)));
|> (r => Some((r, samplingStats)));
}
: None;
let shape =
MixedShapeBuilder.buildSimple(
~continuous=pdf |> E.O.fmap(fst),
~discrete=Some(discrete),
);
let samplesParse: Types.outputs = {
continuousParseParams: pdf |> E.O.fmap(snd),
shape,
};
samplesParse;
};
let fromSamples =
(
~samplingInputs=Types.empty,
samples,
) => {
let samplingInputs =
Types.toF(samplingInputs);
let fromSamples = (~samplingInputs, samples) => {
toShape(~samples, ~samplingInputs, ());
};
};