bugGNU Octave - Bugs: bug #61340, [octave forge] (splines) csaps...

 
 

bug #61340: [octave forge] (splines) csaps 'nonconformant argument' errors from unhandled inputs expected for matlab compatibility.

Submitter:  Nicholas Jankowski <nrjank>
Submitted:  Fri 15 Oct 2021 03:30:52 PM UTC
   
 
Category:  Octave Package Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Nicholas Jankowski Open/Closed:  * Open
Release:  * 6.3.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 16 Oct 2021 10:56:49 PM UTC, comment #3: 

I committed a change to give an error if the input p isn't a scalar [1]. If someone wants to add the ability to handle non-scalar p similarly to Matlab, that would be welcome.

[1] https://sourceforge.net/p/octave/splines/ci/df5c271a9b3071c2cadd19553c2a07dd4d06f1c0/

Nir Krakauer <nir_krakauer>
Fri 15 Oct 2021 04:50:02 PM UTC, comment #2: 

the comment #0 code fails on line 108, which is:


u = (6*(1-p)*QT*diag(1 ./ w)*QT' + p*R) \ (QT*y);

 whos p QT w R y
Variables visible from the current scope:

   Attr Name        Size                     Bytes  Class
   ==== ====        ====                     =====  =====
    f   p           1x21                       168  double
        QT         19x21                      1088  double
    f   w          21x1                        168  double
        R          19x19                      1040  double
    f   y          21x1                        168  double


the QT*diag(1./w)*QT' part is fine, but then the (1-p)*ans part produces

error: operator *: nonconformant arguments (op1 is 1x21, op2 is 19x19)

looking at this, i realize it expects p to be a constant to set the smoothing parameter. Octave's implementation does not accept other types of this parameter.  from the matlab help:

"p — Smoothing parameter
scalar in the range [0,1] | vector | cell array | empty array

Smoothing parameter, specified as a scalar value between 0 and 1 or as a cell array of values for multivariate data. You can also specify values for the roughness measure weights λ by providing p as a vector. To provide roughness measure weights for multivariate data, use a cell array of vectors. If you provide an empty array, the function chooses a default value for p based on the data sites x and the default value of 1 for the roughness measure weight λ."


ok, so that at least narrows down these errors as being related to csaps not accepting the full range of input types now supported by Matlab's csaps. The lack of input type checking allows the inputs to propagate through and create the nonconformant arguments error messages

Retitling to better capture the issue, changed the category.

recommended short fix:  improve usability by adding input type checks and more useful error messages

recommended long fix:  implement the missing matlab compatible input handling options.




Nicholas Jankowski <nrjank>
Group Member
Fri 15 Oct 2021 03:58:24 PM UTC, comment #1: 

trying another example from the function help page, I'm getting a nonconformant argument error from a different part of the code:


x = {linspace(-2,3,51),linspace(-3,3,61)};
[xx,yy] = ndgrid(x{1},x{2});
y = peaks(xx, yy);
noisy = y + (rand(size(y)) - 0.5);
[sval,p] = csaps(x,noisy,[],x);
error: horizontal dimensions mismatch (2x1 vs 1x1)
error: called from
    csaps at line 78 column 3


note that line 78 is an input 'isnan' check.  the function starts with:


  if(nargin < 5)
    w = [];
    if(nargin < 4)
      xi = [];
      if(nargin < 3)
              p = [];
      endif
    endif
  endif

  if(columns(x) > 1)
    x = x';
    y = y';
    w = w';
  endif

  if any (isnan ([x y w](:)) )
    error('NaN values in inputs; pre-process to remove them')
  endif


and the nonconformant argument occurs on the if any isnan check.  w is set to [],  x is a 2x1 cell array, and y is a 61x51 double array.

so [x y w] obviously fails.

according to the matlab doc,  x is permitted to be:

x — Data sites
vector | cell array
Data sites of data values y to be fit, specified as a vector or as a cell array for multivariate data. Spline f is created with knots at each data site x such that f(x(j)) = y(:,j) for all values of j.

For multivariate, gridded data, you can specify x as a cell array that specifies the data site in each variable dimension...


so it appears this is a separate issue, as reading the Octave csaps help it's simply not set up to handle cell array inputs.   This doesn't explain the comment #0 issue though, where the inputs are arrays.


Nicholas Jankowski <nrjank>
Group Member
Fri 15 Oct 2021 03:30:52 PM UTC, original submission:  

One of the matlab example scripts for the csaps function throws a nonconformant argument error when run in Octave 6.3.0, splines 1.3.4:

2nd example from https://www.mathworks.com/help/curvefit/csaps.html


x = linspace(0,2*pi,21); y = sin(x)+(rand(1,21)-.5)*.3;
pp = csaps(x,y,0.4,[],[ones(1,10),repmat(5,1,10), 0]);
pp1 = csaps(x,y, [.4,ones(1,10),repmat(.2,1,10)], [], ...
                    [ones(1,10), repmat(5,1,10), 0]);
x = linspace(0,2*pi,21); y = sin(x)+(rand(1,21)-.5)*.3;
pp = csaps(x,y,0.4,[],[ones(1,10),repmat(5,1,10), 0]);
pp1 = csaps(x,y, [.4,ones(1,10),repmat(.2,1,10)], [], [ones(1,10), repmat(5,1,10), 0]);
figure
hold on
fnplt(pp, 'b');
fnplt(pp1,'r--')
plot(x,y,'ok')
hold off
ylim([-1.5 1.5])
title(['Cubic smoothing spline, with right half treated differently'])
legend('pp Larger error weight', 'pp1 Larger error and smaller roughness weight')

results in the attached figure comparing pp to pp1

in Octave, I get:

pkg load splines
x = linspace(0,2*pi,21); y = sin(x)+(rand(1,21)-.5)*.3;
pp = csaps(x,y,0.4,[],[ones(1,10),repmat(5,1,10), 0]);
pp1 = csaps(x,y, [.4,ones(1,10),repmat(.2,1,10)], [], ...
                    [ones(1,10), repmat(5,1,10), 0]);

error: operator *: nonconformant arguments (op1 is 1x21, op2 is 19x21)
error: called from
    csaps at line 108 column 5




Nicholas Jankowski <nrjank>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #52102:  matlabCSAPS.png added by nrjank (19KiB - image/png)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by nir_krakauer (Posted a comment)
  • -email is unavailable- added by nrjank
  • -email is unavailable- added by nrjank (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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-10-15 nrjank Carbon-Copy- Added -email is unavailable-
    2021-10-15 nrjank Severity3 - Normal 2 - Minor
        Item GroupUnexpected Error or Warning Matlab Compatibility
        StatusNone Confirmed
        Summary[octave forge] (splines) csaps produces nonconformant arguments error for valid input [octave forge] (splines) csaps 'nonconformant argument' errors from unhandled inputs expected for matlab compatibility.
    2021-10-15 nrjank Attached File- Added matlabCSAPS.png, #52102

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code