// Create an estimate of the density of the joint distribution of // hours sleep and programming skill. auto programmingSkill = [8,6,7,5,3,0,9]; auto hoursSleep = [3,6,2,4,3,5,8]; // Make a 2D Gaussian kernel function with bandwidth 0.5 in both // dimensions and covariance zero. static double myKernel(double x1, double x2) { return normalPDF(x1, 0, 0.5) * normalPDF(x2, 0, 0.5); } auto estimator = KernelDensity.fromCallable (&myKernel, programmingSkill, hoursSleep); // Estimate the density at programming skill 1, 2 hours sleep. auto density = estimator(1, 2);
Construct a kernel density estimator from a kernel provided as a callable object (such as a function pointer, delegate, or class with overloaded opCall). R must be either a range of ranges, multiple ranges passed in as variadic arguments, or a single range for the 1D case. Each range represents the values of one variable in the joint distribution. kernel must accept either an array of doubles or the same number of arguments as the number of dimensions, and must return a floating point number.