mattnedrich/MeanShift_cpp

Issue with Gaussian kernel

Closed this issue · 3 comments

Hi,

thanks for the awesome implementation in c++ that is exactly what I need.
But I have one question regarding the Gaussian kernel. Why is the kernel equal to this?
double temp = exp(- (distance*distance) / (kernel_bandwidth));
which I have changed to following referring to the definition of Gaussian
double temp = exp(- 1.0/2.0 * (distance*distance) / (kernel_bandwidth*kernel_bandwidth));
It is maybe a stupid question but I really want to know which one is correct?

Best regards
Wei

Glad you found my code helpful!

I think your equation is theoretically more correct. However, I don't think it makes much of a difference. The 1/2 is a constant. Squaring kernel_bandwidth will impact how different kernels impact the result, though this is the same as just choosing larger (e.g., squared) kernel_bandwidth values in the first equation.

To clarify what I mean - you can achieve the same result with either equation, however you will need to choose different kernel_bandwidth values. I've seen "Gaussian kernels" written so many different ways. I do appreciate you asking about this though, I suppose I should update my code to match what you have suggested. Feel free to open a pull request to change this if you'd like.

Thanks for your comment 👍

It is true that what the squared kernel really changes, is actually the impact to the result. Just now I have open a pull request - I am not sure if I dit it correctly because it is my first time to make a pull request 💃 If there is any wrong, feel free to contact me :)

Merged it, thanks :)