lsqlin() error message

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

Re: lsqlin() error message

GoSim
I am not writing this because I want Octave devs to do my job but because I
like Octave and want it to be as good as possible. If I would wait for bug
fixes that maybe did what I wanted and not circumvet them I would get
nothing done.

If a function in Octave does everything that Matlab does and works in more
cases, this is compatible. Noone would complain because noone base their
code on where a function does not work. As long as the syntax is identical
it is ok.
Even if Octave would manage to implement an algorithm that is better and
gave a better result, this can be discussed, but noone would complain. It's
just sad that you have to copy even where the Matlab functions are weak if
it is easy to fix.

I understand that it is a delicate thing since your main concept is to be
Matlab compatible and mathworks must hate you for that but making your
functions better than matlab with the same syntax should be acceptable.






--
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 Sun, Jul 7, 2019, 11:15 AM GoSim <[hidden email]> wrote:
I am not writing this because I want Octave devs to do my job but because I
like Octave and want it to be as good as possible. If I would wait for bug
fixes that maybe did what I wanted and not circumvet them I would get
nothing done.

If a function in Octave does everything that Matlab does and works in more
cases, this is compatible. Noone would complain because noone base their
code on where a function does not work. As long as the syntax is identical
it is ok.
Even if Octave would manage to implement an algorithm that is better and
gave a better result, this can be discussed, but noone would complain. It's
just sad that you have to copy even where the Matlab functions are weak if
it is easy to fix.

I understand that it is a delicate thing since your main concept is to be
Matlab compatible and mathworks must hate you for that but making your
functions better than matlab with the same syntax should be acceptable.

If you prefer a matrix math based numerical computing environment that does not place a priority on Matlab m-code compatibility, something like SciLab may be more to your liking.

In any case, step one is to review the Octave lsqlin code and figure out how to patch the current error condition.  This initial fix should be MATLAB compatible. Also notice that in one example in the bug report MATLAB does not give NAN for all outputs,  eg, it was [NaN;NaN;5].  Why? What should the algorithm be doing and how does that explain the output? Is lsqlin supposed to be invalid for linearly dependent inputs? It may require reviewing the reference cited by MATLAB on the help page.



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 05:16:54PM -0500, GoSim wrote:
> 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.

I wouldn't think this could be done in a reasonable way. If you remove
a row, you remove the influence of one squared residual, i.e. the
influence of one element of 'D'.

> 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.

Sounds good to mee.

> 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.

I wouldn't try to guess within the optimizer function how to improve
the data. This is something which should be done, if at all, before
feeding the data into the optimizer, IMHO.

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 nrjank
C=[1 2 3; 2 4 6;4 5 6;7 9 8; 5 6 4; 2 5 8]
D=[4   8 5 9 5 7 ]'

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

  -1.04718
   1.44205
   0.41128


The two first rows are lin. dependent. The algorithm seems to be sensitive
to lin. dependency when there are few rows. I have noticed this in my
algorithms with this command.

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

  -3.11111
   3.22222
   0.22222


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


Here I want lsqlin to give me 3 coeffs, when it has less than 3 lin. dep.
rows it is sensitive to lin. dependency. Maybe using lsqlin with too few
rows is a stupid thing and I am just using it incorrectly.
Least squares with less lin. independent rows than sought parameters doesn't
have a solution, but it deosn't give an error if the lin. dependent rows are
removed....I don't know. I leave it to the maintainer.

The [NaN NaN 3]' result in your bugreport I can only guess about. It says it
is using the mldivide algorithm, maybe something with inverting a matrix
that doesn't work well...?



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


12