The OpenD Programming Language

KernelDensity1D.fromCallable

Construct a kernel density estimation object from a callable object. R must be a range of numeric types. C must be a kernel function, delegate, or class or struct with overloaded opCall. The kernel function is assumed to be symmetric about zero, to take its maximum value at zero and to be unimodal.

edgeBuffer determines how much space below and above the smallest and largest observed value will be allocated when doing the binning. Values less than reduce!min(range) - edgeBuffer or greater than reduce!max(range) + edgeBuffer will be assigned a density of zero. If this value is left at its default, it will be set to a value at which the kernel is somewhere between 1e-3 and 1e-4 times its value at zero.

The bandwidth of the kernel is indirectly selected by parametrizing the kernel function.

class KernelDensity1D
static
fromCallable
(
C
R
)
(
scope C kernel
,,
double edgeBuffer = double.nan
)
if (
is(typeof(kernel(2.0)) : double)
)

Examples

auto randNums = randArray!rNormal(1_000, 0, 1);
auto kernel = parametrize!normalPDF(0, 0.01);
auto density = KernelDensity1D(kernel, randNums);
writeln(normalPDF(1, 0, 1), "  ", density(1)).  // Should be about the same.

Meta