Michael Godfrey | 19 Aug 2012 19:18
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #27, bug #36732 (project octave):

An example of a X pair is:
interp1 ([1,2,2,3,4],[0,1,4,2,1],[-1,1.5,2,2.5,3.5], "linear", "extrap")

In X = [1,2,2,3,4] 2,2 is a pair.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/

Ben Abbott | 19 Aug 2012 19:57
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #28, bug #36732 (project octave):

Michael, are you working on a changeset, or should interp1 already handle the
right-continuous / left-continuous behavior correctly with Vivek's changeset
reverted?

I tried the example below, but get the same curve twice.

x = [1, 2, 3, 3, 4, 5];
y = [1, 2, 2, 4, 4, 5];
a = 1:5;
plot (a, interp1 (x, y, a))

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/

Michael Godfrey | 19 Aug 2012 20:21
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #29, bug #36732 (project octave):

Ben, 

What I am working on now is the test for
non-contiguous, identical values in X.

This was the original bug report. Otherwise,
the original code seems correct.  My last
patchs just correct the documentation.

Your test for any duplicate values is
overkill unless Matlab compatibility is
required.  Your test could be retained as
a warning of Matlab incompatiblity.

OK?

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>

_______________________________________________
  Message sent via/by Savannah
(Continue reading)

Michael Godfrey | 19 Aug 2012 23:16
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #30, bug #36732 (project octave):

I noticed an added feature of interp1 which appears
not to be documented:  The X vector is sorted before
the interpolation is done.  This surely added to
the confusion following the original bug report.

For now, I have put the tests for distinct and
duplicated values ahead of the sort.  But, it may
make sense, once users realize that X is sorted, to
put the test after the sort.

Anyhow, the tests now seem to work.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/

Ben Abbott | 19 Aug 2012 23:39
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #31, bug #36732 (project octave):

Michael,

I had omitted an important part of the demo

 clf
 xi = [1, 2, 3, 3, 4, 5];
 yi = [1, 2, 2, 4, 4, 5];
 x = 1:0.01:5;
 plot (x, interp1 (xi, yi, x),
       fliplr (x), interp1 (xi, yi, fliplr (x)))

Should this example produce a single curve, or should the ascending curve
produce a different result as compared to the descending curve?

From comment #24, I had thought you intended that ascending values of x would
use interp1 ([1, 2, 3, 4, 5], [1, 2, 2, 4, 5], x) and descending values of x
would use interp1 ([1, 2, 3, 4, 5], [1, 2, 4, 4, 5], x).

I assume my inference was incorrect.

Regarding the sorting, Matlab does this as well.

interp1 ([1, 3, 2, 5, 4], [1, 3, 2, 5, 4], 1:5)

(Continue reading)

Michael Godfrey | 19 Aug 2012 23:57
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #32, bug #36732 (project octave):

Ben,

About the demo:  It looks plausible, but
I have only glanced at it.  Matlab cannot do it, of course.

I just did the test for noncontiguous values, but
your code looks more compact, so I will try it.

But, what is the answer to where the code should go:
before or after sorting X?  Technically, it seems to
me that it should go after.  But, that can (did) confure
people.

Michael

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/
(Continue reading)

Ben Abbott | 20 Aug 2012 00:09
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #33, bug #36732 (project octave):

It goes immediately after sorting X.

diff --git a/scripts/general/interp1.m b/scripts/general/interp1.m
--- a/scripts/general/interp1.m
+++ b/scripts/general/interp1.m
 <at>  <at>  -169,7 +169,7  <at>  <at> 
   endif

  ## check whether sample point  <at> var{x} are distinct; give error if not.
-  if (any (diff (x) == 0))
+  if (any ((diff (x(1:(end-1))) == 0) & (diff (x(2:end)) == 0)))
     error ("interp1: X should have distinct values");
   endif

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/

(Continue reading)

Michael Godfrey | 20 Aug 2012 01:53
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #34, bug #36732 (project octave):

Agreed about after sorting.  
I would only suggest a somewhat clearer error:

  error ("interp1: X must have at most one pair of non-distinct values");

 
But, now that I look at it more carefully, it does not look
like your patch does this.  Or, am I wrong?

Anyhow, my version gives a warning for non-distinct pairs,
and errors for more non-distincts than 2.

Do you want to see it?

Michael

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>

_______________________________________________
  Message sent via/by Savannah
(Continue reading)

Ben Abbott | 20 Aug 2012 02:10
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #35, bug #36732 (project octave):

Yes. Please attach it.

Also, I'm not sure I understand by what you mean by "non-distinct values".

My thought was that there may be no more than two repeated x-values.  Are you
saying that for any x-value there may not be more than two distinct y-values?

Meaning that x = [1 2 2 2 2 3] and y = [1 2 3 4 5 6] is invalid, but x = [1 2
2 2 2 3] and y = [1 2 2 3 3 6] in ok?

I was thinking both of those would produce an error, but x = [1 2 2 3] and y =
[1 2 3 6] would be ok.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/

(Continue reading)

Michael Godfrey | 20 Aug 2012 03:46
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #36, bug #36732 (project octave):

About non-distinct points, I am assuming that the
Manual is correct. It says in Section 29.1:

Duplicate points in x specify a discontinuous interpolant. There should be at
most
2 consecutive points with the same value. The discontinuous interpolant is
rightcontinuous
if x is increasing, left-continuous if it is decreasing. Discontinuities are
(currently) only allowed for "nearest" and "linear" methods; in all other
cases, x
must be strictly monotonic.

My current patch is attached.

(file #26395)
    _______________________________________________________

Additional Item Attachment:

File name: interp1.diff                   Size:4 KB

    _______________________________________________________

Reply to this item at:
(Continue reading)

Francesco Potortì | 20 Aug 2012 10:53
Picon

Re: [bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

>About non-distinct points, I am assuming that the
>Manual is correct. It says in Section 29.1:
>
>Duplicate points in x specify a discontinuous interpolant. There should
>be at most 2 consecutive points with the same value.

Most probably, this means that, once the X are sorted, any repeated
points should be in couples (i.e. three consecutive repeated points are
not allowed), but there is no limit on the number of couples.

>The discontinuous interpolant is rightcontinuous if x is increasing,
>left-continuous if it is decreasing. Discontinuities are (currently)
>only allowed for "nearest" and "linear" methods; in all other cases, x
>must be strictly monotonic.

This makes little sense, because X is sorted in increasing order anyway.
Maybe this was a comment written at a time when there was no sorting in
place.

--

-- 
Francesco Potortì (ricercatore)        Voice:  +39.050.315.3058 (op.2111)
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Fax:    +39.050.315.2040	 
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it

(Continue reading)

Francesco Potortì | 20 Aug 2012 13:18
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #37, bug #36732 (project octave):

>About non-distinct points, I am assuming that the Manual is correct. It says
in Section 29.1:
>
>Duplicate points in x specify a discontinuous interpolant. There should be at
most 2 consecutive points with the same value.

Most probably, this means that, once the X are sorted, any repeated points
should be in couples (i.e. three consecutive repeated points are not allowed),
but there is no limit on the number of couples.

>The discontinuous interpolant is rightcontinuous if x is increasing,
left-continuous if it is decreasing. Discontinuities are (currently) only
allowed for "nearest" and "linear" methods; in all other cases, x must be
strictly monotonic.

This makes little sense, because X is sorted in increasing order anyway.
Maybe this was a comment written at a time when there was no sorting in place,
which would also explain the reason why the text requires monotonicity.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>
(Continue reading)

Michael Godfrey | 20 Aug 2012 13:41
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #38, bug #36732 (project octave):

Francesco,

Your comments seem right except for the fact that
the sort may be in either increasing or decreasing
order.  This may explain the part about right or left
continuity.

The current patch allows more than one equal pair,
but issues a warning that this is "not compatible."

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/

Ben Abbott | 20 Aug 2012 14:23
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #39, bug #36732 (project octave):

I had inferred the "increasing" / "decreasing" values referred to the "xi"
values (i.e. interp1 (x, y, xi)).

Francesco's thought that they referred to the "x" values prior to the sorting
makes more sense.

We'll need another changeset to fix the manual, correct?

The "distinct" language troubles me since Octave has a "unique()" function. 
The use of "distinct" infers to me that it means something different than
"unique".  Is there a reason why "distinct" is being used as opposed to
"unique"?

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/

(Continue reading)

Michael Godfrey | 20 Aug 2012 14:38
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #40, bug #36732 (project octave):

The only change that I think may be needed
in the Manual would be to explain the sorting.
This should probably go in the help text too.

Do you think of other needed changes?

I will take a look at this soon.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/

Ben Abbott | 20 Aug 2012 14:55
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #41, bug #36732 (project octave):

I was referring to the part below.

"The discontinuous interpolant is right-continuous if x is increasing,
left-continuous if it is decreasing."

There is no difference between right and left-continuous interpolants correct?

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/

Michael Godfrey | 20 Aug 2012 15:03
Picon

[bug #36732] interp1 does not check input for monotonicity

Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only
notification stream.  Info posted to this mailing list address won't appear in the tracker database where
it is most useful.

Follow-up Comment #42, bug #36732 (project octave):

There is no difference between right and left-continuous interpolants
correct?

This is just due to whether the sort was assending or decending.
It should all be symmetrical.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36732>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/


Gmane