Repository navigation
ENH: add asymmetric kernels for kde and cdf, for unit interval and R+ - #7364
Conversation
|
Hello @josef-pkt! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-03-12 18:54:41 UTC |
|
(pep-8, whitespace and line breaks) currently these are just basic function do compute kernel pdf or kernel cdf, taking mean over sample points instead of mean, we need also
update compared to MultivariateKDE
my current functions have all three steps, for univariate case |
|
This pull request introduces 1 alert when merging d707f4e into 5ce985f - view on LGTM.com new alerts:
|
d707f4e to
152397f
Compare
|
amended and force pushed, pep-8 cleaning and adding invgamma kernel (beta2 had flake/lint problems, I didn't run it yet.) |
|
aside: it looks to me like matplotlib hist for cumulative histogram uses the wrong step type
alternative for plotting would be to use some plotting position to get better agreement, i.e. theoretical cdf is somewhere in the middle of the steps of the ecdf, i.e. intersecting instead of touching at jump points. another alternative: plot cdf with linear interpolated of edge points, which would correspond to piecewise constant histogram distribution. example with kernel_cdf_beta2 (not yet in this PR, I wasn't sure boundary corrected kernels can be directly used for cdf) update |
|
notebook checking all kernels for R+: (current branch needs bug fixes for cdf, and missing cdf) |
152397f to
079b5d2
Compare
|
vectorized evaluation for different new x points is still unverified. I only checked initially a gamma example. |
|
adding rvs based on kernel estimate
sample size of original data: 1000 another one after creating more random numbers so seed changes |
|
one more variation: binned data, just using np.histogram for binning continued example, original gamma rvs with nobs=1000. converted to histogram with 50 bins center are bin centers based on np.hist edges
|
|
Ok, I will strip averaging code out of the functions, so that they have only the kernel definitions (similar to kernels for MultivariateKDE). If I want averaging options, then I would have to add them to each function with a lot of code duplication. This way access is through wrapper function that computes weighted average based on a kernel function. Also I want to add a batch loop, for evaluating vector x (prediction points), inside the wrapper function, so looping doesn't use more function calls than in the current version. |
|
That's about as far as I want to get here, for now. (batch loop and doc strings are still missing) open question:
There is no input validation, e.g. no check that points are in support of distributions/kernels |
|
now includes batch loop I refactored unit tests: |
|
should be finished now, except I haven't copied references to each docstring yet. |
|
I had a quick look at It looks like Birnbaum–Saunders, inverse Gaussian, and reciprocal inverse Gaussian kernel require that f(0) = 0 and goes fast enough to zero as x -> 0. (related to exponential versus power tails if I interpret Stephens on transformation of random variables correctly) AFAIR, f(0) = 0 is assumed by most/all kernels except gamma. I'm not sure which kernels can have f(0) = c with c > 0 and finite. |
1c0fb4a to
8e79ba1
Compare
|
I cleaned up docstrings, amended and force pushed should be finished and ready to merge |
|
aside: I don't like the order of arguments in the kernels for MultivariateKDE, so the signature here is not compatible with those. Otherwise, it should be possible to plug the asymmetric kernels into MultivariateKDE |
8e79ba1 to
60a6441
Compare
|
updated gist to correspond to current interface |




see #7346
nonparametric kernel estimation for density and cdf based on asymmetric kernels
kernels are based on the corresponding scipy distribution
for unit interval:
for R+:
Status:
currently only checked visually using kde plots for gamma random sample (nobs=1000), plots look good,
(invgauss is not so good, also weak performance in some references)
update unit test check that average mean squared error AMSE is small.
I followed parameterization of original articles, but I might want to make them more consistent between them.
no extras, especially no bandwidth defaults or selection