No description
Find a file
Chancy Kennedy b88fd362d8 add usage
2024-12-19 11:07:10 -06:00
.github/workflows remove docs action 2024-12-19 11:02:29 -06:00
src unused import 2024-12-19 10:51:19 -06:00
tests add basic test 2024-12-18 23:47:56 -06:00
.gitignore Initial commit 2024-12-18 18:36:57 -06:00
derichekde.nimble change to BSD-3-Clause to match original uwdata/fast-kde 2024-12-19 10:56:36 -06:00
LICENSE change to BSD-3-Clause to match original uwdata/fast-kde 2024-12-19 10:56:36 -06:00
README.md add usage 2024-12-19 11:07:10 -06:00

About

This code is a port of a port of a port, but it seems to work. If anyone that actually understands the math wants to takeover this codebase, please let me know.

The Deriche filter is an order-K approximation of the Gaussian kernel, which is combined with linear binning to produce a fast and accurate implementation of KDE. The naive KDE algorithm is O(n^2), while this implementation is O(n+m) wherem is the number of bins.

Usage

import derichekde

var data = @[1.2, 2.3, 23, 40, 50, 60, 70, 60, 50, 400, 700, 1000]
let (densities, lo, hi) = density_1d(data)

# The default bin size is 512, pass bins to change.
doAssert densities.len == 512

lo and hi are the minimum and maximum values in the data with a padding if extent is not provided.

Pass bandwidth to change the smoothness of the curve.

References

This code is a port of this Python implementation of the Deriche approximation KDE algorithm found here: https://github.com/liuzh-buaa/fast_kde

Which is itself a port of Javascript implementation... which was the implementation of a paper that was based on a port of the Deriche computer vision kernel implemented in C by Getreuer.

The original Javascript implementation is here: https://github.com/uwdata/fast-kde

The paper on the implementation for KDE can be found here: https://idl.uw.edu/papers/fast-kde