Skip to content

Commit 3ade534

Browse files
committed
Merge branch 'master' into HEAD
2 parents 903070f + cf96862 commit 3ade534

File tree

13 files changed

+49
-621
lines changed

13 files changed

+49
-621
lines changed

.travis.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
language: julia
22
os:
3-
- linux
4-
- osx
3+
- linux
4+
- osx
55
julia:
6-
- 0.3
7-
- 0.4
8-
- nightly
6+
- 0.4
7+
- 0.5
8+
- nightly
99
notifications:
10-
email: false
11-
sudo: false
10+
email: false
11+
# Uncomment the following lines to override the default test script
12+
#script:
13+
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
14+
# - julia -e 'Pkg.clone(pwd()); Pkg.build("KernelDensity"); Pkg.test("KernelDensity"; coverage=true)'
15+
after_success:
16+
- julia -e 'cd(Pkg.dir("KernelDensity")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'

README.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# KernelDensity.jl
22

33
[![Build Status](https://travis-ci.org/JuliaStats/KernelDensity.jl.svg?branch=master)](https://travis-ci.org/JuliaStats/KernelDensity.jl)
4-
[![KernelDensity](http://pkg.julialang.org/badges/KernelDensity_0.3.svg)](http://pkg.julialang.org/?pkg=KernelDensity&ver=0.3)
4+
[![Coverage Status](https://coveralls.io/repos/github/JuliaStats/KernelDensity.jl/badge.svg)](https://coveralls.io/github/JuliaStats/KernelDensity.jl)
55
[![KernelDensity](http://pkg.julialang.org/badges/KernelDensity_0.4.svg)](http://pkg.julialang.org/?pkg=KernelDensity&ver=0.4)
6+
[![KernelDensity](http://pkg.julialang.org/badges/KernelDensity_0.5.svg)](http://pkg.julialang.org/?pkg=KernelDensity)
67

7-
Kernel density estimators for julia.
8+
Kernel density estimators for Julia.
89

910
## Usage
1011

@@ -76,7 +77,7 @@ e.g. `boundary` now takes a tuple of tuples `((xlo,xhi),(ylo,yhi))`.
7677
The KDE objects are stored as gridded density values, with attached
7778
coordinates. These are typically sufficient for plotting (see below), but
7879
intermediate values can be interpolated using the
79-
[Grid.jl](https://github.com/timholy/Grid.jl) package via the `pdf` method
80+
[Interpolations.jl](https://github.com/tlycken/Interpolations.jl) package via the `pdf` method
8081
(extended from Distributions.jl).
8182

8283
```
@@ -87,26 +88,12 @@ pdf(k::BivariateKDE, x, y)
8788
where `x` and `y` are real numbers or arrays.
8889

8990
If you are making multiple calls to `pdf`, it will be more efficient to
90-
construct an intermediate `InterpKDE` to store the intermediate `InterpGrid`
91-
object:
91+
construct an intermediate `InterpKDE` to store the interpolation structure:
9292

9393
```
9494
ik = InterpKDE(k)
9595
pdf(ik, x)
9696
```
9797

98-
`InterpKDE` can also take additional arguments specifying the
99-
`BoundaryCondition` (default=`BCnan`) and `InterpType` (default=
100-
`InterpQuadratic`).
98+
`InterpKDE` will pass any extra arguments to `interpolate`.
10199

102-
103-
## Plotting
104-
105-
The [Winston.jl](https://github.com/nolta/Winston.jl) and
106-
[PyPlot.jl](https://github.com/stevengj/PyPlot.jl) plotting packages are
107-
currently supported. See the ijulia notebooks:
108-
* [Winston](http://nbviewer.ipython.org/github/JuliaStats/KernelDensity.jl/blob/master/examples/Winston.ipynb)
109-
* [PyPlot](http://nbviewer.ipython.org/github/JuliaStats/KernelDensity.jl/blob/master/examples/PyPlot.ipynb)
110-
111-
We plan to include support for other plotting packages: please file an issue
112-
if your favourite one is not yet available.

REQUIRE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
julia 0.3
1+
julia 0.4
22
StatsBase
33
Distributions
44
Optim
5-
Grid
5+
Interpolations
66
Compat

examples/PyPlot.ipynb

Lines changed: 0 additions & 334 deletions
This file was deleted.

examples/Winston.ipynb

Lines changed: 0 additions & 194 deletions
This file was deleted.

src/KernelDensity.jl

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
VERSION >= v"0.4.0-dev+6521" && __precompile__()
2+
13
module KernelDensity
24

35
using StatsBase
46
using Distributions
57
using Optim
6-
using Grid
8+
using Interpolations
79
using Compat
810

911
import Base: conv
@@ -12,21 +14,11 @@ import Distributions: twoπ, pdf
1214

1315
export kde, kde_lscv, UnivariateKDE, BivariateKDE, InterpKDE, pdf
1416

17+
abstract AbstractKDE
18+
1519
include("univariate.jl")
1620
include("bivariate.jl")
1721
include("interp.jl")
1822

19-
macro glue(pkg)
20-
path = joinpath(dirname(Base.source_path(nothing)),"glue",string(pkg,".jl"))
21-
init = symbol(string(pkg,"_init"))
22-
quote
23-
$(esc(init))() = include($path)
24-
isdefined(Main,$(QuoteNode(pkg))) && $(esc(init))()
25-
end
26-
end
27-
28-
@glue Winston
29-
@glue PyPlot
30-
3123
end # module
3224

src/bivariate.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Store both grid and density for KDE over R2
2-
type BivariateKDE{Rx<:Range,Ry<:Range}
2+
type BivariateKDE{Rx<:Range,Ry<:Range} <: AbstractKDE
33
x::Rx
44
y::Ry
55
density::Matrix{Float64}

src/glue/PyPlot.jl

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/glue/Winston.jl

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/interp.jl

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1-
type InterpKDE{K,G}
1+
import Interpolations: interpolate
2+
3+
type InterpKDE{K,I} <: AbstractKDE
24
kde::K
3-
grid::G
5+
itp::I
6+
InterpKDE(kde,itp) = new(kde,itp)
47
end
58

6-
function InterpKDE{BC<:BoundaryCondition, IT<:InterpType}(k::UnivariateKDE, bc::Type{BC}=BCnan,it::Type{IT}=InterpQuadratic)
7-
g = CoordInterpGrid(k.x, k.density, bc, it)
8-
InterpKDE(k,g)
9-
end
10-
function InterpKDE{BC<:BoundaryCondition, IT<:InterpType}(k::BivariateKDE, bc::Type{BC}=BCnan,it::Type{IT}=InterpQuadratic)
11-
g = CoordInterpGrid((k.x,k.y),k.density,bc,it)
12-
InterpKDE{typeof(k),typeof(g)}(k,g)
9+
10+
function InterpKDE(kde::UnivariateKDE, opts...)
11+
itp_u = interpolate(kde.density, opts...)
12+
itp = scale(itp_u, kde.x)
13+
InterpKDE{typeof(kde),typeof(itp)}(kde, itp)
1314
end
15+
InterpKDE(kde::UnivariateKDE) = InterpKDE(kde, BSpline(Quadratic(Line())), OnGrid())
1416

1517

16-
pdf(ik::InterpKDE,x...) = ik.grid[x...]
18+
function InterpKDE(kde::BivariateKDE, opts...)
19+
itp_u = interpolate(kde.density,opts...)
20+
itp = scale(itp_u, kde.x, kde.y)
21+
InterpKDE{typeof(kde),typeof(itp)}(kde, itp)
22+
end
23+
InterpKDE(kde::BivariateKDE) = InterpKDE(kde::BivariateKDE, BSpline(Quadratic(Line())), OnGrid())
24+
25+
pdf(ik::InterpKDE,x::Real...) = ik.itp[x...]
26+
pdf(ik::InterpKDE,xs::AbstractVector) = [ik.itp[x] for x in xs]
27+
pdf(ik::InterpKDE,xs::AbstractVector,ys::AbstractVector) = [ik.itp[x,y] for x in xs, y in ys]
1728

1829
pdf(k::UnivariateKDE,x) = pdf(InterpKDE(k),x)
1930
pdf(k::BivariateKDE,x,y) = pdf(InterpKDE(k),x,y)

0 commit comments

Comments
 (0)