lsqlin() error message

classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

lsqlin() error message

GoSim
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



it is because two rows in C and D are linearly dependent, row 1 and 3 in
this case.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

GoSim
if I do this it works:

C=[1 2 3; 2 4 6]
D=[4  8]'
lsqlin(C,D,[],[])
ans =

  -3.7616
  -8.8628
   7.1624


it still has two linearly dependent rows, maybe because the rows are after
eachother it works?



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

GoSim
In reply to this post by GoSim
C=[1 2 3; 2 4 6;4 5 6]
D=[4  8 5]'
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



changed rows and gives error again. Anyway, I would appreciate if you fixed
it.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

Doug Stewart-4


On Fri, Jul 5, 2019 at 4:58 AM GoSim <[hidden email]> wrote:
C=[1 2 3; 2 4 6;4 5 6]
D=[4  8 5]'
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



changed rows and gives error again. Anyway, I would appreciate if you fixed
it.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



You should be watching the EXITFLAG


--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

Olaf Till-2
In reply to this post by GoSim
On Fri, Jul 05, 2019 at 03:33:24AM -0500, GoSim wrote:

> C=[1 2 3; 2 4 6;4 5 6]
> D=[4  8 5]'
> 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
>
>
>
> changed rows and gives error again. Anyway, I would appreciate if you fixed
> it.
How does Matlabs lsqlin behave if given the 'C' from your examples?

Olaf

--
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net



signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

GoSim
In reply to this post by Doug Stewart-4
[X, RESNORM, RESIDUAL, EXITFLAG]=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



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

GoSim
In reply to this post by Olaf Till-2
Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

GoSim
In reply to this post by Doug Stewart-4
more outputs gives the same error:

[X, RESNORM, RESIDUAL, EXITFLAG, OUTPUT, LAMBDA]=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



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

Ardid, Salva
In reply to this post by GoSim

El divendres, 5 de juliol de 2019, a les 7:58:14 EDT, GoSim va escriure:

  I don't have Matlab.
 
 
 
  --
  Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

For the case it is useful, in Matlab 2019a:

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

C =

     1     2     3
     4     5     6
     2     4     6

>> D=[4 5 8]'

D =

     4
     5
     8

>> lsqlin(C,D,[],[])

ans =

   NaN
   NaN
   NaN
 
 
 




Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

GoSim
Thanks.

this could be something:

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

mldivide(D,C)
ans =

   0.38095   0.61905   0.85714

mldivide(C,D)
warning: matrix singular to machine precision
ans =

  -1.55556
   0.11111
   1.77778



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

GoSim
In reply to this post by Ardid, Salva
C=[1 2 3;4 5 6]
D=[4   5]'
lsqlin(C,D,[],[])
ans =

   2.4495
  -4.8990
   2.4495


removing the linearly dependent rows makes it work. So the algorithm should
remove rows which are linearly dependent is a solution idea.
But if the matrix is only two rows which are lin. dependent it works... so
this is a really nice bug. This error message has appeared to me for a long
time and I finally could recreate it.




--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

nrjank
In reply to this post by Ardid, Salva
On Fri, Jul 5, 2019, 8:27 AM Ardid, Salva <[hidden email]> wrote:

El divendres, 5 de juliol de 2019, a les 7:58:14 EDT, GoSim va escriure:

  I don't have Matlab.



  --
  Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

For the case it is useful, in Matlab 2019a:

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

C =

     1     2     3
     4     5     6
     2     4     6

>> D=[4 5 8]'

D =

     4
     5
     8

>> lsqlin(C,D,[],[])

ans =

   NaN
   NaN
   NaN



Ok so it appears the compatibility bug is that MATLAB produces a non-error output of NaNs, and Octave throws an error when the inputs are not linearly independent.  Might be worth playing around with the MATLAB outputs a bit more to see if there are any other corner cases octave doesn't capture. 

Whether or not to add a noncompatible flag to have octave clip out the linearly dependent input as per GoSim's suggestion may warrant further discussion.



Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

GoSim
nrjank wrote
> Whether or not to add a noncompatible flag to have octave clip out the
> linearly dependent input as per GoSim's suggestion may warrant further
> discussion.

First make lsqlin give NaN in these cases instead of error. Then if lsqlin
gives NaN try to remove lin. dependent rows and try again.
Like this there is no need to always look for lin. dependent rows.

Matlab should do this too.

But it could be something else because when two lin. dependent rows were the
only two inputs it worked.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

GoSim
In reply to this post by GoSim
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


This is a similar thing. Not as severe. I would remove lin. dependent rows.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

Doug Stewart-4


On Fri, Jul 5, 2019 at 2:19 PM GoSim <[hidden email]> wrote:
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


This is a similar thing. Not as severe. I would remove lin. dependent rows.


I have a suggestion for you. make your own file that removes lin dependent rows and then calls lsqlin.


 

--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html




--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

GoSim
I have already done it in the case of equality constraint matrices. Because
Octave gave an error message that said something.
In the other case I didn't know why this error appeared. Just tried to give
some info to whoever does the optim package.



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

nrjank
On Fri, Jul 5, 2019 at 3:08 PM GoSim <[hidden email]> wrote:
I have already done it in the case of equality constraint matrices. Because
Octave gave an error message that said something.
In the other case I didn't know why this error appeared. Just tried to give
some info to whoever does the optim package.


since I don't know anything specific about the desired operation of the lsqlin function, I'll just mention that there are a lot of things we think Matlab should do. That said, m-code compatibility is one of the primary objectives of Octave, so the primary task should probably be to remove the error and ensure the NAN output, as you said.  Octave does have code and other options that extend functionality beyond what Matlab does. it's possible this could be one of those cases, but only if mathematically justified within the function. 


Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

nrjank
bug 56582 submitted to capture at least the non-compatible error 


Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

GoSim
In reply to this post by GoSim
I tried to create a username in savannah 20 times but evidently I need a
password from Mars so I will just write my ideas here.

To the maintainer of optim:

Best solution: remove lin. dependent rows and keep lsqlin working even if
e.g. two of the same linear combinations are filled in.

Second best solution: Do like Matlab but also write an error/warning so the
user understands why he gets NaN. Lsqlin is very powerful and it is hard to
understand that such a small thing can make it fail.

Worst solution: just like Matlab

Experimental solution: identify lin. dependent rows and to all but one of
them add a very small white noise. The idea is that if you have many linear
combinations that are the same this means something, it should be weighted.
So by keeping them and adding a very small noise maybe the algorithm can
handle it and it will be weighted.

Thanks for optim, I use it often.  



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: lsqlin() error message

nrjank
On Fri, Jul 5, 2019 at 7:00 PM GoSim <[hidden email]> wrote:
I tried to create a username in savannah 20 times but evidently I need a
password from Mars so I will just write my ideas here.

I have a fairly simple (as far as they go) password for savannah, so not sure what the issue is.  you can always comment anonymously on that bug report if login remains an issue. I think you'll still get directly copied on replies since I added your email.
 
To the maintainer of optim:

(CC'd here)
 
Best solution: remove lin. dependent rows and keep lsqlin working even if
e.g. two of the same linear combinations are filled in.

Second best solution: Do like Matlab but also write an error/warning so the
user understands why he gets NaN. Lsqlin is very powerful and it is hard to
understand that such a small thing can make it fail.

Worst solution: just like Matlab

Experimental solution: identify lin. dependent rows and to all but one of
them add a very small white noise. The idea is that if you have many linear
combinations that are the same this means something, it should be weighted.
So by keeping them and adding a very small noise maybe the algorithm can
handle it and it will be weighted.

Thanks for optim, I use it often.   


Matlab non-compatibility is generally considered a bug for Octave. so i would think your best solution would only be an possibility after quite a bit of discussion regarding deliberately breaking m-code compatibility. Emulating Matlab output would be a baseline. Adding a warning could still be ok I think. an error would break execution, so probably not. An optional flag or setting to enable one of the fixes you suggest could be ok, as it would extend Octave beyond matlab while maintaining compatibility. BUT the change would need to be mathematically justified. Do we know what algorithm matlab uses? they give a reference [1], why does it produce a NaN? Perturbing the inputs without user notification would require significant mathematical justification. 



12