Interpolations.jl icon indicating copy to clipboard operation
Interpolations.jl copied to clipboard

Periodic onCell OnGrid

Open egiovan opened this issue 6 years ago • 3 comments

I tried the following code:

using Interpolations using Dierckx t = range(-π,stop=π, length=8) y = sin.(t); y[end] = y[1]

tt = range(-π,stop=π, length=100)

itpg = extrapolate(interpolate(y, BSpline(Cubic(Periodic(OnGrid())))),Periodic()) itpc = extrapolate(interpolate(y, BSpline(Cubic(Periodic(OnCell())))),Periodic()) sitpg = scale(itpg, t) sitpc = scale(itpc, t);

p = ParametricSpline(t,reshape(y,1,:),periodic=true);

yy = sin.(tt) yg = sitpg(tt); yc = sitpc(tt); yd = reshape(p(tt),:);

I saw a small difference between yg and yc of the order10^-17, so basically numerical precision.

No effects basically between the OnCell and OnGrid.

The approximation calculated by the Diercks routines was closer to the true values:

maximum(yg.-yy) = 0.0969 maximum(yd.-yy) = 0.0020

Cheers, :-)

egiovan avatar Feb 04 '19 16:02 egiovan

With interpolation, there is no "right answer": you're hoping to approximate a continuous function from a set of discrete measurements. I could perturbe the function arbitrarily between measurement locations and get any result I want from this kind of test; with

f(x) = sin(x) + exp(-1000/(x+2)^2)

you'll get no change in the y values but a change >0.1 in some of the yy values. You could presumably find other functions (or perhaps even other measurement locations for sin) and come to the opposite conclusion.

That said, if you happen to know that Dierckx and Interpolations are nominally computing the same thing (i.e., are supposedly using the identical interpolant), and yet we're arriving at different answers, that indicates a bug somewhere.

timholy avatar Feb 04 '19 19:02 timholy

Well of course, Quite likely they are doing different things. I'm looking for fast interpolation routines in Julia, so, this is why I had a look at your routines. I'm comparing them to the Dierckx as I have used them in Python and Fortran.

I'm more worried that I don't see any difference in the two periodic conditions, that with OnCell and with OnGrid.

Cheers

egiovan avatar Feb 05 '19 15:02 egiovan

You're probably misunderstanding what those parameters do; don't worry - you're not the first one to be confused. There's some clarification in the discussion in #228, but that discussion also sort-of dies out with "we should probably find better names for these."

Basically, try a cubic b-spline with flat BC and compare the behavior between OnCell and OnGrid. IIRC, the OnCell variant should be flat at x == 0.5 (i.e. a half-width outside the first data point) and the OnGrid should be flat at x == 1 (i.e. exactly on the first data point).

tomasaschan avatar Feb 05 '19 15:02 tomasaschan