Closed skrisna closed 9 years ago
I would like to have a range and guarantee that the function is 0 (dies down) at the boundaires. How can I setup KernelDensity properly to achieve this result?
Short answer: you can't. The problem is that the convolution in KDEs is based on a Fourier transform, which essentially assumes that your domain is periodic: this means you need to pad the extent of each range so that this "wrap-around" effect is small.
What you could do is construct the kde, trim off what you don't want, and put it back together, e.g.:
X = rand(10)
r = linrange(-1.0,2.0,1024)
# construct "padded" kde
k = kde(X,r)
# lower and upper indices
i,j = searchsortedfirst(r,0), searchsortedlast(r,1)
# construct trimmed kde object
k2 = UnivariateKDE(k.x[i:j],k.density[i:j])
That is great. Thanks for the exposition and the padding suggestion.
I am not sure if this is an issue but I am having a hard time understanding the behavior of KernelDensity so please feel free to close it if it is not really an issue.
I am trying to get KernelDensity to work using range. This is what I did-
kr = kde_range((0.0,1.0),2048) k1 = kde(H1,kr) k0 = kde(H0,kr)
This function behaves properly except at the boundaries-![screenclip](https://cloud.githubusercontent.com/assets/2131842/7026423/934b0b36-dd17-11e4-9674-fc97e0dcafef.png)
When I do not use the range parameter, things seem to die down at the boundaries but the boundaries extend beyond the range I am interested in.![screenclip](https://cloud.githubusercontent.com/assets/2131842/7026482/e61cd100-dd17-11e4-8fc4-0dd231b5f773.png)
I would like to have a range and guarantee that the function is 0 (dies down) at the boundaires. How can I setup KernelDensity properly to achieve this result?