KernelDensity.fromCallable

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.

class KernelDensity
static
fromCallable
(
C
R...
)
if (
allSatisfy!(isInputRange, R)
)

Examples

1 // Create an estimate of the density of the joint distribution of
2 // hours sleep and programming skill.
3 auto programmingSkill = [8,6,7,5,3,0,9];
4 auto hoursSleep = [3,6,2,4,3,5,8];
5 
6 // Make a 2D Gaussian kernel function with bandwidth 0.5 in both
7 // dimensions and covariance zero.
8 static double myKernel(double x1, double x2) {
9   return normalPDF(x1, 0, 0.5) * normalPDF(x2, 0, 0.5);
10 }
11 
12 auto estimator = KernelDensity.fromCallable
13    (&myKernel, programmingSkill, hoursSleep);
14 
15 // Estimate the density at programming skill 1, 2 hours sleep.
16 auto density = estimator(1, 2);

Meta