Closed GoogleCodeExporter closed 8 years ago
Erratum: CommonOps#invert(m,m_inv) does not produce the expected behaviour
either.
The only method that produces a warning is using a LinearSolver and checking
manually for solver quality().
Why not adding an automatic check on determinant in SimpleMatrix#invert() ?
Original comment by sylvain....@gmail.com
on 9 Jun 2014 at 7:59
It appears to be doing exactly what it says it does. The JavaDoc includes a
warning that an exception might not be thrown if the system is singular/nearly
singular. Here's what octave produces:
octave:1> A=[1,2,3;4,5,6;7,8,9];
octave:2> det(A)
ans = -1.3326e-15
The other question is that should it throw an exception? The problem with
checking a numerical value of the quality (for which there is no clear "best"
metric) is that a threshold must be selected. In your application you might
want an exception to be thrown, in others people might want any sort of
solution they can get. See the problem?
Original comment by peter.ab...@gmail.com
on 9 Jun 2014 at 12:29
Many thanks for your quick answer.
I fully understand that two different users will have opposite expectations for
the same library.
I am just surprised that returning a matrix filled with NaN and +/-Infinity is
allowed by the library. I agree that it could be checked at application level
but as you had the excellent idea to offer 3 levels of complexity to access
your library, I would have expected that the SimpleMatrix level designed for
non-specialists would naturally intercept these kind of situations and alert
the user.
About the threshold issue, you could have one invert(double
singularityThreshold) method and one invert() method with a default threshold.
This is the approach taken by CommonsMath library.
Users that do not care about having NaN in their resulting matrix could still
use 0.0 as a threshold. And if you know by experience that this is the
behaviour expected by most users, you could also use 0.0 as default threshold...
Well, this is only my point of view. Do not hesitate to close the topic if you
think it is not relevant.
Original comment by sylvain....@gmail.com
on 9 Jun 2014 at 2:04
I forgot to include the test matrix that produces NaN and +/-Infinity when
trying to invert:
m=
[1,2,3,4,5,6,7
;2,3,4,5,6,7,8
;3,4,5,6,7,8,9
;4,5,6,7,8,9,10
;5,6,7,8,9,10,11
;6,7,8,9,10,11,12
;7,8,9,10,11,12,13];
Original comment by sylvain....@gmail.com
on 9 Jun 2014 at 2:15
I modified SimpleMatrix.solve and invert so that it checks for NaN and
infinity. Trying to decide if I should do the same for determinant, probably
yes.
For the optional tolerance parameter, I'm still thinking about it. I want to
keep that interface as simple as possible, but knowing when an operation failed
seems like a good idea.
Original comment by peter.ab...@gmail.com
on 9 Jun 2014 at 3:45
Just going to close this. Current behavior is explained in javadoc and
reasonable.
Original comment by peter.ab...@gmail.com
on 17 Nov 2014 at 8:59
Original issue reported on code.google.com by
sylvain....@gmail.com
on 9 Jun 2014 at 7:42