gerlero / pchipinterpolation.jl Goto Github PK
View Code? Open in Web Editor NEWThis project forked from slabanja/simplepchip
Monotonic cubic interpolation in Julia
License: Other
This project forked from slabanja/simplepchip
Monotonic cubic interpolation in Julia
License: Other
The first code snippet in the README file was broken by the changes in 316c1af. xs
and ys
ought to be 1D (column) vectors instead of row vectors.
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
Would be better to make defensive copies of the input vectors.
I believe there may be an bug in the following lines:
PCHIPInterpolation.jl/src/PCHIPInterpolation.jl
Lines 39 to 40 in cfc4287
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
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!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.