SVD decomposition looks incorrect

154 views
Skip to first unread message

Cory Barr

unread,
Dec 15, 2014, 2:37:28 PM12/15/14
to nume...@googlegroups.com
I'm getting puzzling results in the implementation of the SVD. The projections are differing vs running the same dataset through a numpy implementation. I think there's an issue in the numeric.js SVD implementation. I'm noticing that some of the columns of the U matrix have differing signs vs the Python implementation. It's not a case of just flipping the signs of the values, since some row differ. It's resulting in differing projections into 2D space. More specifically, when multiplied by its transpose, U should be returning the identify matrix. Here's a case were that doesn't happen. Any ideas?

Thanks!


//tested with numeric.js version 1.2.6

var countsMatrix = [[0,0,1,1,0,0,0,0,0],[0,0,0,0,0,1,0,0,1],[0,1,0,0,0,0,0,1,0],[0,0,0,0,0,0,1,0,1],[1,0,0,0,0,1,0,0,0],[1,1,1,1,1,1,1,1,1],[1,0,1,0,0,0,0,0,0],[0,0,0,0,0,0,1,0,1],[0,0,0,0,0,2,0,0,1],[1,0,1,0,0,0,0,1,0],[0,0,0,1,1,0,0,0,0]];

var svd = numeric.svd(countsMatrix);

var U = svd.U;
var UTranspose = numeric.transpose(U);

//U should be a unitary matrix, so transpose(U) * U should be the identity matrix:
//http://web.mit.edu/be.400/www/SVD/Singular_Value_Decomposition.htm

var shouldBeIdentity = numeric['*'](UTranspose, U);
//However, it isn't the identity matrix:
console.log(JSON.stringify(shouldBeIdentity));

Sohail Siadat

unread,
Nov 3, 2015, 4:01:40 PM11/3/15
to numericjs
It seems the SVD does not return correct result for non square matrices. For example:

A = [ [ +1  -1 0 ], [0 ,0 ,0] ]
The Matrix U should be still orthogonal.
A == U * S * transpose(V)
but the U & V are not square and Orthogonal.

Sébastien Loisel

unread,
Nov 3, 2015, 4:26:41 PM11/3/15
to nume...@googlegroups.com
Hi Sohail,

numeric.svd is a port of a code found at
http://stitchpanorama.sourceforge.net/Python/svd.py which is "almost
literally" a port of the algorithm by Golub and Reinsch. Apparently
this algorithm requires the matrix A to be taller than it is wide. If
not, you need to compute the SVD of A^T instead.

Thanks,

Sébastien Loisel
> --
> You received this message because you are subscribed to the Google Groups
> "numericjs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to numericjs+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Sébastien Loisel
Assistant Professor
Department of Mathematics, Heriot-Watt University
Riccarton, EH14 4AS, United Kingdom
web: http://www.ma.hw.ac.uk/~loisel/
email: S.Loisel at hw.ac.uk
phone: +44 131 451 3234
fax: +44 131 451 3249
Reply all
Reply to author
Forward
0 new messages