tommyod / KDEpy

Kernel Density Estimation in Python
https://kdepy.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
584 stars 90 forks source link

updated silvermans_rule to work with multidimensional data #166

Open bean217 opened 8 months ago

bean217 commented 8 months ago

silvermans_rule algorithm is essentially the same, but with some handling for multidimensional data thrown in there. Also wrote some tests for checking the shape of the output.

tommyod commented 8 months ago

Do you have a reference for the correctness of taking Silverman's rule in each dimension as you currently do?

In one dimension, the width of a kernel is a single number. In two dimensions it is three numbers: the two diagonals of the covariance matrix and the off diagonal element. If you compute the 1D Silverman estimate along each dimension, then you do not account for correlations between the variables.

Have you thought about this? Have you looked at the literature?

I fear that generalizing Silermans rule to higher dimensions is not as easy as your current code sketch makes it out to be (?).

bean217 commented 8 months ago

I apologize for my extremely naive implementation. I had made some pretty terrible assumptions, so I'm going to actually read up on this some more rather than continuing to submit something incorrect.

tommyod commented 8 months ago

No worries, have a look at it! If you manage to figure it out it can improve the library.