Add Epanechnikov kernel function for particle distribution management#6913
Add Epanechnikov kernel function for particle distribution management#6913JarettBakerDunn wants to merge 1 commit intogeodynamics:mainfrom
Conversation
| { | ||
| if (distance < bandwidth) | ||
| { | ||
| return std::max((0.75)*(bandwidth-(distance*distance))/bandwidth,0.0); |
There was a problem hiding this comment.
Shouldnt this be:
| return std::max((0.75)*(bandwidth-(distance*distance))/bandwidth,0.0); | |
| return 0.75*(1.0-(distance*distance)/(bandwidth*bandwidth)); |
(i.e. you currently divide only once by bandwidth, but it should be divided by bandwidth squared)
you shouldnt need the std::max, because your if condition should catch the case distance >= bandwidth, which is the only case the function value can become negative.
There was a problem hiding this comment.
I am testing out these edits to the function, and the epanechnikov function still performs worse than cutoff-c1.
I think you are right about changing from bandwidth - distance^2, to 1.0-distance^2 since the distance value is already normalized.
This makes me realize that I also need to change the triangular function, since it is currently using bandwidth-distance. Actually, changing the triangular function to 1.0-distance makes it score worse, but it is more accurate to what the function should actually be doing.
Further, I think that the uniform kernel function currently returns a value of 1 any time that the distance is less than the bandwidth, but I think that if the distance is already normalized, the uniform function should return a value of 1.0 any time that the distance is less than 1.0?
What is the reasoning for dividing by bandwidth*bandwidth instead of just bandwidth?
There was a problem hiding this comment.
This makes me realize that I also need to change the triangular function, since it is currently using bandwidth-distance.
But for the triangular function it doesnt make a difference since: (bandwidth-distance) / distance == 1 - (bandwidth / distance). It only matters for the Epanechnikov kernel, because it uses distance^2.
What is the reasoning for dividing by bandwidth*bandwidth instead of just bandwidth?
Well, my thinking was this: We are using bandwidth to change the support of the (already non-dimensionalized) distance. So in essence we are replacing distance by distance/bandwidth as independent variable u for the kernel evaluation. So if the Epanechnikov kernel is defined as 0.75 * (1 - u^2) then after substitution this becomes 0.75 * (1 - (distance / bandwidth) * (distance / bandwidth)). Or did I miss something?
This pull request adds an Epanechnikov kernel function to be used to handle particle distribution.
The Epanechnikov kernel function is described here on Wikipedia. Interestingly although Wikipedia describes the Epanechnikov function as the most efficient kernel function, it does not seem to perform better than the deal.ii cosine function for this application. This makes me wonder if my implementation of the Epanechnikov has some problems.