From 673e0a53557e311dc2f3fb5c844e8e62d6eadd84 Mon Sep 17 00:00:00 2001 From: Josh Christie Date: Fri, 23 Dec 2016 15:21:03 +1000 Subject: [PATCH] Add boundary condition for interpolation --- README.md | 4 ++-- src/interp.jl | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f50d050a..897bbe95 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/src/interp.jl b/src/interp.jl index f33bd545..12325ad7 100644 --- a/src/interp.jl +++ b/src/interp.jl @@ -1,4 +1,4 @@ -import Interpolations: interpolate +import Interpolations: interpolate, ExtrapDimSpec type InterpKDE{K,I} <: AbstractKDE kde::K @@ -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]