Recent

Author Topic: Kernel density estimate  (Read 1626 times)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Kernel density estimate
« on: November 04, 2019, 05:54:43 pm »
I'm looking for 2D kernel density estimation (KDE) code to contour data, but am having no luck finding pascal code.

I'd be grateful if anyone can share a pointer to existing code.

VTwin
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Kernel density estimate
« Reply #1 on: November 04, 2019, 07:19:01 pm »
Hi!

No, nothing in fpc and there seems to be nothing in Turbo Pascal.

In the net you'll find sources for Python, C++, R and mathlab.
But not even pseudocode.

Sorry.

Winni

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Kernel density estimate
« Reply #2 on: November 05, 2019, 01:14:16 am »
Yes, there are a lot of implementations. The MATLAB, R, C++, and Python code I have found have a lot of dependencies and advanced options. I am content to start with a simple "rule of thumb" implementation (Silverman, 1986). I imagine I can figure it out, but was hoping there might be some existing code.
« Last Edit: November 05, 2019, 01:17:30 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: Kernel density estimate
« Reply #3 on: November 05, 2019, 02:58:11 am »
https://en.wikipedia.org/wiki/Kernel_density_estimation
If you look down below there is code....

Is that what you are looking for ?
The only true wisdom is knowing you know nothing

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Kernel density estimate
« Reply #4 on: November 05, 2019, 03:16:27 am »
Yes, that is a good summary of the 1D KDE, although I need a 2D KDE. That was pretty much where I started looking, and I did not find any links there that seemed promising.

I can dig further into some of those links, but the MATLAB and R code is not straightforward (for me) to translate.

ESRI has a decent explanation of their implementation that I could probably code, but it uses a quartic kernel rather than the more common Gaussian kernel. I'm no expert, and just looking for a basic implementation.
« Last Edit: November 05, 2019, 03:33:51 am by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

MathMan

  • Sr. Member
  • ****
  • Posts: 325
Re: Kernel density estimate
« Reply #5 on: November 05, 2019, 08:35:33 am »
Better Wikipedia link is https://en.wikipedia.org/wiki/Multivariate_kernel_density_estimation I think - it also has a link to a a collection of peer-reviewed articles on multivariate KDE math.

If you are not shy of tackling C++ sources then libagf.sf.net (not checked if it still exists) might be a place to look at.

Another one is available here - https://gitlab.com/stochastic-control/StOpt (not checked if it still exists). It relates to arXiv:1712.00993v2 (from Oct 2018, so quite recent at least) which explicitely covers univariate, bivariate and multivariate approaches.

My search also didn't reveal a lot of links to sources and unfortunately none to Pascal.

Cheers,
MathMan
« Last Edit: November 05, 2019, 11:12:19 am by MathMan »

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Kernel density estimate
« Reply #6 on: November 07, 2019, 05:40:56 pm »
Thanks MathMan. I did overlook that page, and it is helpful. I'm generally not shy about using C++ sources, I used it exclusively for a few years, although it is easy to write obtuse code.

libagf is still available on sourceforge with some documentation. I'll see what I can figure out.

Cheers,
VTwin
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

 

TinyPortal © 2005-2018