weyns49570 / efficient-java-matrix-library

Automatically exported from code.google.com/p/efficient-java-matrix-library
0 stars 0 forks source link

Matrix rank seems incorrect for large matrices #50

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. The matrix is shown below.
2. call and print SimpleMatrix.svd(true).rank()

What is the expected output? What do you see instead?

MATLAB computes rank = 27 which is expected but EJML computes 28.

What version of the product are you using? On what operating system?

0.25 on Mac OSX 10.10.

Please provide any additional information below.

Correct for small matrices.

Test matrix input:

       1     -32       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0      16     -16       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0      16       0       0       0       0       0       0      -4       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0      16      -1       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0      16       0      -1       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0      16       0       0      -1       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0      16       0       0       0      -1       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       1       0       0       0      -4       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0      16       0       0       0       0       0       0       0       0       0       0       0       0      -1       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       2     -32       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       8      -8       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       8       0      -8       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       8       0       0      -8       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       8       0       0       0      -8       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       1       0       0       0      -1       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       4      -1
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       1       0       0      -1       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       1       0      -1       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       1      -1       0
       0       0       0       0       1       0       0      -4       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       1       0      -4       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       1      -4       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       1      -1       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       1       0      -1       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       1       0       0      -1       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       1       0       0       0      -1       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       1       0       0       0      -4       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0      16     -16       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0      16      -1       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0      16       0      -1       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0      16       0       0      -1       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0      16       0       0       0      -1       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       1       0       0       0     -16       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0      64      -1       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       1       0       0     -16       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       1       0     -16       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       1     -16       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       1       0       0      -4       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       1       0      -4       0       0       0       0       0       0       0       0       0       0       0       0       0       0
       0       0       0       0       0       0       0       0       0       0       0       0       1      -4       0       0       0       0       0       0       0       0       0       0       0       0       0       0

Original issue reported on code.google.com by farley...@dynagrid.net on 4 Nov 2014 at 3:57

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Yes, there is a tiny difference of the singular values but my application 
requires the MATLAB one which is what it should be from the theory. Any 
suggestions?

EJML by extractDIag():

71.5611696859336600
41.1896906595225700
36.6704302554985160
36.0066163727442500
33.5218874295711400
17.9164805604597780
16.0147592153640870
8.0622577482985600
8.0622577482985560
8.0622577482985510
7.2550641757216170
4.5489470485754270
4.1924929110640880
1.4142135623730978
1.4142135623730963
1.4142135623730958
1.4142135623730950
1.4142135623730950
1.4142135623730950
1.4142135623730947
1.4142135623730947
1.4142135623730930
1.2624026508386340
1.1230861141335210
0.9381052747817946
0.4573016700202984
0.4144298804285476
0.0000000000000039

MATLAB computes:

  71.561169685933493
  41.189690659522519
  36.670430255498459
  36.006616372744155
  33.521887429571024
  17.916480560459728
  16.014759215364055
   8.062257748298553
   8.062257748298551
   8.062257748298547
   7.255064175721619
   4.548947048575421
   4.192492911064086
   1.414213562373096
   1.414213562373095
   1.414213562373095
   1.414213562373095
   1.414213562373095
   1.414213562373095
   1.414213562373094
   1.414213562373094
   1.414213562373093
   1.262402650838633
   1.123086114133520
   0.938105274781794
   0.457301670020297
   0.414429880428547
   0.000000000000002

Original comment by farley...@dynagrid.net on 4 Nov 2014 at 9:16

GoogleCodeExporter commented 9 years ago
This issue is most likely caused by a fixed threshold being used for singular 
values.  Matlab uses a threshold based on matrix size.  The code has been 
modified to replicate matlab's behavior since it is more reasonable.

See complex branch on 685cb55d51176650bc866b89cf358e8f74e9a9af

Original comment by peter.ab...@gmail.com on 12 Nov 2014 at 6:28