numeric icon indicating copy to clipboard operation
numeric copied to clipboard

Found a test case where numeric.svd returns an incorrect decomposition

Open corybarr opened this issue 10 years ago • 1 comments

//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));

corybarr avatar Dec 15 '14 17:12 corybarr

Same here: svd works fine on this matrix: M = [ [5, 0, 0], [0, 1, 0], [ 0, 0, 1] ] https://jsfiddle.net/bwrkerqv/

but fails on that one (which is the same with switched columns/rows): M = [ [1, 0, 0], [0, 1, 0], [ 0, 0, 5] ] https://jsfiddle.net/vyvj1o9f/

valette avatar Jan 06 '16 14:01 valette