@data-ui/histogram
Version:
React + d3 library for creating histograms
25 lines (22 loc) • 676 B
JavaScript
;
exports.__esModule = true;
exports.default = kernelDensityEstimator;
var _d3Array = require("d3-array");
/*
* Kernel density estimator factory which takes a kernel function and input bins
* as input config and returns a function that takes values of a random variable
* as input and estimates its probability density function
* code from https://gist.github.com/mbostock/4341954
*/
function kernelDensityEstimator(kernel, bins) {
return function (values) {
return bins.map(function (bin) {
return {
bin: bin,
value: (0, _d3Array.mean)(values, function (v) {
return kernel(bin - v);
})
};
});
};
}