The Wikipedia page on Akima splines (https://en.wikipedia.org/wiki/Akima_spline) is clear on how the spline is defined between the third sample point and the n-2 sample point. It is not very clear on how the curve is defined before the third sample point, nor after the n-2 sample point. Is there an accepted definition for the shape of Akima splines before the third sample point and after the n-2 sample point?
I am debugging a data analysis problem. I have discovered that different math libraries give me different results for Akima spline interpolation. The discrepancies exist in the regions I mentioned – before the third sample point and after the n-2 sample point. Specifically, when I run my test case in R or Python, I get one result, but when I run the same test case in Math.NET, I get a different result. Distrustful of Math.NET, I wrote my own Akima interpolation code following the approach described here: https://www.iue.tuwien.ac.at/phd/rottinger/node60.html. My result is very close to the Math.NET result. In other words, it disagrees with R and Python.
I can't help but wonder if there are multiple valid implementations of Akima splines, which differ from each other in how they handle the curve near the first two and last two sample points. Perhaps R and Python are using one implementation, while Math.NET and my custom code are using another. Can anyone provide some insight?
By the way, I know that Akima's 1970 paper is available to read online. I looked at it, but I don't understand it.
Some scripts:
R
> library(akima)
> x<-c(0,0.104453617941107,0.308445193528619,0.509584827596991,0.708262091859746,0.903877623008211,1)
> y<-c(387.923,471,519.3,553.4,594.6,652,710.541)
> aspline(x,y,0.05)
$x
[1] 0.05
$y
[1] 437.7062
Python
from scipy.interpolate import Akima1DInterpolator
x = [0,0.104453617941107,0.308445193528619,0.509584827596991,0.708262091859746,0.903877623008211,1]
y = [387.923,471,519.3,553.4,594.6,652,710.541]
q=Akima1DInterpolator(x,y)
x0=0.05
y0= q(x0)
print(y0)
437.7061888068854
Math.NET
public void AkimaTest()
{
var x = new double[] { 0, 0.104453617941107, 0.308445193528619, 0.509584827596991, 0.708262091859746, 0.903877623008211, 1 };
var y = new double[] { 387.923, 471, 519.3, 553.4, 594.6, 652, 710.541 };
var cubicSpline = CubicSpline.InterpolateAkima(x, y);
var x0 = 0.05;
var y0 = cubicSpline.Interpolate(x0);
Console.WriteLine($"y0 = {y0:F4}");
}
y0 = 432.6210
EDIT
I can't answer my question, but after studying it for a couple of days, I can shed some light on it.
First of all, I found a very good paper on interpolation methods which included a section on Akima splines. It proposed a set of constraints at the first two and last two sample points which differ from the constraints mentioned on the TU Wien page I cited before. (I would link to the paper with the alternative constraints, but I can no longer find it.) From this, it seems reasonable to infer that the answer to my question is yes, there are multiple Akima splines through a set of sample points because different implementations are free to use different constraints near the first two and last two sample points.
However, I also spent more time studying the approach documented on that TU Wien page, and I discovered that when implemented properly, it produces the same interpolations as R's akima library, Python's scipy library, and MATLAB's Akima Interpolation library. From this, it seems reasonable to infer that even if there is discretion about how to implement Akima splines near the end points, the major math libraries are all using the same approach, and it is the one documented there.