Start of refactor to directly tie to pdfast
This commit is contained in:
parent
88d54d4de9
commit
b4b9f2cc9f
|
@ -52,6 +52,7 @@
|
||||||
"moment": "2.24.0",
|
"moment": "2.24.0",
|
||||||
"parcel-bundler": "1.12.4",
|
"parcel-bundler": "1.12.4",
|
||||||
"parcel-plugin-less-js-enabled": "1.0.2",
|
"parcel-plugin-less-js-enabled": "1.0.2",
|
||||||
|
"pdfast": "^0.2.0",
|
||||||
"postcss-cli": "7.1.0",
|
"postcss-cli": "7.1.0",
|
||||||
"rationale": "0.2.0",
|
"rationale": "0.2.0",
|
||||||
"react": "16.12.0",
|
"react": "16.12.0",
|
||||||
|
|
|
@ -157,9 +157,9 @@ let make = () => {
|
||||||
unitType: "UnspecifiedDistribution",
|
unitType: "UnspecifiedDistribution",
|
||||||
zero: MomentRe.momentNow(),
|
zero: MomentRe.momentNow(),
|
||||||
unit: "days",
|
unit: "days",
|
||||||
sampleCount: "10000",
|
sampleCount: "1000",
|
||||||
outputXYPoints: "5000",
|
outputXYPoints: "1000",
|
||||||
truncateTo: "1000",
|
truncateTo: "500",
|
||||||
},
|
},
|
||||||
(),
|
(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -16,6 +16,13 @@ let toDistPlus =
|
||||||
t: distPlusIngredients,
|
t: distPlusIngredients,
|
||||||
)
|
)
|
||||||
: option(distPlus) => {
|
: option(distPlus) => {
|
||||||
|
let test =
|
||||||
|
Guesstimator.toMixed(
|
||||||
|
t.guesstimatorString,
|
||||||
|
sampleCount,
|
||||||
|
outputXYPoints,
|
||||||
|
30,
|
||||||
|
);
|
||||||
let shape =
|
let shape =
|
||||||
Guesstimator.stringToMixedShape(
|
Guesstimator.stringToMixedShape(
|
||||||
~string=t.guesstimatorString,
|
~string=t.guesstimatorString,
|
||||||
|
|
|
@ -61,6 +61,8 @@ module T = {
|
||||||
let xMap = (fn, t: t): t => {xs: E.A.fmap(fn, t.xs), ys: t.ys};
|
let xMap = (fn, t: t): t => {xs: E.A.fmap(fn, t.xs), ys: t.ys};
|
||||||
let fromArray = ((xs, ys)): t => {xs, ys};
|
let fromArray = ((xs, ys)): t => {xs, ys};
|
||||||
let fromArrays = (xs, ys): t => {xs, ys};
|
let fromArrays = (xs, ys): t => {xs, ys};
|
||||||
|
let fromZippedArray = (is: array((float, float))): t =>
|
||||||
|
is |> Belt.Array.unzip |> fromArray;
|
||||||
|
|
||||||
module Combine = {
|
module Combine = {
|
||||||
let combineLinear = (t1: t, t2: t, fn: (float, float) => float) => {
|
let combineLinear = (t1: t, t2: t, fn: (float, float) => float) => {
|
||||||
|
|
|
@ -32,7 +32,8 @@ module Internals = {
|
||||||
external stringToSamples: (string, int) => array(float) = "stringToSamples";
|
external stringToSamples: (string, int) => array(float) = "stringToSamples";
|
||||||
|
|
||||||
[@bs.module "./GuesstimatorLibrary.js"]
|
[@bs.module "./GuesstimatorLibrary.js"]
|
||||||
external samplesToContinuousPdf: (array(float), int, int) => array(float) =
|
external samplesToContinuousPdf:
|
||||||
|
(array(float), int, int) => CdfLibrary.JS.distJs =
|
||||||
"samplesToContinuousPdf";
|
"samplesToContinuousPdf";
|
||||||
|
|
||||||
// todo: Format to correct mass, also normalize the pdf.
|
// todo: Format to correct mass, also normalize the pdf.
|
||||||
|
@ -67,3 +68,30 @@ let stringToMixedShape =
|
||||||
) =>
|
) =>
|
||||||
Internals.toCombinedFormat(string, sampleCount, outputXYPoints, width)
|
Internals.toCombinedFormat(string, sampleCount, outputXYPoints, width)
|
||||||
|> Internals.toMixedShape(~truncateTo);
|
|> Internals.toMixedShape(~truncateTo);
|
||||||
|
|
||||||
|
let toMixed = (string, sampleCount, returnLength, width) => {
|
||||||
|
let samples = Internals.stringToSamples(string, sampleCount);
|
||||||
|
let length = samples |> E.A.length;
|
||||||
|
Array.sort(compare, samples);
|
||||||
|
let items =
|
||||||
|
E.A.uniq(samples)
|
||||||
|
|> E.A.fmap(r => (r, samples |> E.A.filter(n => n == r) |> E.A.length));
|
||||||
|
let (discretePart, continuousPart) =
|
||||||
|
Belt.Array.partition(items, ((_, count)) => count > 1);
|
||||||
|
let discrete: DistTypes.xyShape =
|
||||||
|
discretePart
|
||||||
|
|> E.A.fmap(((x, count)) =>
|
||||||
|
(x, float_of_int(count) /. float_of_int(length))
|
||||||
|
)
|
||||||
|
|> XYShape.T.fromZippedArray;
|
||||||
|
let pdf: DistTypes.xyShape =
|
||||||
|
continuousPart |> E.A.length > 20
|
||||||
|
? {
|
||||||
|
Internals.samplesToContinuousPdf(samples, returnLength, width)
|
||||||
|
|> CdfLibrary.JS.jsToDist;
|
||||||
|
}
|
||||||
|
: {xs: [||], ys: [||]};
|
||||||
|
let continuous = pdf |> Distributions.Continuous.fromShape;
|
||||||
|
let shape = MixedShapeBuilder.buildSimple(~continuous, ~discrete);
|
||||||
|
shape;
|
||||||
|
};
|
|
@ -3,6 +3,7 @@ const {
|
||||||
} = require("@foretold/cdf/lib/samples");
|
} = require("@foretold/cdf/lib/samples");
|
||||||
const _ = require("lodash");
|
const _ = require("lodash");
|
||||||
const { Guesstimator } = require('@foretold/guesstimator/src');
|
const { Guesstimator } = require('@foretold/guesstimator/src');
|
||||||
|
const pdfast = require('pdfast');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param values
|
* @param values
|
||||||
|
@ -89,10 +90,7 @@ const stringToSamples = (
|
||||||
sampleCount,
|
sampleCount,
|
||||||
inputs = [],
|
inputs = [],
|
||||||
) => {
|
) => {
|
||||||
const [_error, item] = Guesstimator.parse({ text });
|
const [_error, item] = Guesstimator.parse({ text:"=" + text });
|
||||||
if (_error){
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
const { parsedInput } = item;
|
const { parsedInput } = item;
|
||||||
|
|
||||||
const guesstimator = new Guesstimator({ parsedInput });
|
const guesstimator = new Guesstimator({ parsedInput });
|
||||||
|
@ -106,15 +104,16 @@ const stringToSamples = (
|
||||||
|
|
||||||
const samplesToContinuousPdf = (
|
const samplesToContinuousPdf = (
|
||||||
samples,
|
samples,
|
||||||
outputResolutionCount,
|
size,
|
||||||
width,
|
width,
|
||||||
min = false,
|
min = false,
|
||||||
max = false,
|
max = false,
|
||||||
) => {
|
) => {
|
||||||
const values = _.filter(samples, _.isFinite);
|
let _samples = _.filter(samples, _.isFinite);
|
||||||
const _samples = new Samples(values);
|
if (_.isFinite(min)) { _samples = _.filter(_samples, r => r > min) };
|
||||||
const pdf = _samples.toPdf({ size: outputResolutionCount, width, min, max });
|
if (_.isFinite(max)) { _samples = _.filter(_samples, r => r < max) };
|
||||||
return pdf;
|
let pdf = pdfast.create(_samples, { size, width });
|
||||||
|
return {xs: pdf.map(r => r.x), ys: pdf.map(r => r.x)};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
@ -7570,7 +7570,7 @@ pbkdf2@^3.0.3:
|
||||||
safe-buffer "^5.0.1"
|
safe-buffer "^5.0.1"
|
||||||
sha.js "^2.4.8"
|
sha.js "^2.4.8"
|
||||||
|
|
||||||
pdfast@0.2.0:
|
pdfast@0.2.0, pdfast@^0.2.0:
|
||||||
version "0.2.0"
|
version "0.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/pdfast/-/pdfast-0.2.0.tgz#8cbc556e1bf2522177787c0de2e0d4373ba885c9"
|
resolved "https://registry.yarnpkg.com/pdfast/-/pdfast-0.2.0.tgz#8cbc556e1bf2522177787c0de2e0d4373ba885c9"
|
||||||
integrity sha1-jLxVbhvyUiF3eHwN4uDUNzuohck=
|
integrity sha1-jLxVbhvyUiF3eHwN4uDUNzuohck=
|
||||||
|
|
Loading…
Reference in New Issue
Block a user