How do you deal with data that you need to be monotonically increasing in order to work with interpolation libs and other functions, when it is in fact not monotonically increasing?

  • $\begingroup$ what is given, what are you looking for? $\endgroup$ – Arnold Neumaier Sep 21 '12 at 10:33
  • $\begingroup$ @ArnoldNeumaier a way to transform a non-monotonically increasing data set to make it monotonically increasing.... $\endgroup$ – pyCthon Sep 21 '12 at 16:22
  • 4
    $\begingroup$ This still doesn't make your question precise enough that one can give asensible answer. - You can make a data set monotone increasing by sorting it, but apparently this is not what you want; so you need to say what kind of problem you have and which properties must be preserved. $\endgroup$ – Arnold Neumaier Sep 21 '12 at 18:03
  • $\begingroup$ Cool ! I thought it were difficult but not at all... $\endgroup$ – user4753 Jul 11 '13 at 14:19

If you want to remove the nonmonotonic structure without changing anything else, you can do an isotonic least squares fit:


  • $\begingroup$ this is perfect! $\endgroup$ – pyCthon Sep 21 '12 at 16:20

I'm confused. Data needs not be monotonic to interpolate. (Yes, there are monotonic curve fitting tools, but that seems not to be what you are asking for.) For example (in matlab)

x = 0:20;
y = sin(x);
xi = 0:.01:20;
yi = spline(x,y,xi);

sine function

Perhaps you have a problem where the data comes from a relationship that is not single valued. As an example, points that lie around the circumference of a circle.

The problem is any function at a given value of x must yield a single prediction. But if you have a relationship that is not single valued, What can you do?

The general idea is to create a third variable, that allows you to predict x(t) and y(t) parametrically. You really need that third piece of information, as the sequence of the points is crucial. Typically one uses the cumulative chordal arc length between the points as the parameter t. Of course, in the case of a circle, one could have used polar angle as the parameter, but for the general problem the cumulative linear arc length works well.

x = rand(10,1);
y = rand(10,1);
t = [0;cumsum(diff(x).^2 + diff(y).^2)];
ti = linspace(0,t(end),1000);
xi = spline(t,x,ti);
yi = spline(t,y,ti);

random curve

  • $\begingroup$ yeah but matlab does something beneath the scenes when you fed it non-monotomically increasing data, say for instance 'y = [1,1,1,2,2,2,3,3,....]' the above will still work when for other libraries like gsl for example it fails because it doesn't do what matlab does behind the scenes $\endgroup$ – pyCthon Sep 21 '12 at 2:57
  • $\begingroup$ IF you intend to interpolate y(x), where x is an increasing vector and y is as indicated, y = [1,1,1,2,2,2,3,3,....], then ANY interpolant will work (although it may exhibit ringing.) This is no problem. If you have replicate values for the independent variable, thus x, then the code can either error out or it may choose to average the values for y at those points. (interp1 errors out.) I still see no problem. If x elements are replicated, then what prediction for a multi-valued function do you wish the interpolant to return? $\endgroup$ – user840 Sep 21 '12 at 14:31
  • $\begingroup$ If your problem is how do you average those y values at a replicated x, then use my consolidator tool, designed to solve exactly this problem. mathworks.com/matlabcentral/fileexchange/8354-consolidator $\endgroup$ – user840 Sep 21 '12 at 14:33

You can use parametric interpolation methods to fit a curve through a sequence of given data points $(x_i,y_i)$ where $x_i$ does not necessarily have to be less than $x_{i+1}$: http://www.ams.org/journals/mcom/1997-66-217/S0025-5718-97-00796-5/

  • $\begingroup$ I don't mind being downvoted. I'd appreciate an explanation though... $\endgroup$ – Paul Jul 14 '13 at 17:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.