Giter Site home page Giter Site logo

kerneldensity.jl's Introduction

KernelDensity.jl

CI Coverage Status

Kernel density estimators for Julia.

Usage

Univariate

The main accessor function is kde:

U = kde(data)

will construct a UnivariateKDE object from the real vector data. The optional keyword arguments are

  • boundary: the lower and upper limits of the kde as a tuple. Due to the fourier transforms used internally, there should be sufficient spacing to prevent wrap-around at the boundaries.
  • npoints: the number of interpolation points to use. The function uses fast Fourier transforms (FFTs) internally, so for optimal efficiency this should be a power of 2 (default = 2048).
  • kernel: the distributional family from Distributions.jl to use as the kernel (default = Normal). To add your own kernel, extend the internal kernel_dist function.
  • bandwidth: the bandwidth of the kernel. Default is to use Silverman's rule.

The UnivariateKDE object U contains gridded coordinates (U.x) and the density estimate (U.density). These are typically sufficient for plotting. A related function

kde_lscv(data)

will construct a UnivariateKDE object, with the bandwidth selected by least-squares cross validation. It accepts the above keyword arguments, except bandwidth.

There are also some slightly more advanced interfaces:

kde(data, midpoints::R) where R<:AbstractRange

allows specifying the internal grid to use. Optional keyword arguments are kernel and bandwidth.

kde(data, dist::Distribution)

allows specifying the exact distribution to use as the kernel. Optional keyword arguments are boundary and npoints.

kde(data, midpoints::R, dist::Distribution) where R<:AbstractRange

allows specifying both the distribution and grid.

Bivariate

The usage mirrors that of the univariate case, except that data is now either a tuple of vectors

B = kde((xdata, ydata))

or a matrix with two columns

B = kde(datamatrix)

Similarly, the optional arguments all now take tuple arguments: e.g. boundary now takes a tuple of tuples ((xlo,xhi),(ylo,yhi)).

The BivariateKDE object B contains gridded coordinates (B.x and B.y) and the bivariate density estimate (B.density).

Interpolation

The KDE objects are stored as gridded density values, with attached coordinates. These are typically sufficient for plotting (see above), but intermediate values can be interpolated using the Interpolations.jl package via the pdf method (extended from Distributions.jl).

pdf(k::UnivariateKDE, x)
pdf(k::BivariateKDE, x, y)

where x and y are real numbers or arrays.

If you are making multiple calls to pdf, it will be more efficient to construct an intermediate InterpKDE to store the interpolation structure:

ik = InterpKDE(k)
pdf(ik, x)

InterpKDE will pass any extra arguments to interpolate.

kerneldensity.jl's People

Contributors

andreasnoack avatar ararslan avatar awllee avatar axsk avatar chriselrod avatar davidanthoff avatar dehann avatar devmotion avatar femtocleaner[bot] avatar github-actions[bot] avatar iainnz avatar jaksle avatar jltastet avatar juliatagbot avatar palday avatar panlanfeng avatar paulsoderlind avatar piever avatar pkofod avatar ranjanan avatar simonbyrne avatar t-bltg avatar tkelman avatar tlnagy avatar tpapp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kerneldensity.jl's Issues

Plotting error

I am having trouble reproducing the first plot in the ijulia notebook for PyPlot. I ran:

using PyPlot
using Distributions
using KernelDensity

plot(kde(X))

I get the following error message:

PyError (:PyObject_Call) <class 'TypeError'>
TypeError("float() argument must be a string or a number, not 'PyCall.jlwrap'",)
  File "C:\Python\Anaconda3\lib\site-packages\matplotlib\pyplot.py", line 3099, in plot
    ret = ax.plot(*args, **kwargs)
  File "C:\Python\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 1374, in plot
    self.add_line(line)
  File "C:\Python\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 1504, in add_line
    self._update_line_limits(line)
  File "C:\Python\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 1515, in _update_line_limits
    path = line.get_path()
  File "C:\Python\Anaconda3\lib\site-packages\matplotlib\lines.py", line 874, in get_path
    self.recache()
  File "C:\Python\Anaconda3\lib\site-packages\matplotlib\lines.py", line 584, in recache
    y = np.asarray(yconv, np.float_)
  File "C:\Python\Anaconda3\lib\site-packages\numpy\core\numeric.py", line 462, in asarray
    return array(a, dtype, copy=False, order=order)

 [inlined code] from C:\Users\lucab\.julia\v0.4\PyCall\src\exception.jl:81
 in pycall at C:\Users\lucab\.julia\v0.4\PyCall\src\PyCall.jl:344
 in plot at C:\Users\lucab\.julia\v0.4\PyPlot\src\PyPlot.jl:460
 in include_string at loading.jl:272
 in eval at C:\Users\lucab\.julia\v0.4\Atom\src\Atom.jl:3
 [inlined code] from C:\Users\lucab\.julia\v0.4\Atom\src\eval.jl:39
 in anonymous at C:\Users\lucab\.julia\v0.4\Atom\src\eval.jl:108
 in withpath at C:\Users\lucab\.julia\v0.4\Requires\src\require.jl:37
 in withpath at C:\Users\lucab\.julia\v0.4\Atom\src\eval.jl:53
 [inlined code] from C:\Users\lucab\.julia\v0.4\Atom\src\eval.jl:107
 in anonymous at task.jl:58

I'm running Julia 0.4.3 and Python 3.4.3. The packages are up to date. Do you know what I'm doing wrong?

Midpoints boundserror

I'm not sure if this is a bug or intentional, but when specifying the midpoints argument i get a boundserror when the ranges do not cover the maximum value in the input vectors.

As an example:

x = [rand(1.0:10000.0) for i = 1:10000]
y = [rand(1.0:10.0) for i = 1:10000]

test1 = kde((x,y),(1:10000,0:10))

Works fine, and so does:

x = [rand(1.0:10000.0) for i = 1:10000]
y = [rand(1.0:10.0) for i = 1:10000]

test2 = kde((x,y), (1:10000,4:10))

However if I do the following I get a boundserror.

x = [rand(1.0:10000.0) for i = 1:10000]
y = [rand(1.0:10.0) for i = 1:10000]

test3 = kde((x,y), (1:10000,4:9))

No plotting examples in Readme

While the plotting is easy, I think there should be a short example and a mention that StatPlots should be used in the Readme file.

Grid.jl is deprecated, causes breakage on v0.6

julia> using KernelDensity
ERROR: LoadError: LoadError: MethodError: no method matching Union(::Type{Distributions.Laplace}, ::Type{Distributions.Logistic}, ::Type{Distributions.SymTriangularDist})
Closest candidates are:
  Union{T}(::Any) at sysimg.jl:53
 in include_from_node1(::String) at ./loading.jl:426
 in include_from_node1(::String) at /Users/tamasnagy/Downloads/julia/usr/lib/julia/sys.dylib:?
 in include_from_node1(::String) at ./loading.jl:426
 in include_from_node1(::String) at /Users/tamasnagy/Downloads/julia/usr/lib/julia/sys.dylib:?
 in eval(::Module, ::Any) at ./boot.jl:234
 in eval(::Module, ::Any) at /Users/tamasnagy/Downloads/julia/usr/lib/julia/sys.dylib:?
 in require(::Symbol) at ./loading.jl:357
 in require(::Symbol) at /Users/tamasnagy/Downloads/julia/usr/lib/julia/sys.dylib:?
while loading /Users/tamasnagy/.julia/v0.6/KernelDensity/src/univariate.jl, in expression starting on line 11
while loading /Users/tamasnagy/.julia/v0.6/KernelDensity/src/KernelDensity.jl, in expression starting on line 12

julia> versioninfo()
Julia Version 0.6.0-dev.376
Commit 2390055 (2016-08-23 16:14 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin15.6.0)
  CPU: Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, haswell)

julia> Pkg.installed("KernelDensity")
v"0.0.2"

Pkg.test() on Julia 0.5.0 fails (Mac)

julia> Pkg.test("KernelDensity")
INFO: Testing KernelDensity
Running tests:
 * univariate.jl
ERROR: LoadError: LoadError: ArgumentError: Normal: the condition σ > zero(σ) is not satisfied.
 in macro expansion at /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/pkgs-0.5.0.4/v0.5/Distributions/src/utils.jl:6 [inlined]
 in Type at /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/pkgs-0.5.0.4/v0.5/Distributions/src/univariate/continuous/normal.jl:28 [inlined]
 in Type at /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/pkgs-0.5.0.4/v0.5/Distributions/src/univariate/continuous/normal.jl:32 [inlined]
 in kernel_dist(::Type{Distributions.Normal}, ::Float64) at /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/pkgs-0.5.0.4/v0.5/KernelDensity/src/univariate.jl:8
 in #kde_lscv#4(::Type{T}, ::Tuple{Float64,Float64}, ::Function, ::Array{Float64,1}, ::FloatRange{Float64}) at /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/pkgs-0.5.0.4/v0.5/KernelDensity/src/univariate.jl:178
 in (::KernelDensity.#kw##kde_lscv)(::Array{Any,1}, ::KernelDensity.#kde_lscv, ::Array{Float64,1}, ::FloatRange{Float64}) at ./<missing>:0
 in #kde_lscv#7(::Tuple{Float64,Float64}, ::Int64, ::Type{T}, ::Tuple{Float64,Float64}, ::Function, ::Array{Float64,1}) at /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/pkgs-0.5.0.4/v0.5/KernelDensity/src/univariate.jl:200
 in macro expansion; at /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/pkgs-0.5.0.4/v0.5/KernelDensity/test/univariate.jl:50 [inlined]
 in anonymous at ./<missing>:?
 in include_from_node1(::String) at ./loading.jl:488
 in include_from_node1(::String) at /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/julia/Contents/Resources/julia/lib/julia/sys.dylib:?
 in macro expansion; at /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/pkgs-0.5.0.4/v0.5/KernelDensity/test/runtests.jl:12 [inlined]
 in anonymous at ./<missing>:?
 in include_from_node1(::String) at ./loading.jl:488
 in include_from_node1(::String) at /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/julia/Contents/Resources/julia/lib/julia/sys.dylib:?
 in process_options(::Base.JLOptions) at ./client.jl:262
 in _start() at ./client.jl:318
 in _start() at /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/julia/Contents/Resources/julia/lib/julia/sys.dylib:?
while loading /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/pkgs-0.5.0.4/v0.5/KernelDensity/test/univariate.jl, in expression starting on line 17
while loading /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/pkgs-0.5.0.4/v0.5/KernelDensity/test/runtests.jl, in expression starting on line 9
====================================================================[ ERROR: KernelDensity ]=====================================================================

failed process: Process(`/Applications/JuliaPro-0.5.0.4.app/Contents/Resources/julia/Contents/Resources/julia/bin/julia -Ccore2 -J/Applications/JuliaPro-0.5.0.4.app/Contents/Resources/julia/Contents/Resources/julia/lib/julia/sys.dylib --compile=yes --depwarn=yes --check-bounds=yes --code-coverage=none --color=yes --compilecache=yes /Applications/JuliaPro-0.5.0.4.app/Contents/Resources/pkgs-0.5.0.4/v0.5/KernelDensity/test/runtests.jl`, ProcessExited(1)) [1]

=================================================================================================================================================================
ERROR: KernelDensity had test errors
 in #test#61(::Bool, ::Function, ::Array{AbstractString,1}) at ./pkg/entry.jl:740
 in (::Base.Pkg.Entry.#kw##test)(::Array{Any,1}, ::Base.Pkg.Entry.#test, ::Array{AbstractString,1}) at ./<missing>:0
 in (::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#test,Tuple{Array{AbstractString,1}}})() at ./pkg/dir.jl:31
 in cd(::Base.Pkg.Dir.##2#3{Array{Any,1},Base.Pkg.Entry.#test,Tuple{Array{AbstractString,1}}}, ::String) at ./file.jl:59
 in #cd#1(::Array{Any,1}, ::Function, ::Function, ::Array{AbstractString,1}, ::Vararg{Array{AbstractString,1},N}) at ./pkg/dir.jl:31
 in (::Base.Pkg.Dir.#kw##cd)(::Array{Any,1}, ::Base.Pkg.Dir.#cd, ::Function, ::Array{AbstractString,1}, ::Vararg{Array{AbstractString,1},N}) at ./<missing>:0
 in #test#3(::Bool, ::Function, ::String, ::Vararg{String,N}) at ./pkg/pkg.jl:258
 in test(::String, ::Vararg{String,N}) at ./pkg/pkg.jl:258

KernelDensity with range

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

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

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?

Key for densities in plot?

Is there a way to plot a legend off to the side of the image that shows what the colours from blue to red mean, as in:
qpgm6

check_ambiguous_visitor assertion

julia> versioninfo()
    Julia Version 0.6.4
    Commit 9d11f62bcb (2018-07-09 19:09 UTC)
    DEBUG build
    Platform Info:
      OS: Linux (x86_64-pc-linux-gnu)
      CPU: Intel(R) Core(TM) i7-7740X CPU @ 4.30GHz
      WORD_SIZE: 64
      BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell MAX_THREADS=16)
      LAPACK: libopenblas64_
      LIBM: libopenlibm
      LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)
julia> using KernelDensity
INFO: Precompiling module KernelDensity.
julia-debug: /buildworker/worker/package_linux64/build/src/gf.c:1132: check_ambiguous_visitor: Assertion `!jl_subtype((jl_value_t*)sig, (jl_value_t*)type)' failed.

signal (6): Aborted
while loading ~/.julia/v0.6/KernelDensity/src/KernelDensity.jl, in expression starting on line 9

This happening both on

julia> Pkg.status("KernelDensity")
 - KernelDensity                 0.4.1

and master.

Tag a release

On an empty project
add FFTW; add KernelDensity
install FFTW v1.0.1 and results in an error

ERROR: Unsatisfiable requirements detected for package KernelDensity [5ab0869b]:
 KernelDensity [5ab0869b] log:
 ├─possible versions are: [0.0.1-0.0.2, 0.1.0-0.1.2, 0.2.0, 0.3.0-0.3.2, 0.4.0-0.4.1, 0.5.0-0.5.1] or uninstalled
 ├─restricted to versions * by an explicit requirement, leaving only versions [0.0.1-0.0.2, 0.1.0-0.1.2, 0.2.0, 0.3.0-0.3.2, 0.4.0-0.4.1, 0.5.0-0.5.1]
 ├─restricted by compatibility requirements with FFTW [7a1cc6ca] to versions: [0.0.1-0.0.2, 0.1.0-0.1.2, 0.2.0, 0.3.0-0.3.2, 0.4.0-0.4.1] or uninstalled, leaving only versions: [0.0.1-0.0.2, 0.1.0-0.1.2, 0.2.0, 0.3.0-0.3.2, 0.4.0-0.4.1]
 │ └─FFTW [7a1cc6ca] log:
 │   ├─possible versions are: [0.0.1-0.0.4, 0.1.0-0.1.2, 0.2.0-0.2.4, 0.3.0, 1.0.0-1.0.1] or uninstalled
 │   └─restricted to versions 1.0.1 by an explicit requirement, leaving only versions 1.0.1
 └─restricted by julia compatibility requirements to versions: 0.5.0-0.5.1 or uninstalled — no versions left

Installing KernelDensity first installs v.0.5.1, and v0.3.0 of FFTW. However, this bins Makie to version v0.9.3 instead of v0.9.5.

[PkgEval] KernelDensity may have a testing issue on Julia 0.3 (2014-07-15)

PackageEvaluator.jl is a script that runs nightly. It attempts to load all Julia packages and run their tests (if available) on both the stable version of Julia (0.2) and the nightly build of the unstable version (0.3). The results of this script are used to generate a package listing enhanced with testing results.

On Julia 0.3

  • On 2014-07-14 the testing status was Tests pass.
  • On 2014-07-15 the testing status changed to Package doesn't load.

Tests pass. means that PackageEvaluator found the tests for your package, executed them, and they all passed.

Package doesn't load. means that PackageEvaluator did not find tests for your package. Additionally, trying to load your package with using failed.

This issue was filed because your testing status became worse. No additional issues will be filed if your package remains in this state, and no issue will be filed if it improves. If you'd like to opt-out of these status-change messages, reply to this message saying you'd like to and @IainNZ will add an exception. If you'd like to discuss PackageEvaluator.jl please file an issue at the repository. For example, your package may be untestable on the test machine due to a dependency - an exception can be added.

Test log:

INFO: Cloning cache of KernelDensity from git://github.com/JuliaStats/KernelDensity.jl.git
INFO: Installing ArrayViews v0.4.6
INFO: Installing Distributions v0.5.2
INFO: Installing KernelDensity v0.0.2
INFO: Installing PDMats v0.2.1
INFO: Installing StatsBase v0.5.3
INFO: Package database updated
ERROR: NumericExtensions not found
 in require at loading.jl:47
 in include at ./boot.jl:245
 in include_from_node1 at ./loading.jl:128
 in reload_path at loading.jl:152
 in _require at loading.jl:67
 in require at loading.jl:54
 in include at ./boot.jl:245
 in include_from_node1 at ./loading.jl:128
 in reload_path at loading.jl:152
 in _require at loading.jl:67
 in require at loading.jl:54
 in include at ./boot.jl:245
 in include_from_node1 at ./loading.jl:128
 in reload_path at loading.jl:152
 in _require at loading.jl:67
 in require at loading.jl:51
 in include at ./boot.jl:245
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354
while loading /home/idunning/pkgtest/.julia/v0.3/PDMats/src/PDMats.jl, in expression starting on line 9
while loading /home/idunning/pkgtest/.julia/v0.3/Distributions/src/Distributions.jl, in expression starting on line 4
while loading /home/idunning/pkgtest/.julia/v0.3/KernelDensity/src/KernelDensity.jl, in expression starting on line 4
while loading /home/idunning/pkgtest/.julia/v0.3/KernelDensity/testusing.jl, in expression starting on line 1
INFO: Package database updated

Plans to update for julia 0.7?

Are there plans to update this package for julia 0.7? Some parts appear to be easy to adapt, but the interpolation parts seem a little more complicated.

pdf of new data points?

Forgive me if I'm being naive, but once I run a univariate or bivariate kde, how would I go about getting the pdf of a new data point?

[PkgEval] KernelDensity may have a testing issue on Julia 0.4 (2015-06-30)

PackageEvaluator.jl is a script that runs nightly. It attempts to load all Julia packages and run their tests (if available) on both the stable version of Julia (0.3) and the nightly build of the unstable version (0.4). The results of this script are used to generate a package listing enhanced with testing results.

On Julia 0.4

  • On 2015-06-27 the testing status was Tests pass.
  • On 2015-06-30 the testing status changed to Tests fail.

This issue was filed because your testing status became worse. No additional issues will be filed if your package remains in this state, and no issue will be filed if it improves. If you'd like to opt-out of these status-change messages, reply to this message saying you'd like to and @IainNZ will add an exception. If you'd like to discuss PackageEvaluator.jl please file an issue at the repository. For example, your package may be untestable on the test machine due to a dependency - an exception can be added.

Test log:

>>> 'Pkg.add("KernelDensity")' log
INFO: Installing Calculus v0.1.8
INFO: Installing Distributions v0.7.3
INFO: Installing DualNumbers v0.1.3
INFO: Installing Grid v0.3.10
INFO: Installing KernelDensity v0.1.1
INFO: Installing NaNMath v0.0.2
INFO: Installing Optim v0.4.1
INFO: Installing PDMats v0.3.3
INFO: Installing WoodburyMatrices v0.1.0
INFO: Package database updated

>>> 'Pkg.test("KernelDensity")' log
Julia Version 0.4.0-dev+5700
Commit 147fa0b* (2015-06-29 20:31 UTC)
Platform Info:
  System: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2650 0 @ 2.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Nehalem)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3
INFO: Testing KernelDensity
Running tests:
 * univariate.jl
Warning: could not import Base.@math_const into Distributions
ERROR: LoadError: LoadError: LoadError: LoadError: UndefVarError: @math_const not defined
 in include at ./boot.jl:254
 in include_from_node1 at ./loading.jl:133
 in include at ./boot.jl:254
 in include_from_node1 at ./loading.jl:133
 in reload_path at ./loading.jl:157
 in _require at ./loading.jl:69
 in require at ./loading.jl:52
 in include at ./boot.jl:254
 in include_from_node1 at ./loading.jl:133
 in anonymous at no file:11
 in include at ./boot.jl:254
 in include_from_node1 at loading.jl:133
 in process_options at ./client.jl:305
 in _start at ./client.jl:405
while loading /home/vagrant/.julia/v0.4/Distributions/src/constants.jl, in expression starting on line 6
while loading /home/vagrant/.julia/v0.4/Distributions/src/Distributions.jl, in expression starting on line 252
while loading /home/vagrant/.julia/v0.4/KernelDensity/test/univariate.jl, in expression starting on line 2
while loading /home/vagrant/.julia/v0.4/KernelDensity/test/runtests.jl, in expression starting on line 8
============================[ ERROR: KernelDensity ]============================

failed process: Process(`/home/vagrant/julia/bin/julia --check-bounds=yes --code-coverage=none --color=no /home/vagrant/.julia/v0.4/KernelDensity/test/runtests.jl`, ProcessExited(1)) [1]

================================================================================
INFO: No packages to install, update or remove
ERROR: KernelDensity had test errors
 in error at ./error.jl:21
 in test at pkg/entry.jl:746
 in anonymous at pkg/dir.jl:31
 in cd at file.jl:22
 in cd at pkg/dir.jl:31
 in test at pkg.jl:71
 in process_options at ./client.jl:281
 in _start at ./client.jl:405

>>> End of log

Epanechnikov kernel?

Doing kernel densities using the epanechnikov kernel is very common, but does not seem to be a built-in option. Perhaps because epanechnikov is not included in Distributions.jl.

I think it would be widely convenient as a built-in kernel: is that something you would consider adding? I'd submit a PR if my Julia skills were up to it.

deprecated code

some of the code seems to use deprecated commands, I get these warnings:

julia> using KernelDensity

julia> data=randn(1000);

julia> y=kde(data);

julia> pdf(y,.5)
┌ Warning: interpolate(A, BSpline(Quadratic(Line())), Interpolations.OnGrid()) is deprecated, use interpolate(A, BSpline(Quadratic(Line(Interpolations.OnGrid()))))
│   caller = Type at interp.jl:11 [inlined]
└ @ Core C:\Users\andras\AppData\Local\JuliaPro-1.0.1.1\pkgs-1.0.1.1\packages\KernelDensity\JfNeR\src\interp.jl:11
┌ Warning: `getindex(itp::AbstractInterpolation{T, N}, i::Vararg{Number, N}) where {T, N}` is deprecated, use `itp(i...)` instead.
│   caller = pdf at interp.jl:25 [inlined]
└ @ Core C:\Users\andras\AppData\Local\JuliaPro-1.0.1.1\pkgs-1.0.1.1\packages\KernelDensity\JfNeR\src\interp.jl:25
0.3531142839535672

BoundsError with Interpolations 0.9.x

Interpolations 0.9.0 was a breaking release, and it breaks KernelDensity when trying to evaluate the KDE outside the bounds of the interpolator.

Steps to reproduce:

Manifest.toml.zip

(v1.0) pkg> generate Test
Generating project Test:
    Test/Project.toml
    Test/src/Test.jl

shell> cd Test
/tmp/Test

(v1.0) pkg> activate .

(Test) pkg> add KernelDensity
  Updating registry at `~/.julia/registries/General`
  Updating git-repo `https://github.com/JuliaRegistries/General.git`
 Resolving package versions...
  Updating `Project.toml`
  [5ab0869b] + KernelDensity v0.5.0
  Updating `Manifest.toml`
  [621f4979] + AbstractFFTs v0.3.2
  [7d9fca2a] + Arpack v0.2.3
  [13072b0f] + AxisAlgorithms v0.3.0
  [9e28174c] + BinDeps v0.8.10
  [b99e7846] + BinaryProvider v0.5.0
  [49dc2e85] + Calculus v0.4.1
  [bbf7d656] + CommonSubexpressions v0.2.0
  [34da2185] + Compat v1.2.0
  [8f4d0f93] + Conda v1.0.2
  [864edb3b] + DataStructures v0.14.0
  [01453d9d] + DiffEqDiffTools v0.6.0
  [163ba53b] + DiffResults v0.0.3
  [b552c78f] + DiffRules v0.0.7
  [31c24e10] + Distributions v0.16.4
  [7a1cc6ca] + FFTW v0.2.4
  [f6369f11] + ForwardDiff v0.9.0
  [a98d9a8b] + Interpolations v0.9.1
  [682c06a0] + JSON v0.19.0
  [5ab0869b] + KernelDensity v0.5.0
  [d3d80556] + LineSearches v7.0.0
  [e1d29d7a] + Missings v0.3.1
  [d41bc354] + NLSolversBase v7.1.0
  [77ba4419] + NaNMath v0.3.2
  [6fe1bfb0] + OffsetArrays v0.8.1
  [429524aa] + Optim v0.17.1
  [bac558e1] + OrderedCollections v1.0.2
  [90014a1f] + PDMats v0.9.5
  [d96e819e] + Parameters v0.10.1
  [85a6dd25] + PositiveFactorizations v0.2.1
  [1fd47b50] + QuadGK v2.0.2
  [c84ed2f1] + Ratios v0.3.0
  [189a3867] + Reexport v0.2.0
  [79098fc4] + Rmath v0.5.0
  [a2af1166] + SortingAlgorithms v0.3.1
  [276daf66] + SpecialFunctions v0.7.1
  [90137ffa] + StaticArrays v0.8.3
  [2913bbd2] + StatsBase v0.25.0
  [4c63d2b9] + StatsFuns v0.7.0
  [30578b45] + URIParser v0.4.0
  [81def892] + VersionParsing v1.1.3
  [efce3f68] + WoodburyMatrices v0.4.1
  [2a0f44e3] + Base64 
  [ade2ca70] + Dates 
  [8bb1440f] + DelimitedFiles 
  [8ba89e20] + Distributed 
  [b77e0a4c] + InteractiveUtils 
  [76f85450] + LibGit2 
  [8f399da3] + Libdl 
  [37e2e46d] + LinearAlgebra 
  [56ddb016] + Logging 
  [d6f4376e] + Markdown 
  [a63ad114] + Mmap 
  [44cfe95a] + Pkg 
  [de0858da] + Printf 
  [3fa0cd96] + REPL 
  [9a3f8284] + Random 
  [ea8e919c] + SHA 
  [9e88b42a] + Serialization 
  [1a1011a3] + SharedArrays 
  [6462fe0b] + Sockets 
  [2f01184e] + SparseArrays 
  [10745b16] + Statistics 
  [4607b0f0] + SuiteSparse 
  [8dfed614] + Test 
  [cf7118a7] + UUIDs 
  [4ec0a83e] + Unicode 

julia> using Random, KernelDensity

julia> Random.seed!(1337);

julia> x = rand(1000);

julia> K = kde(x)
UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}(-0.26038988009831726:0.0007430635406498104:1.2606611876118445, [7.04455e-5, 7.05408e-5, 7.07904e-5, 7.11946e-5, 7.17542e-5, 7.247e-5, 7.33433e-5, 7.43754e-5, 7.55682e-5, 7.69234e-5    7.80742e-5, 7.65918e-5, 7.5274e-5, 7.41185e-5, 7.31234e-5, 7.22871e-5, 7.1608e-5, 7.10851e-5, 7.07174e-5, 7.05043e-5])

julia> pdf(K, -1.0)
┌ Warning: interpolate(A, BSpline(Quadratic(Line())), Interpolations.OnGrid()) is deprecated, use interpolate(A, BSpline(Quadratic(Line(Interpolations.OnGrid()))))
│   caller = Type at interp.jl:11 [inlined]
└ @ Core ~/.julia/packages/KernelDensity/JfNeR/src/interp.jl:11
┌ Warning: `getindex(itp::AbstractInterpolation{T, N}, i::Vararg{Number, N}) where {T, N}` is deprecated, use `itp(i...)` instead.
│   caller = pdf at interp.jl:25 [inlined]
└ @ Core ~/.julia/packages/KernelDensity/JfNeR/src/interp.jl:25
ERROR: BoundsError: attempt to access 2048-element interpolate(OffsetArray(::Array{Float64,1}, 0:2049), BSpline(Quadratic(Line(Interpolations.OnGrid())))) with element type Float64 at index [-994.3524556660287]
Stacktrace:
 [1] throw_boundserror(::Interpolations.BSplineInterpolation{Float64,1,OffsetArrays.OffsetArray{Float64,1,Array{Float64,1}},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.Line{Interpolations.OnGrid}}},Tuple{Base.OneTo{Int64}}}, ::Tuple{Float64}) at ./abstractarray.jl:484
 [2] BSplineInterpolation at /home/jl/.julia/packages/Interpolations/Pwkql/src/b-splines/indexing.jl:6 [inlined]
 [3] (::Interpolations.ScaledInterpolation{Float64,1,Interpolations.BSplineInterpolation{Float64,1,OffsetArrays.OffsetArray{Float64,1,Array{Float64,1}},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.Line{Interpolations.OnGrid}}},Tuple{Base.OneTo{Int64}}},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.Line{Interpolations.OnGrid}}},Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}})(::Float64) at /home/jl/.julia/packages/Interpolations/Pwkql/src/scaling/scaling.jl:63
 [4] getindex(::Interpolations.ScaledInterpolation{Float64,1,Interpolations.BSplineInterpolation{Float64,1,OffsetArrays.OffsetArray{Float64,1,Array{Float64,1}},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.Line{Interpolations.OnGrid}}},Tuple{Base.OneTo{Int64}}},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.Line{Interpolations.OnGrid}}},Tuple{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}}, ::Float64) at ./deprecated.jl:55
 [5] pdf at /home/jl/.julia/packages/KernelDensity/JfNeR/src/interp.jl:25 [inlined]
 [6] pdf(::UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Float64) at /home/jl/.julia/packages/KernelDensity/JfNeR/src/interp.jl:29
 [7] top-level scope at none:0

Mass point to the right in the estimated density

I am not sure if this is a bug, or my ignorance but running

using Distributions
using Gadfly
using KernelDensity


n = 300
dx = rand(TruncatedNormal(1., 20., 0, Inf),n)
x = cumsum(dx)

dx_kde = kde(dx)
dx_kde_midpoints = kde(dx, minimum(dx):maximum(dx)*2)

plot(x=1:n, y=x, Geom.line)
plot(x = dx_kde.x, y = dx_kde.density,Geom.line)
plot(x = dx_kde_midpoints.x, y = dx_kde_midpoints.density, Geom.line)

Gives the following two plots (in the same order as the code)

nomid
midpoints

I really just wanted to truncate it to the left, which seems to work. No matter how high or low I set the upper limit in the kde(Array, Range) call, I get that jump in the end.

Failing on 0.4 master

I ran into this when doing using Gadfly.

ERROR: LoadError: LoadError: LoadError: LoadError: ArgumentError: invalid type for argument boundary in method definition for kde_range at /Users/viral/.julia/v0.4/KernelDensity/src/univariate.jl:62
 in include at ./boot.jl:252
 in include_from_node1 at ./loading.jl:134
 in include at ./boot.jl:252
 in include_from_node1 at ./loading.jl:134
 in reload_path at ./loading.jl:158
 in _require at ./loading.jl:70
 in require at ./loading.jl:56
 in include at ./boot.jl:252
 in include_from_node1 at ./loading.jl:134
 in include at ./boot.jl:252
 in include_from_node1 at ./loading.jl:134
 in reload_path at ./loading.jl:158
 in _require at ./loading.jl:70
 in require at ./loading.jl:53
while loading /Users/viral/.julia/v0.4/KernelDensity/src/univariate.jl, in expression starting on line 61
while loading /Users/viral/.julia/v0.4/KernelDensity/src/KernelDensity.jl, in expression starting on line 14
while loading /Users/viral/.julia/v0.4/Gadfly/src/statistics.jl, in expression starting on line 16
while loading /Users/viral/.julia/v0.4/Gadfly/src/Gadfly.jl, in expression starting on line 1054

Density is 0.0 for y range of z:z

Hey, I'm not sure if this is a bug or intended behavior, but given the following code:

x = [rand(1.0:10000.0) for i = 1:10000]
y = [rand(1.0:10.0) for i = 1:10000]
test = kde((x,y), (1:10000,10:10))
test.density

It will return a 10000x1 Array{Float64,2} with all values being 0.0, seen by running (which will give 0.0 as well):

sum(test.density)

However, if you change the range so it is not a z:z value. For instance:

x = [rand(1.0:10000.0) for i = 1:10000]
y = [rand(1.0:10.0) for i = 1:10000]
test = kde((x,y), (1:10000,9:10))
test.density

Then everything works as intended and gives you a 10000x2 Array{Float64,2} filled with density values.

Multithreading problem caused by FFTW dependency

tl;dr if you use many threads, running FFTW.set_num_threads(1) can be a good idea. Otherwise FFTW probably slows down computation and prevents outer parallelism. I suggest adding it to the README.

Full explanation
I was trying to do a lot of KDE in the loop, but it occurred that running the code in parallel slow down the process. Even if I simply set JULIA_NUM_THREADS=20 (for 56 core server) without using @threads:

using KernelDensity
using Base.Threads

interp_kde(coords::Array{Float64, 2}, bandwidth::Float64) =
    InterpKDE(kde((coords[1,:], coords[2,:]), bandwidth=(bandwidth, bandwidth)))

td = rand(2, 100000);
@time for i in 1:500
    interp_kde(td, 1.0)
end

It creates multiple threads with loading 30% and takes 15.9 seconds. The same code with JULIA_NUM_THREADS=1 takes 7.5 seconds, working fairly in single thread. Timing doesn't really change if I use `@threads:

@time @threads for i in 1:500
    interp_kde(td, 1.0)
end

After some digging, the problem occurred to be in the FFTW package, which is called somewhere during interpolation and by default uses nthreads() * 4 threads inside its C code. To disable it you need to run FFTW.set_num_threads(1). After that, running with JULIA_NUM_THREADS=20 but without @threads takes 7.5 seconds, as it should be, and with @threads it takes 0.5 seconds.

I was trying different run configurations, but at the end, looks like having FFTW parallel improves situation comparing to single thread only with large arrays (>500000) and large number of iterations (>100) And it's always much worse than having outer loop parallel.

Tag new release?

Tests have deprecation warnings on 0.1.2, but don't on master (Julia v0.5). Could you please tag a new release?

Density sum

Hello,

I'm by no means a math-wizard, so this might just be dumb question.

But since Kernel Density Estimation is about estimating the probability density function, aren't all the returned densities supposed to sum to approximately 1?

Using a different kernel distribution

Hello,

I'm trying to use LogNormal as kernel, but it is not supported by this package. The main problem seems to be cf does not support LogNormal.

The docs say

To add your own kernel, extend the internal kernel_dist function.

however, I'm struggling to find out how to do this. Can anyone enlighten me on this subject?
Many thanks.

Edit: to be clear, the reason I want to do this is because I have some time series which by definition do not assume values lower than zero. When plotting Normal KDE, it looks like there is a significant portion below zero. Using boundaries does not help as it just ctus the density at that point. I'm not sure a LogNormal KDE is indeed the most appropriate solution.

extend methods for TrackedArray and TrackedReal

I would like to use kde as part of a machine learning flow. suppose the input data is a TrackedArray from Flux.jl. Currently FFTW which is used for convolution of data with distribution kernel does not support TrackedArrays, I recommend a rewrite of conv to use Flux's conv...

broadcast doesn't work for pdf calculation

broadcast doesn't work for pdf calculation, see e.g.

julia> using KernelDensity

julia> y=kde(randn(1000));

julia> pdf.(y, [.5,.6])
ERROR: MethodError: no method matching length(::UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}})
Closest candidates are:
  length(::Core.SimpleVector) at essentials.jl:582
  length(::Base.MethodList) at reflection.jl:728
  length(::Core.MethodTable) at reflection.jl:802
  ...
Stacktrace:
 [1] _similar_for(::UnitRange{Int64}, ::Type, ::UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Base.HasLength) at .\array.jl:532
 [2] _collect(::UnitRange{Int64}, ::UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Base.HasEltype, ::Base.HasLength) at .\array.jl:563
 [3] collect(::UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}) at .\array.jl:557
 [4] broadcastable(::UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}) at .\broadcast.jl:609
 [5] broadcasted(::Function, ::UnivariateKDE{StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}}, ::Array{Float64,1}) at .\broadcast.jl:1163
 [6] top-level scope at none:0

This is in contrast to other calculations of pdfs, e.g.

julia> using Distributions

julia> N=Normal()
Normal{Float64}=0.0, σ=1.0)

julia> pdf.(N, [.5,.6])
2-element Array{Float64,1}:
 0.3520653267642995
 0.33322460289179967

The non-broadcasting version does work for KernelDensity (pdf(y,[.5,.6])), however, for this kind of usage seems to be not recommended and deprecated, see e.g.

julia> pdf(N, [.5,.6])
┌ Warning: `pdf(d::UnivariateDistribution, X::AbstractArray)` is deprecated, use `pdf.(d, X)` instead.
│   caller = top-level scope at none:0
└ @ Core none:0
2-element Array{Float64,1}:
 0.3520653267642995
 0.33322460289179967

Installation Unsatisfiable Requirements

In Julia 1.2, within the ordinary REPL (not atom)

(v1.2) pkg> add KernelDensity
 Resolving package versions...
ERROR: Unsatisfiable requirements detected for package KernelDensity [5ab0869b]:
 KernelDensity [5ab0869b] log:
 ├─possible versions are: [0.0.1-0.0.2, 0.1.0-0.1.2, 0.2.0, 0.3.0-0.3.2, 0.4.0-0.4.1, 0.5.0-0.5.1] or uninstalled
 ├─restricted to versions * by an explicit requirement, leaving only versions [0.0.1-0.0.2, 0.1.0-0.1.2, 0.2.0, 0.3.0-0.3.2, 0.4.0-0.4.1, 0.5.0-0.5.1]
 ├─restricted by compatibility requirements with FFTW [7a1cc6ca] to versions: [0.0.1-0.0.2, 0.1.0-0.1.2, 0.2.0, 0.3.0-0.3.2, 0.4.0-0.4.1] or uninstalled, leaving only versions: [0.0.1-0.0.2, 0.1.0-0.1.2, 0.2.0, 0.3.0-0.3.2, 0.4.0-0.4.1]
 │ └─FFTW [7a1cc6ca] log:
 │   ├─possible versions are: [0.0.1-0.0.4, 0.1.0-0.1.2, 0.2.0-0.2.4, 0.3.0, 1.0.0-1.0.1] or uninstalled
 │   └─restricted to versions 1.0.0 by an explicit requirement, leaving only versions 1.0.0
 └─restricted by julia compatibility requirements to versions: 0.5.0-0.5.1 or uninstalled — no versions left

Package versions I am using

(v1.2) pkg> status
    Status `~/.julia/environments/v1.2/Project.toml`
  [c52e3926] Atom v0.10.1
  [6e4b80f9] BenchmarkTools v0.4.3
  [336ed68f] CSV v0.5.12
  [be33ccc6] CUDAnative v2.3.1
  [3a865a2d] CuArrays v1.2.1
  [a93c6f00] DataFrames v0.19.4
  [31a5f54b] Debugger v0.6.2
  [39dd38d3] Dierckx v0.4.1
  [7a1cc6ca] FFTW v1.0.1
  [5789e2e9] FileIO v1.0.7
  [c27321d9] Glob v1.2.0
  [f67ccb44] HDF5 v0.12.3
  [5903a43b] Infiltrator v0.1.0
  [a98d9a8b] Interpolations v0.12.2
  [033835bb] JLD2 v0.1.3
  [e5e0dc1b] Juno v0.7.2
  [91a5bcdd] Plots v0.26.3
  [f27b6e38] Polynomials v0.5.2
  [c46f51b8] ProfileView v0.4.1
  [438e738f] PyCall v1.91.2
  [d330b81b] PyPlot v2.8.2
  [295af30f] Revise v2.2.0
  [276daf66] SpecialFunctions v0.8.0
  [90137ffa] StaticArrays v0.11.0
  [0796e94c] Tokenize v0.5.6
  [796a5d58] WordTokenizers v0.5.3

The solution for now is to remove the FFTW package and then add KernelDensity.jl
(v1.2) pkg> rm FFTW

At least this gets me to the ability to add KernelDensity.jl I haven't tested it yet.

accessors for gridpoints and corresponding densities

It is unclear if eg for univariate densities the slots x and density can be used (ie are part of the API and can be expected to be stable, not an internal implementation detail).

It would be great to document this, or alternatively provide accessor functions. Similarly for bivariate.

If the package maintainers clarify their intention, I would be happy to make a PR.

N-variate KDE

It would be useful to have N-variate KDEs, or at least trivariate, as those can still be visualized. How involved would it be to implement this?

Transforms of Variables

Would there be any easy way to implement doing Kernel density estimation on transforms of variables? For example, I have a variable that is constrained to be between 0 and 1, it would be better for me to do the kernel density estimate of the logit of the variable or the complementary log log of the variable, obtain the fit, and then scale it by the appropriate value.

It would be nice if this was built into the package for particular transforms of interest so that packages like gadfly can use them without the user having to manually transform the variables, feed those variables to gadfly etc.

bug in InterpKDE

I have a kde::UnivariateKDE which is non-negative. Constructing ik = InterpKDE(kde) results in undefined grid. Even worse, calling pdf(ik, x) sometimes return negative values.

bug in kde_range

There seem to be a problem with kde_range in univariant.jl: The range that is returned sometimes has the wrong number of points.

Can be easily detected by inserting length(lo:step:hi) == npoints || @show "ERROR", length(lo:step:hi)
before returning.

I think it results from a problem is linspace.

Suggested fix:

return lo + (0:npoints-1)*step instead of lo:step:hi

Installation problem

I've encountered the following error message when I try to install KernelDensity.jl. Not sure if this is best addressed here or at Atom

(v1.1) pkg> add KernelDensity.jl
  Updating registry at `C:\Users\uctpdtz\.julia\registries\General`
  Updating git-repo `https://github.com/JuliaRegistries/General.git`
 Resolving package versions...
ERROR: Unsatisfiable requirements detected for package DebuggerFramework [67417a49]:
 DebuggerFramework [67417a49] log:
 ├─possible versions are: 0.1.0-0.1.2 or uninstalled
 ├─restricted by compatibility requirements with Atom [c52e3926] to versions: 0.1.0-0.1.2
 │ └─Atom [c52e3926] log:
 │   ├─possible versions are: [0.1.0-0.1.1, 0.2.0-0.2.1, 0.3.0, 0.4.0-0.4.6, 0.5.0-0.5.10, 0.6.0-0.6.17, 0.7.0-0.7.15, 0.8.0-0.8.2] or uninstalled
 │   └─restricted to versions 0.7.14 by an explicit requirement, leaving only versions 0.7.14
 └─restricted by julia compatibility requirements to versions: uninstalled — no versions left

Add plot recipes?

Looking at 2de1e7b it seems like it would be pretty straightforward to add recipe(s) so that all these plots are supported easily. Would you rather add a dependency on RecipesBase here and keep the recipes close, or add to StatPlots? We can choose either since StatPlots depends on this package.

Using UnicodePlots.jl for Base.show?

For AverageShiftedHistograms.jl, I'm using the new UnicodePlots.jl for Base.show methods. This gives a simple look at the density and makes for quick comparisons between smoothing parameter/kernel options. I think this would be a cool addition to KernelDensity. Any thoughts?

Here's an example (it looks good in the REPL...border is off with copy/paste)

julia> o = ash(randn(1000), nbins = 75)
AverageShiftedHistograms.UnivariateASH
*  kernel: biweight
*       m: 5
*   edges: -4.775108686536068:0.12562952377203349:4.647105596366442
*    nobs: 1000
        ┌────────────────────────────────────────┐ 
    0.5 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
        │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠤⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
        │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠔⠉⠀⠀⠘⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
        │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠎⠀⠀⠀⠀⠀⠹⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
        │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡜⠀⠀⠀⠀⠀⠀⠀⢣⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
        │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡜⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⢦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
        │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠜⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢣⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
        │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⠔⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
        │⠒⠒⠒⠒⠒⠒⠒⠒⠛⠛⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠛⠛⠓⠒⠒⠒⠒⠒⠒⠂│ 
   -0.1 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ 
        └────────────────────────────────────────┘ 
        -5                                       5

Bivariate pdf call for list of values

When I use the following method pdf(k::BivariateKDE, x, y) on two lists of size N I get an NxN matrix of values. Is there a way to tell pdf to return an array of length N where the ith element is computing pdf(...,x[i],y[i])?

KDE with weighted data

I need to do a KDE over weighted data, i.e. each entry of data::RealVector should count according to weights::RealVector with sum(weights) == 1

Am I right thinking that all I need to adjust is
ainc = 1.0 / (ndata*s*s) -> ainc = 1.0 / (s*s)
and

grid[j] += (midpoints[k]-x)*ainc*weights[i] # where data[i] == x
grid[k] += (x-midpoints[j])*ainc*weights[i]

in univariate.jl?

[PkgEval] KernelDensity may have a testing issue on Julia 0.3 (2014-05-20)

PackageEvaluator.jl is a script that runs nightly. It attempts to load all Julia packages and run their tests (if available) on both the stable version of Julia (0.2) and the nightly build of the unstable version (0.3). The results of this script are used to generate a package listing enhanced with testing results.

On Julia 0.3

  • On 2014-05-19 the testing status was Tests pass..
  • On 2014-05-20 the testing status changed to Package doesn't load..

Tests pass. means that PackageEvaluator found the tests for your package, executed them, and they all passed.

Package doesn't load. means that PackageEvaluator did not find tests for your package. Additionally, trying to load your package with using failed.

This issue was filed because your testing status became worse. No additional issues will be filed if your package remains in this state, and no issue will be filed if it improves. If you'd like to opt-out of these status-change messages, reply to this message saying you'd like to and @IainNZ will add an exception. If you'd like to discuss PackageEvaluator.jl please file an issue at the repository. For example, your package may be untestable on the test machine due to a dependency - an exception can be added.

drop Optim?

Optim is a rather heavy dependency, especially since the optimisation problem in kde_lscv appears to be fairly straightforward.

I therefore experimented with a simple golden section search - and it works well. It seems as if Optim could be dropped and the short golden section search code (a total of 18 lines) could be added to the package.

The key parts of the code are a follows:

hGSS = golden_section_searchX(hlb, hub,0.0001) do h
... [current loss function]
end

function golden_section_searchX(f, a, b, ϵ)
... [standard code, 16 lines]
end

Feature Request: Mode(s) finding

It would be great to have an implementation of an algorithm that finds modes of kernel density estimates. Most common algorithm is mean-shift algorithm:

Comaniciu, Dorin; Peter Meer (May 2002). "Mean Shift: A Robust Approach Toward Feature Space Analysis". IEEE Transactions on Pattern Analysis and Machine Intelligence (IEEE) 24 (5): 603–619. doi:10.1109/34.1000236.

A great short (2 page) guide to using mean shift algorithm for clustering http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/TUZEL1/MeanShift.pdf

Might be more appropriate for the Clustering.jl package.

New method for kernel density estimation

Hello,

I was searching for a Kernel Density estimation in 3D. I think it could be nice to implement the following method from Zdravko Botev et al. in Julia.

Botev, Z. I.; Grotowski, J. F.; Kroese, D. P. Kernel density estimation via diffusion. Ann. Statist. 38 (2010), no. 5, 2916--2957.

There is an implementation of it in Matlab by Zdravko Botev accessible here :
https://fr.mathworks.com/matlabcentral/profile/authors/878078-zdravko-botev

This method proposes also an adaptative algorithm for a better kernel width estimation.

I might try to implement it on my own but I dont know yet if I will use your structures. Still, I will try to drop usable scripts here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.