numeric
numeric copied to clipboard
Found a test case where numeric.svd returns an incorrect decomposition
//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));
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/