Auto-kernel-width

This commit is contained in:
Ozzie Gooen 2020-04-03 14:32:14 +01:00
parent 5ad426f4a9
commit 145452d50f
3 changed files with 13 additions and 4 deletions

View File

@ -60,8 +60,8 @@
"react-use": "^13.27.0", "react-use": "^13.27.0",
"reason-react": ">=0.7.0", "reason-react": ">=0.7.0",
"reschema": "1.3.0", "reschema": "1.3.0",
"tailwindcss": "1.2.0", "science": "^1.9.3",
"science": "1.9.3" "tailwindcss": "1.2.0"
}, },
"alias": { "alias": {
"react": "./node_modules/react", "react": "./node_modules/react",

View File

@ -88,6 +88,15 @@ module T = {
(continuous, discrete); (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. // todo: Figure out some way of doing this without having to integrate so many times.
let toShape = (~samples: t, ~outputXYPoints=3000, ~kernelWidth=10, ()) => { let toShape = (~samples: t, ~outputXYPoints=3000, ~kernelWidth=10, ()) => {
Array.fast_sort(compare, samples); Array.fast_sort(compare, samples);
@ -102,7 +111,7 @@ module T = {
let pdf: DistTypes.xyShape = let pdf: DistTypes.xyShape =
continuousPart |> E.A.length > 5 continuousPart |> E.A.length > 5
? { ? {
continuousPart |> KDE.normalSampling(_, outputXYPoints, kernelWidth); continuousPart |> kde(~samples=_, ~outputXYPoints)
} }
: {xs: [||], ys: [||]}; : {xs: [||], ys: [||]};
let continuous = pdf |> Distributions.Continuous.make(`Linear); let continuous = pdf |> Distributions.Continuous.make(`Linear);

View File

@ -8579,7 +8579,7 @@ scheduler@^0.19.0:
loose-envify "^1.1.0" loose-envify "^1.1.0"
object-assign "^4.1.1" object-assign "^4.1.1"
science@1.9.3: science@^1.9.3:
version "1.9.3" version "1.9.3"
resolved "https://registry.yarnpkg.com/science/-/science-1.9.3.tgz#ec89bac44aeff2e5a2d749aa496f377089903dd4" resolved "https://registry.yarnpkg.com/science/-/science-1.9.3.tgz#ec89bac44aeff2e5a2d749aa496f377089903dd4"
integrity sha1-7Im6xErv8uWi10mqSW83cImQPdQ= integrity sha1-7Im6xErv8uWi10mqSW83cImQPdQ=