I redid all of my graphs, over 100 curves total. Either 1D or 2D worked well in most cases. I defaulted to 1D because some curves had odd artifacts in 2D. I did find one curve where the data wasn't inherently smooth and 2D worked best. Linear interpolation was best for very dense curves (hundreds of points) and for connecting a few plotted data points with straight lines to emphasize the sparse sampling. It's nice to have a choice of interpolation method.

Brian

]]>maybe we (at least me and Brian) just don't know what is the 2-D cubic spline suitable for. But one thing is sure: if you add one, (or better several) cubic splines of the 1-dimensional types (including the so called "natural" one - described for instance in the above wikipedia link) -- then everybody will be happy, and no more questions will arise.

]]>The normal 1-dimensional cubic spline does not work for my goal in all cases so I used the 2-dimensional variation instead. It is basically a parametric function where both x(t) and y(t) is interpolated as cubic splines.

I think I first saw it at MathWorld:

http://mathworld.wolfram.com/CubicSpline.html

There is also an interactive Java applet here:

http://www.cse.unsw.edu.au/~lambert/spl … cubic.html

But I understand that other people have other goals. It was always my intention to add more interpolation algorithms, but no matter how many I add there will always be some complaining that I have not implemented their favorite variation. However I will consider adding 1-dimensional cubic splines.

]]>I just informed myself a bit more about cubic spline interpolation. You see, there are indeed very many variations of cubic splines.

But I agree with you that the one provided by Ivan does not behave in the most expected way. For instance, I repeated the interpolation provided at http://en.wikipedia.org/wiki/Interpolation , at the end of the article (the 3 points interp. ) and "Graph" give "strange" results in comparison with the Natural type (see wiki) of cubic spline.

Thanks for pointing out; I will also write to Ivan.

]]>I have now been looking into this and there doesn't seem to be any bugs in the implementation of cubic splines in Graph. The difference in the image shown is because Graph uses 2-dimension cubic splines as opposed to 1-dimension cubic splines. The 2-dimension splines seem to work much better than 1-dimension and will therefore be kept as it is for now. More types of interpolation may be added in the future.

Ivan, I just made some little research about cubic spline interpolation. So, what do you mean by 1-dimensional and 2-dimensional cubic splines? Did you actually intend to interpolate a third variable, like z=f(x,y)? That could be the issue then.

Please see http://docs.scipy.org/doc/scipy/referen … olate.html , or other.

Also, some other simple cubic spline (called 'natural') do interpolate, indeed, in a more expected way. http://en.wikipedia.org/wiki/Spline_interpolation (I tried the example there in the end with 3 points); also read the 3rd external link in the same wiki page.

Another way to state my objection is that most commonly encountered processes are low-order. They are inherently smooth. Attempting to model them as high-order processes will yield invalid and misleading results unless you have a lot of data samples. Graph's interpolation acts as if its model order were much higher than that of ordinary cubic spline interpolation. It yields curves that are less smooth, change more abruptly, and are more like connecting the dots with linear interpolation. Commonly encountered data isn't like that.

Before I wrote my own cubic spline interpolator, whenever I encountered problems with Graph's cubic spline I would simply plot the data points as dots and use Graph's linear interpolation to connect them. The resulting curve wasn't at all smooth, but the obvious straight-line segments and the visible dots provided immediate visual clues about the nature of the model. Anyone looking at the plot could immediately grasp what had been done without obtaining a false impression. They realized that the data wasn't really piecewise linear. But when I simply used Graph's cubic spline to plot a curve without marking the data points, the unavoidable impression was that the data followed the curve as shown. In fact, in some places it wasn't near the curve at all, but the user had no way to know this.

Ivan could keep his program from plotting misleading curves by simply offering ordinary cubic spline interpolation as an option.

Brian

]]>Brian

]]>The red curve seems to be a much better interpolation of the four points than the blue. The blue curve overshoots heavily.

))

Good reply, Ivan.

]]>Ivan, I just used a sine wave as an example. I am not creating a function. I am sampling a known function so that it is easy to tell whether the interpolation is reasonable. The defects I've highlighted apply to any function or curve. They are not unique to sine waves. They apply also to measured data, as shown in my first example.

The interpolation method you are using does not yield curves that make sense, curves that are useful for obtaining accurate values between the points supplied, or curves that are mathematically correct. The method as implemented is entirely bogus. It is bizarre. It does not always yield single-valued functions. It bears no relation to a proper interpolation, whether you choose to use the name cubic spline or call it something else. No one who uses cubic spline interpolation in Graph can trust the outcome. It can give such crazy results that it is impossible to predict what it might do. That's why I offered my external interpolation utility. You must export data to it and then import the interpolated points, but at least it gives valid results. It would be so much easier if Graph would simply do it all internally. What would be so hard about that?

All you need to create a useful cubic spline interpolation is to use the code I sent you. It is standard code. I have used it for years in several different programs without any problems or weird results whatsoever. Call it spline1 and call the method you now use spline2. At least give users a choice.

I have no idea why you are unable to understand this issue. Just look at the examples I've provided and use common sense.

Brian

Brian, those exactly same 3 or points could have been from a different function, not sine function. Then what, would you expect that an interpolation method in one case will resemble to sine function, in other case--to another function??? Think about it! Interpolation methods are not intended to give the original function, but, as Ivan pointed, just to give a function that satisfies some smoothness conditions. That's all! Only in case you provide more and more points, the method will begin to give a graph close to the original particular function.

Read more about interp. on wiki...

I've updated the program at the URL given earlier.

Adding normal cubic spline interpolation to Graph would allow users to plot coarsely or unevenly sampled data without generating funny curves. Adding optional clipping thresholds for all interpolation methods would permit it to generate realistic curves for data with natural saturation.

Brian

]]>I use Graph to draw plots of measured data from my electronics hobby. I take manual readings from lab instruments, both analog and digital, and then use Graph to plot the points. Due to time constraints, I can't always collect as many samples as I'd like. Sometimes I sample outlier points just to complete a curve. I rely on smooth interpolation to fill in the missing data. The problem with Graph's interpolation is that you can't trust it to do a reasonable job of filling in missing points. It can generate funny curves that are nothing like the underlying process you've measured. But ordinary cubic spline interpolation works in these cases.

If you want to keep the current Graph interpolation, I strongly recommend that you add standard cubic spline interpolation that a user can invoke when necessary. Users will have to determine for themselves when to use one interpolation or another, but at least they will have the option of plotting correct, valid curves.

Cubic spline interpolation smooths a curve by making certain assumptions about the first and second derivatives of the underlying function that the data represents. Sometimes real data does not conform to those assumptions. For example, some of the electrical signals I measure may saturate. The plotted curve suddenly becomes a constant value. The circuits are operating correctly but they exhibit discontinuous or nonsmooth derivatives. Any cubic spline interpolation may generate nonconstant interpolated values over a region of constant data due to the influence of adjacent regions. Usually the error is small, but the deviation of a nonflat curve can obscure the underlying saturation, which may be entirely normal. The user is left to explain the unexpected behavior exhibited by the plot. I have added an option to my cubic spline interpolator that enables it to preserve saturated data values. See the next message. If you implement a standard cubic spline interpolation, you might consider adding such a feature. It is not often needed, but it can make the interpolation model more realistic for some data.

Brian

]]>The interpolation method you are using does not yield curves that make sense, curves that are useful for obtaining accurate values between the points supplied, or curves that are mathematically correct. The method as implemented is entirely bogus. It is bizarre. It does not always yield single-valued functions. It bears no relation to a proper interpolation, whether you choose to use the name cubic spline or call it something else. No one who uses cubic spline interpolation in Graph can trust the outcome. It can give such crazy results that it is impossible to predict what it might do. That's why I offered my external interpolation utility. You must export data to it and then import the interpolated points, but at least it gives valid results. It would be so much easier if Graph would simply do it all internally. What would be so hard about that?

All you need to create a useful cubic spline interpolation is to use the code I sent you. It is standard code. I have used it for years in several different programs without any problems or weird results whatsoever. Call it spline1 and call the method you now use spline2. At least give users a choice.

I have no idea why you are unable to understand this issue. Just look at the examples I've provided and use common sense.

Brian

]]>