Kernel density estimators for Julia.
The main accessor function is
U = kde(data)
will construct a
UnivariateKDE object from the real vector
optional keyword arguments are
boundary: the lower and upper limits of the kde as a tuple. Due to the fourier transforms used internally, there should be sufficient spacing to prevent wrap-around at the boundaries.
npoints: the number of interpolation points to use. The function uses fast Fourier transforms (FFTs) internally, so for optimal efficiency this should be a power of 2 (default = 2048).
kernel: the distributional family from Distributions.jl to use as the kernel (default =
Normal). To add your own kernel, extend the internal
bandwidth: the bandwidth of the kernel. Default is to use Silverman's rule.
U contains gridded coordinates (
U.x) and the density
U.density). These are typically sufficient for plotting.
A related function
will construct a
UnivariateKDE object, with the bandwidth selected by
least-squares cross validation. It accepts the above keyword arguments, except
There are also some slightly more advanced interfaces:
kde(data, midpoints::R) where R<:AbstractRange
allows specifying the internal grid to use. Optional keyword arguments are
allows specifying the exact distribution to use as the kernel. Optional
keyword arguments are
kde(data, midpoints::R, dist::Distribution) where R<:AbstractRange
allows specifying both the distribution and grid.
The usage mirrors that of the univariate case, except that
data is now
either a tuple of vectors
B = kde((xdata, ydata))
or a matrix with two columns
B = kde(datamatrix)
Similarly, the optional arguments all now take tuple arguments:
boundary now takes a tuple of tuples
B contains gridded coordinates (
B.y) and the bivariate density
The KDE objects are stored as gridded density values, with attached
coordinates. These are typically sufficient for plotting (see above), but
intermediate values can be interpolated using the
Interpolations.jl package via the
pdf(k::UnivariateKDE, x) pdf(k::BivariateKDE, x, y)
y are real numbers or arrays.
If you are making multiple calls to
InterpKDE to store the interpolation structure:
ik = InterpKDE(k) pdf(ik, x)
InterpKDE will pass any extra arguments to
24 days ago