Giter Site home page Giter Site logo

gerlero / pchipinterpolation.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from slabanja/simplepchip

7.0 7.0 4.0 193 KB

Monotonic cubic interpolation in Julia

License: Other

Julia 100.00%
extrapolation integration interpolation julia pchip-polynomial-spline splines

pchipinterpolation.jl's People

Contributors

dependabot[bot] avatar fghzxm avatar gerlero avatar github-actions[bot] avatar jer-j avatar pallharaldsson avatar scottlemon avatar slabanja avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pchipinterpolation.jl's Issues

BoundsError sometimes when evaluating at rightmost point

using PCHIPInterpolation

x = collect(range(0, stop=1, length=199))
itp = Interpolator(x, x)
itp(1) # Uses linear search (length < 200): OK

x = collect(range(0, stop=1, length=200))
itp = Interpolator(x, x)
itp(1) # Uses bisection: BoundsError: attempt to access 200-element Vector{Float64} at index [201]

x = collect(range(0, stop=1, length=1000))
itp = Interpolator(x, x)
itp(1) # Also uses bisection: but OK

Bug in definition of wl and wr terms

I believe there may be an bug in the following lines:

wl = 2hl + hr
wr = hl + 2hr

Based on the scipy/Matlab implementations of the derivative function the wl and wr terms should be swapped so that:

wl = hl + 2hr
wr = 2hl + hr

See https://github.com/scipy/scipy/blob/main/scipy/interpolate/_cubic.py#L285 for the corresponding scipy version.

Due to this issue, the current Julia version gives subtly different results to both Matlab and scipy.

For example, the Python scipy version:

import numpy as np
import scipy.interpolate

xs = np.array([0.0,  1.2,  2.0,  5.0, 10.0, 11.0])
ys = np.array([2.0,  2.1,  1.0,  0.0,  0.0,  3.0])
yp = scipy.interpolate.pchip_interpolate(xs, ys, 2.5)

gives yp=0.714763623953731

The Matlab version:

xs = [0.0,  1.2,  2.0,  5.0, 10.0, 11.0]
ys = [2.0,  2.1,  1.0,  0.0,  0.0,  3.0]
yp = pchip(x, y, 2.5)

also gives yp=0.714763623953731

The current Julia version:

xs = [0.0,  1.2,  2.0,  5.0, 10.0, 11.0]
ys = [2.0,  2.1,  1.0,  0.0,  0.0,  3.0]
itp = Interpolator(xs, ys)
yp = itp(2.5)

gives yp=0.7592273552265896

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

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.