bugGNU Octave - Bugs: bug #56582, [octave forge] (optim) lsqlin...

 
 

bug #56582: [octave forge] (optim) lsqlin produces unexpected error on linearly dependent inputs

Submitter:  Nicholas Jankowski <nrjank>
Submitted:  Fri 05 Jul 2019 08:16:05 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  None
Originator Name:  Nicholas Jankowski Open/Closed:  * Closed
Release:  * 5.1.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Tue 04 Jan 2022 07:39:33 AM UTC, comment #2: 

The original optimization problem has no single solution. According to the reported output, Matlab indicates success with the exit flag but returns NaNs as solution. For a similar problem, one element of the solution is not NaN, according to the report. None of these outputs seems right. The exit flag is supposed to indicate such problems. Returning NaNs is not necessary then. Returning a single solution out of a solution space with many solutions is not usually done by such functions, and if it is done, it makes no sense to set some elements to NaN. User code relying on some solution elements being NaN and some not is probably buggy.

The patch
https://sourceforge.net/p/octave/optim/ci/b29564bac152d65d3443b6da2b45f44d55b0b0f5/
sets an error exit flag for the condition previously causing the reported error message.

The problem with different behaviour of Matlab for rank-deficient equality constraint matrices is unrelated.

Olaf Till <i7tiol>
Group Member
Sat 06 Jul 2019 01:53:39 AM UTC, comment #1: 

checking full Matlab output for compatibility. #2 is odd:

1. Matlab:

>> C = [1,2,3;2,4,6;2,4,5];
>> D = [4 8 5]';
>> [X, RESNORM, RESIDUAL, EXITFLAG, OUTPUT, LAMBDA]=lsqlin(C,D,[],[])

X =

   NaN
   NaN
     3


RESNORM =

   NaN


RESIDUAL =

   NaN
   NaN
   NaN


EXITFLAG =

     1


OUTPUT =

  struct with fields:

         iterations: 0
          algorithm: 'mldivide'
      firstorderopt: []
    constrviolation: []
       cgiterations: []
       linearsolver: []
            message: ''


LAMBDA =

  struct with fields:

      lower: []
      upper: []
    ineqlin: []
      eqlin: []

Octave error:

error: __qp__: operator *: nonconformant arguments (op1 is 1x1, op2 is 3x1)
error: called from
    quadprog at line 352 column 36
    lsqlin at line 123 column 21


2. Matlab:

>> C=[1 2 3;4 5 6; 2 4 6];
>> D=[4 5 8]';
>> [X, RESNORM, RESIDUAL, EXITFLAG, OUTPUT, LAMBDA]=lsqlin(C,D,[],[])

X =

   NaN
   NaN
   NaN


RESNORM =

   NaN


RESIDUAL =

   NaN
   NaN
   NaN


EXITFLAG =

     1


OUTPUT =

  struct with fields:

         iterations: 0
          algorithm: 'mldivide'
      firstorderopt: []
    constrviolation: []
       cgiterations: []
       linearsolver: []
            message: ''


LAMBDA =

  struct with fields:

      lower: []
      upper: []
    ineqlin: []
      eqlin: []

Octave output:

X =

  -3.2660
   6.5320
  -3.2660

RESNORM =  105.00
RESIDUAL =

  -4.0000
  -8.0000
  -5.0000

EXITFLAG = 0
OUTPUT =

  scalar structure containing the fields:

    iterations =  200

LAMBDA = [](0x0)


3. Matlab:

>> C = [1 2 3; 4 5 6];
>> D = [4 5]';
>> A = [1 1 1;2 2 2];
>> B = [1 2]';
>> [X, RESNORM, RESIDUAL, EXITFLAG, OUTPUT, LAMBDA]=lsqlin(C,D,[],[],A,B,[],[])

Minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.

<stopping criteria details>

X =

   -0.1667
    0.3333
    0.8333


RESNORM =

     2


RESIDUAL =

   -1.0000
    1.0000


EXITFLAG =

     1


OUTPUT =

  struct with fields:

            message: '↵Minimum found that satisfies the constraints.↵↵Optimization completed because the objective function is non-decreasing in ↵feasible directions, to within the value of the optimality tolerance,↵and constraints are satisfied to within the value of the constraint tolerance.↵↵<stopping criteria details>↵↵Optimization completed: The relative dual feasibility, 9.259951e-13,↵is less than options.OptimalityTolerance = 1.000000e-08, the complementarity measure,↵0.000000e+00, is less than options.OptimalityTolerance, and the relative maximum constraint↵violation, 0.000000e+00, is less than options.ConstraintTolerance = 1.000000e-08.↵↵'
          algorithm: 'interior-point'
      firstorderopt: 4.1670e-11
    constrviolation: 0
         iterations: 1
       linearsolver: 'dense'
       cgiterations: []


LAMBDA =

  struct with fields:

    ineqlin: [0×1 double]
      eqlin: [2×1 double]
      lower: [3×1 double]
      upper: [3×1 double]


Octave error:

error: quadprog: equality constraint matrix must be full row rank
error: called from
    quadprog at line 283 column 11
    lsqlin at line 123 column 21


Nicholas Jankowski <nrjank>
Group Member
Fri 05 Jul 2019 08:16:05 PM UTC, original submission:  

from a mailing list discussion [1]:

Octave:

C=[1 2 3;4 5 6; 2 4 6]
D=[4 5 8]'
lsqlin(C,D,[],[])
error: __qp__: operator *: nonconformant arguments (op1 is 2x2, op2 is 3x1)
error: called from
    quadprog at line 351 column 32
    lsqlin at line 123 column 19


Matlab:

>> C = [1 2 3;4 5 6; 2 4 6];

>> D=[4 5 8]';

>> lsqlin(C,D,[],[])
ans =
   NaN
   NaN
   NaN


the error seems to be related to the 1st and 3rd row of C being linearly dependent.


another possibly related error output:

Octave:

C=[1 2 3;4 5 6]
D=[4   5]'
A=[1 1 1;2 2 2]
B=[1 2]'

lsqlin(C,D,[],[],A,B,[],[])
error: quadprog: equality constraint matrix must be full row rank
error: called from
    quadprog at line 282 column 11
    lsqlin at line 123 column 19


Haven't checked that output in Matlab.   In any case, mailing list suggestion is that Octave produces the NaN output like matlab rather than erroring out.  Also was suggested having an option where lsqlin removes the linearly dependent input for you, although no basis or approach for this to be done consistently and compatibly has been discussed.


[1] http://octave.1599824.n4.nabble.com/lsqlin-error-message-tp4693279.html

Nicholas Jankowski <nrjank>
Group Member

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by i7tiol (Posted a comment)
  • -email is unavailable- added by nrjank (Submitted the item)
  • -email is unavailable- added by nrjank (optim maintainer and participants in mail list discussion)
  • -email is unavailable- added by nrjank (optim maintainer and participants in mail list discussion)
  • -email is unavailable- added by nrjank (optim maintainer and participants in mail list discussion)
  •  

    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 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-01-04 i7tiol StatusNone Fixed
        Open/ClosedOpen Closed
    2019-07-05 nrjank Carbon-Copy- Added -email is unavailable-
        Carbon-Copy- Added -email is unavailable-
        Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code