Making KernelDensity.pdf interface consistent with Distributions.pdf #122
+0
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This solves issue #120 as well as implements functionality of PR #102, but for any dimension, not only 2D matrices as in #102.
There is one breaking change:
pdf(k::UnivariateKDE, v::AbstractVector)becomes undefined andpdf(k::InterpolateKDE, v::AbstractVector)now tries to calculatepdfat multi-dimensional pointvinstead of treatingvas a collection of 1D points. I am open to discussion but I am afraid the old version is unsalvageable. There is no such method in Distributions.jl and the existence of it conflicts with implementing pdf methods for multi-dimensional KDEs. The same functionality is now available usingpdf.(k, xs)as in Distributions.I left methods
pdf(k2d::BivariateKDE, x,y)andpdf(k::UnivariateKDE, xs, ys)which do not have Distributions equivalents, but are mostly harmless.Turning on broadcast is just line 15 in KernelDensity.jl file which turns all KDE objects into scalars. But, broadcast was dysfunctional in that state because there was no constant propagation, so the efficiency was atrocious. (I am not completely sure why, but it my be because functors from Interpolation.jl have custom broadcast.) The proposed solution is to extend custom broadcast to
pdftoo, interp.jl line 37, where it gets redirected to Interpolations functor broadcast. Now calculating pdf for multiple datapoints is actually even a litte faster than before.This is supposed to be a small PR only with changes absolutely necessary to fix the interface. But there are additional changes which can be made to clear the situation more:
InterpKDEtype unfortunately does not contain information about the dimension the KDE is in, so we cannot write dimension-specific methods and errors caused by inconsistent dimensions look horrible. This can be fixed leaving the interfaceInterpKDEbut making internal typeInterpKDE{N}or something similar.kde(M::Matrix), i.e. that the datapoints are rows. Alas, inDistributionsdatapoints are columns, inpdfmethod too. MakingKernelDensity.pdfact on rows would be insane, so we are left with very uncomfortable situation wherekdeandpdfmethods have contradictory interface. I do not fix this because that would be another breaking change.