User Guide¶
Exact one-dimensional KDE¶
"""Fit and evaluate an exact one-dimensional KDE."""
import numpy as np
from kern import KernelDensity
rng = np.random.default_rng(0)
data = rng.normal(size=1_000)
points = np.linspace(-3.0, 3.0, 200)
model = KernelDensity(bandwidth=0.25, kernel="gaussian").fit(data)
density = model.evaluate(points)
print(density[:5])
Approximate KDE¶
kern.ApproximateKernelDensity sorts training samples once during
fit. A distance cutoff and optional neighbor limit reduce the number of
kernel evaluations.
For Gaussian kernels, fast_gaussian=True uses Schraudolph’s exponential
approximation [Schraudolph 1999].
memory="high" uses per-thread partial sums for symmetric self-KDE and can
cache external cutoff bounds. memory="low" avoids those buffers.
memory="auto" chooses based on the workload.
Bounded KDE¶
kern.BoundedKernelDensity supports reflected standard kernels and a
sample-centered Beta kernel for samples on [0, 1]. The reflected method
uses the reflection construction for support constraints
[Schuster 1985].
Set method=None to use the same regular unbounded estimator behavior
through the bounded estimator class.
Multivariate KDE¶
kern.MultivariateKernelDensity uses blocked product-kernel evaluation.
The block_size parameter controls how many query rows reuse each data
block.