Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add boundary condition for interpolation #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ ik = InterpKDE(k)
pdf(ik, x)
```

`InterpKDE` will pass any extra arguments to `interpolate`.

`InterpKDE` can take a boundary condition that is passed to `extrapolate`
and any extra arguments are passed to `interpolate`.
12 changes: 7 additions & 5 deletions src/interp.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Interpolations: interpolate
import Interpolations: interpolate, ExtrapDimSpec

type InterpKDE{K,I} <: AbstractKDE
kde::K
Expand All @@ -7,20 +7,22 @@ type InterpKDE{K,I} <: AbstractKDE
end


function InterpKDE(kde::UnivariateKDE, opts...)
function InterpKDE(kde::UnivariateKDE, extrap::Union{ExtrapDimSpec, Number}, opts...)
itp_u = interpolate(kde.density, opts...)
itp_u = extrapolate(itp_u, extrap)
itp = scale(itp_u, kde.x)
InterpKDE{typeof(kde),typeof(itp)}(kde, itp)
end
InterpKDE(kde::UnivariateKDE) = InterpKDE(kde, BSpline(Quadratic(Line())), OnGrid())
InterpKDE(kde::UnivariateKDE) = InterpKDE(kde, NaN, BSpline(Quadratic(Line())), OnGrid())


function InterpKDE(kde::BivariateKDE, opts...)
function InterpKDE(kde::BivariateKDE, extrap::Union{ExtrapDimSpec, Number}, opts...)
itp_u = interpolate(kde.density,opts...)
itp_u = extrapolate(itp_u, extrap)
itp = scale(itp_u, kde.x, kde.y)
InterpKDE{typeof(kde),typeof(itp)}(kde, itp)
end
InterpKDE(kde::BivariateKDE) = InterpKDE(kde::BivariateKDE, BSpline(Quadratic(Line())), OnGrid())
InterpKDE(kde::BivariateKDE) = InterpKDE(kde::BivariateKDE, NaN, BSpline(Quadratic(Line())), OnGrid())

pdf(ik::InterpKDE,x::Real...) = ik.itp[x...]
pdf(ik::InterpKDE,xs::AbstractVector) = [ik.itp[x] for x in xs]
Expand Down