lucasmaystre / svdlibc

A fork of Doug Rohde's SVD C Library.
http://tedlab.mit.edu/~dr/SVDLIBC/
48 stars 19 forks source link

3x3 Identity matrix returns erroneous results #3

Open sarahcohen520 opened 5 years ago

sarahcohen520 commented 5 years ago

hi !

we ran the code over 3x3 identity matrix. the results do not multiply back to identity..

do you maybe know why ?

tnx, sarah

lucasmaystre commented 5 years ago

Hi Sarah, can you share the files & the exact command invocation that you are using?

sarahcohen520 commented 5 years ago

Sure, the file I use is : cat THE_MATRIX_sparse1 3 3 3 1 0 1.0 1 1 1.0 1 2 1.0

and the cmd line :

./svd -o result -v 200 ./THE_MATRIX_sparse1

sarahcohen520 commented 5 years ago

and the results output: Verbosity = 200 Loading the matrix... Computing the SVD... SOLVING THE [A^TA] EIGENPROBLEM NO. OF ROWS = 3 NO. OF COLUMNS = 3 NO. OF NON-ZERO VALUES = 3 MATRIX DENSITY = 33.33% MAX. NO. OF LANCZOS STEPS = 3 MAX. NO. OF EIGENPAIRS = 3 LEFT END OF THE INTERVAL = -1.00E-30 RIGHT END OF THE INTERVAL = 1.00E-30 KAPPA = 1.00E-06

NUMBER OF LANCZOS STEPS = 3 RITZ VALUES STABILIZED = 3

COMPUTED RITZ VALUES (ERROR BNDS) 1 9.99999985841008E-01 ( 0.00E+00) 2 1.00000000000000E+00 ( 0.00E+00) 3 1.00000000000000E+00 ( 0.00E+00)

SINGULAR VALUES: 3 1 1 1

LEFT SINGULAR VECTORS (transpose of U): 3 3 0.000271442 0.868467 -0.495747 -0.000308055 -0.868467 0.495747 3.43207e-05 0.495747 0.868467

RIGHT SINGULAR VECTORS (transpose of V): 3 3 0.000271442 0.868467 -0.495747 -0.000308055 -0.868467 0.495747 3.43207e-05 0.495747 0.868467 SINGULAR VALUES FOUND = 3; nsig=3

ELAPSED CPU TIME = 0 sec. MULTIPLICATIONS BY A = 11

lucasmaystre commented 5 years ago

Hi Sarah, thanks. I could indeed reproduce the bug (both with sparse and dense text input). The result of U^T dot V gives something close to

 1 -1 0
-1  1 0
 0  0 1

I don't know where the problem is coming from. Let me know if you make any progress on this issue.

sarahcohen520 commented 5 years ago

Hi Lucas, First, thanks for your responses. Second, I am compiling with gcc 6.3 in 64 bit. while I am compiling with gcc 4.2 in 32 bit, I have different results, but still, not the good ones:

./bin/svd -r st -v 4 THE_MATRIX_sparse1 Verbosity = 4 Loading the matrix... Computing the SVD... SOLVING THE [A^TA] EIGENPROBLEM NO. OF ROWS = 3 NO. OF COLUMNS = 3 NO. OF NON-ZERO VALUES = 3 MATRIX DENSITY = 33.33% MAX. NO. OF LANCZOS STEPS = 3 MAX. NO. OF EIGENPAIRS = 3 LEFT END OF THE INTERVAL = -1.00E-30 RIGHT END OF THE INTERVAL = 1.00E-30 KAPPA = 1.00E-06

NUMBER OF LANCZOS STEPS = 1 RITZ VALUES STABILIZED = -1208451084

COMPUTED RITZ VALUES (ERROR BNDS) 1 0.00000000000000E+00 ( 1.38E+306)

SINGULAR VALUES: 0

LEFT SINGULAR VECTORS (transpose of U): 3 3 0 0 0 0 0 0 0 0 0

RIGHT SINGULAR VECTORS (transpose of V): 3 3 1 0 0 0 0 0 0 0 0 SINGULAR VALUES FOUND = 0; nsig=0

ELAPSED CPU TIME = 0 sec. MULTIPLICATIONS BY A = 2 MULTIPLICATIONS BY A^T = 2

Can you please send me which gcc are you using and on which platform (32/64 bit)? Thanks, Sarah

lucasmaystre commented 5 years ago

Hi Sarah, I am on a 64 bit platform. My GCC is in fact symlinked to clang (Apple LLVM version 10.0.1 (clang-1001.0.46.3)).

I get the exact same results you posted 3 days ago, on April 8.

If I use a matrix whose singular values are not all the same, e.g. the following dense text matrix:

3 3
1.0 0.0 0.0
0.0 2.0 0.0
0.0 0.0 3.0

then the results seem to be correct. Therefore, I wonder if SVDLIBC is not struggling with singular values of multiplicity > 1?

sarahcohen520 commented 5 years ago

this one is working for you: 3 3 1 0 0 0 1 0 0 0 1

sarahcohen520 commented 5 years ago

it is the dense matrix of the sparse that I sent you 3 days ago.

sarahcohen520 commented 5 years ago

this one is working for me also: 3 3 1.0 0.0 0.0 0.0 2.0 0.0 0.0 0.0 3.0,

lucasmaystre commented 5 years ago

The dense identity matrix does not work for me - it produces the same result as the one you sent 3 days ago (whether the format is dense or sparse).

sarahcohen520 commented 5 years ago

ok, also all the matrices that have values very closed to the identity matrix are not working.

Do you have an idea why?

lucasmaystre commented 5 years ago

No, unfortunately I don't have an idea where this might be coming from...