diff --git a/package.json b/package.json index 6d5c6342..332492fa 100644 --- a/package.json +++ b/package.json @@ -60,8 +60,8 @@ "react-use": "^13.27.0", "reason-react": ">=0.7.0", "reschema": "1.3.0", - "tailwindcss": "1.2.0", - "science": "1.9.3" + "science": "^1.9.3", + "tailwindcss": "1.2.0" }, "alias": { "react": "./node_modules/react", diff --git a/src/Samples.re b/src/Samples.re index 8ccd178c..d7f3b5d2 100644 --- a/src/Samples.re +++ b/src/Samples.re @@ -88,6 +88,15 @@ module T = { (continuous, discrete); }; + let kde = (~samples, ~outputXYPoints) => { + let width = Science.nrd0(samples); + let xyPointRange = E.A.Sorted.range(samples) |> E.O.default(0.0); + let xyPointWidth = xyPointRange /. float_of_int(outputXYPoints); + let kernelWidth = int_of_float(Jstat.max([|(width /. xyPointWidth), 1.0 |])); + Js.log4(samples, width, xyPointWidth, kernelWidth); + KDE.normalSampling(samples, outputXYPoints, kernelWidth); + }; + // todo: Figure out some way of doing this without having to integrate so many times. let toShape = (~samples: t, ~outputXYPoints=3000, ~kernelWidth=10, ()) => { Array.fast_sort(compare, samples); @@ -102,7 +111,7 @@ module T = { let pdf: DistTypes.xyShape = continuousPart |> E.A.length > 5 ? { - continuousPart |> KDE.normalSampling(_, outputXYPoints, kernelWidth); + continuousPart |> kde(~samples=_, ~outputXYPoints) } : {xs: [||], ys: [||]}; let continuous = pdf |> Distributions.Continuous.make(`Linear); diff --git a/yarn.lock b/yarn.lock index 01e751af..b3c000da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8579,7 +8579,7 @@ scheduler@^0.19.0: loose-envify "^1.1.0" object-assign "^4.1.1" -science@1.9.3: +science@^1.9.3: version "1.9.3" resolved "https://registry.yarnpkg.com/science/-/science-1.9.3.tgz#ec89bac44aeff2e5a2d749aa496f377089903dd4" integrity sha1-7Im6xErv8uWi10mqSW83cImQPdQ=