This project has moved. For the latest updates, please go here.

denseSvd returns defferent results each time

Apr 23, 2013 at 7:00 PM
Hi

I have a denseSvd from which I take the VT matrix as follows:
DenseSvd denseSvd = new DenseSvd(X, true);
Matrix<double> R = denseSvd.VT();
when I run my program twice on the same values I get different results. (Matrix R is different). Does anybody know why is that?
here are the results I get:
0   -0.124571344    -0.399180534    -0.304784305    -0.853629012    -0.059673442
0   -0.562896305    -0.198629699    -0.493132467    0.312634207 0.55024923
1             0                  0                     0                     0                 0 
0   0.076604661 0.74392234  -0.63451157 -0.121846869    -0.152511264
0   -0.066946333    0.439757565 0.417646849 -0.393079387    0.687888928
0   0.810727848 -0.233225171    -0.294776312    0.064956127 0.444087832
second time I run the program I get this result:
0   0.00639447  -0.007152342    0.087039515 0.739199858 0.667769157
0   0.576575821 -0.130699607    0.786454138 0.05486861  -0.170168327
0   0.336920023 0.315769739 -0.359575285    0.566529835 -0.580106827
0   -0.687065201    -0.32264893 0.331555517 0.35520258  -0.433291061
1             0                    0                       0                       0                    0
0   0.286261663 -0.882640129    -0.367002133    0.058720341 -0.029360171
any help would be much appriciated
Thanks
Apr 24, 2013 at 5:15 AM
Hi,

Could you post your matrix and the values of VectorS? If there are any duplicate singular values, then R is not unique. If this is the problem, then our SVD implementation isn't stable (though it isn't clear why that would be the case).

Thanks,
Marcus
Apr 24, 2013 at 6:20 AM
Hi Marcus
First of all - thank you very much for taking the time replying to my message. :)

here are links to Matrix X which is the input to the SVD. I think it is important to mention that X is also the result of SVD.
            Matrix<double> U = _denseSvd.U();
            Matrix<double> X = U.SubMatrix(0, U.RowCount, 0, _c);
_c has the same value both times.

https://dl.dropboxusercontent.com/u/48902173/matrix%20x-08-56-53.xlsx
https://dl.dropboxusercontent.com/u/48902173/matrix%20x-08-58-28.xlsx

Thanks
Guy
Apr 24, 2013 at 11:43 AM
For both matrices, I get the same values for VT no matter how many times I run SVD:
   -0.326068     0.276482     0.267086     0.190362     0.651066     0.534582
   -0.651499     0.504864   -0.0477582     0.306449    -0.391004    -0.267555
     0.67046     0.583849   -0.0828722     0.427784   -0.0910705     0.106971
   -0.012109     0.482237    -0.503288    -0.641862     0.291136    -0.131353
  -0.0827904    -0.298736    -0.698457     0.516829     0.351557    -0.159235
   -0.112743   -0.0774301    -0.422344   -0.0880439    -0.454513     0.767193
Could you post a complete code snippet that produces the problem?

Thanks,
Marcsu
Apr 24, 2013 at 5:32 PM
Hi Marcus

Here is a code snippet which I've tested and yields different results:
        private void testFunction()
        {
            _denseSvd = new DenseSvd(_L, true);

            Matrix<double> U = _denseSvd.U();
            DenseMatrix X = (DenseMatrix) U.SubMatrix(0, U.RowCount, 0, 6);

            DenseSvd denseSvd = new DenseSvd(X, true);
            Matrix<double> R = denseSvd.VT();
        }
The input matrix _L is 100% identical every time i run my program.
X has some minor differences. for instance:
the value X[0,0] the first time is "-0.0078527626357212" and the second time it is: "-0.0078527626357214"

R is very different each time I run the program.

I'm adding links to the input matrix _L and to the other matrixs in case it will help in any way.
_L: https://dl.dropboxusercontent.com/u/48902173/Matrix/matrix%20L2-19-19-27.xlsx

results of first run:
X: https://dl.dropboxusercontent.com/u/48902173/Matrix/matrix%20X1-19-12-09.xlsx
R: https://dl.dropboxusercontent.com/u/48902173/Matrix/matrix%20R1-19-12-10.xlsx

results of second run:
X: https://dl.dropboxusercontent.com/u/48902173/Matrix/matrix%20X2-19-19-35.xlsx
R: https://dl.dropboxusercontent.com/u/48902173/Matrix/matrix%20R2-19-19-35.xlsx


Thanks you very much
Guy
Apr 25, 2013 at 1:22 PM
Hi Guy,

Sorry, every time I run it I get the same answer:
X[0,0] : -0.00785276266443448

R:
0  0.628428409244284  0.331639665434677  0.0541319100191873  0.512793332729552  0.478754217726453
0  -0.225395214099178  -0.60813740974644  -0.462640190079296  0.179522810030001  0.577149463770349
0  -0.711576427945528  0.286199769437471  0.413629849063554  0.439154605298659  0.218637279014495
1       0       0       0       0       0
0  -0.204867974192568  0.558056949785275  -0.780641439240004  0.116248400468175  -0.153905187295535
0  0.0772193774800145  -0.356154679805782  -0.0504289812114381  0.706005736960133  -0.605147774537257
Is it possible that the L matrix changes slightly between runs? Also, the singular values of the second SVD are all 1, so the singular vectors are not unique (as I understand it).

Regards,
Marcus
Marked as answer by cdrnet on 10/3/2013 at 5:41 PM
Apr 25, 2013 at 1:24 PM
Edited Apr 25, 2013 at 1:25 PM
and what CPU and operating system are you running this on? and are you using managed or native SVD?
Apr 25, 2013 at 2:52 PM
Edited Apr 25, 2013 at 2:53 PM
Hi Marcus
_L matrix is always the same and never changes.

I'm running it intel core i7 - 3610qm
Windows 7 premium
it's a laptop (if it makes any difference)

i've installed Mathnet.numerics through NuGet.

What do you mean by "Managed or native SVD"?
Apr 25, 2013 at 4:39 PM
What do you mean by "Managed or native SVD"?
If you were you using the MKL native linear algebra provider or not. I just tried it and it also returns the same result between runs.

I'm using a similar setup so I'm stumped.
Apr 25, 2013 at 5:10 PM
It's ok - thank you very much for taking the time and trying to help.

Guy