bugGNU Octave - Bugs: bug #41980, interp1: piecewise linear...

 
 

bug #41980: interp1: piecewise linear interpolation with discontinuities behaves differently

Submitter:  Mike Miller <mtmiller>
Submitted:  Thu 27 Mar 2014 06:43:56 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 3.8.1 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sun 06 Apr 2014 07:38:07 PM UTC, comment #9: 

I fixed up the tests to match the new interp1 behavior around discontinuities and checked in Juan's changeset here (http://hg.savannah.gnu.org/hgweb/octave/rev/5fe907167520).

Rik <rik5>
Group administrator
Mon 31 Mar 2014 03:08:56 PM UTC, comment #8: 

Works for me too, thanks for coming up with a fix so quickly. I know it's not Matlab compatible but it is quite useful, and definitely used by the signal package.

Maybe some tests should be added also for this case to capture this extension behavior so we don't lose it again. I'll try to look at it later today.

Mike Miller <mtmiller>
Group Member
Mon 31 Mar 2014 03:01:38 PM UTC, comment #7: 

The patch seems to work.  Although running 'test interp1' now fails.  Perhaps the %!tests need to be updated to reflect the new behavior around discontinuities?

Rik <rik5>
Group administrator
Sun 30 Mar 2014 09:41:37 PM UTC, comment #6: 

This patch fixes the problem reported by Mike.

The following examples work fine

x = [0 1 1 2 2 3]
y = [-1 0 1 2 3 4]';
y2= [-1 0 1 2 3 4; -1 1 2 2 3 4]';
xi = linspace (0, 3, 1000)';
yi = interp1 (x, y, xi);
plot(xi,yi,'-',x,y,'.')
pause
yi = interp1 (x, y2, xi);
plot(xi,yi,'-',x,y2,'.')

Patch attached


(file #31081)

Juan Pablo Carbajal <juanpi>
Group Member
Sun 30 Mar 2014 08:30:20 PM UTC, comment #5: 

This is what I suspected.  Matlab has a 'strictly monotonic' requirement and does not support discontinuities.  Since Octave doesn't have to conform to Matlab in this regard I think we are free to choose our own behavior.

@Juan:  I'm not sure there is anything to fix.  The behavior changed from 3.6.4 to handle discontinuities.  We added options like 'left' or 'right' for fine-grained control of this behavior.  Perhaps all we need to do is add a note in the NEWS section describing the added functionality, rather than removing it.

Rik <rik5>
Group administrator
Sun 30 Mar 2014 08:26:54 PM UTC, comment #4: 

It seems ML doesn't handle discontinuities. I checked that all my comments regarding discontinuities are already in place in interp1-m. I will fix the regression I introduced.



Juan Pablo Carbajal <juanpi>
Group Member
Sun 30 Mar 2014 08:20:29 PM UTC, comment #3: 

I checked with Matlab R2013b, and interp1() gave the error below.


Error using griddedInterpolant
The grid vectors are not strictly monotonic increasing.

Error in interp1 (line 191)
        F = griddedInterpolant(X,V,method);


Ben Abbott <bpabbott>
Group Member
Sun 30 Mar 2014 08:07:22 PM UTC, comment #2: 

This might be a regression, introduced trying to fix the function for multiple inputs. I am checking if I can fix this. However:

The data x,y doesn't define a function. There are two different outputs for the same input. So linear interpolation is not defined, one could approximate, but not interpolate. Now approximation is not the work of interp1 (optim-interp or regression functions would do the trick).

You case could be handled with "nearest", but what happens when there are more than two values of the output for the same input?

I guess one could first check that the data is indeed discontinuous and not noisy data, by checking that there are no more than 2 equal x values with different y values. And then break the data into those points and produce independent polynomials for each segment.

What does matlab do?


Juan Pablo Carbajal <juanpi>
Group Member
Sat 29 Mar 2014 07:20:08 PM UTC, comment #1: 

I added Juan and Ben to the CC list for this bug.  I think the problem was introduced earlier when Ben Abbott added handling of discontinuous inputs.  Bug #40825 was really just an amendment of that existing discontinuity code to handle multiple columns.

Rik <rik5>
Group administrator
Thu 27 Mar 2014 06:43:56 PM UTC, original submission:  

This change in behavior may be intentional, please let me know if that's the case, but it appears like a regression to me.

In 3.6.4, something like the following worked very nicely:


x = [0 0.5 0.5 1]';
y = [0 0 1 1]';
xi = linspace (0, 1, 1000)';
yi = interp1 (x, y, xi);
isequal (yi, [zeros(500,1); ones(500,1)])
ans =  1


This is no longer possible in 3.8. Now the point (0.5,0) is removed from the input set before interpolating, so the resulting line segments are from (0,0) to (0.5,1) and from (0.5,1) to (1,1). If the "left" option is used, the point (0.5,1) is removed instead, and the resulting two line segments are now from (0,0) to (0,0.5) and from (0,0.5) to (1,1).

It looks to me like this changed with the fix for bug #40825, so can Rik or JuanPi comment on whether this was intentional or an unfortunate side effect?

Mike Miller <mtmiller>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #31081:  interp1.patch added by juanpi (975B - text/x-patch)

 

Depends on the following items: None found

Digest:
   bug dependencies.

 

Carbon-Copy List
  • -email is unavailable- added by bpabbott (Posted a comment)
  • -email is unavailable- added by juanpi (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by rik5
  • -email is unavailable- added by rik5
  • -email is unavailable- added by mtmiller (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-04-06 rik5 StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2014-03-31 rik5 StatusNone Patch Submitted
    2014-03-30 juanpi Attached File- Added interp1.patch, #31081
    2014-03-29 rik5 Carbon-Copy- Added bpabbott
    2014-03-29 rik5 Carbon-Copy- Added juanpi
    2014-03-28 mtmiller Dependencies- bugs #41958 is dependent

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code