/**
* Creates a random SVD that is highly unlikely to be in the correct order. Adjust its order
* and see if it produces the same matrix.
*/
private void testDescendingOrder(int numRows, int numCols, boolean compact, boolean testArray ) {
SimpleMatrix U,W,V;
int minLength = Math.min(numRows,numCols);
double singularValues[] = new double[minLength];
if( compact ) {
U = SimpleMatrix.wrap(RandomMatrices.createOrthogonal(numRows,minLength,rand));
W = SimpleMatrix.wrap(RandomMatrices.createDiagonal(minLength,minLength,0,1,rand));
V = SimpleMatrix.wrap(RandomMatrices.createOrthogonal(numCols,minLength,rand));
} else {
U = SimpleMatrix.wrap(RandomMatrices.createOrthogonal(numRows,numRows,rand));
W = SimpleMatrix.wrap(RandomMatrices.createDiagonal(numRows,numCols,0,1,rand));
V = SimpleMatrix.wrap(RandomMatrices.createOrthogonal(numCols,numCols,rand));
}
// Compute A
SimpleMatrix A=U.mult(W).mult(V.transpose());
// extract array of singular values
for( int i = 0; i < singularValues.length; i++ )
singularValues[i] = W.get(i,i);
// put into descending order
if( testArray ) {
SingularOps.descendingOrder(U.getMatrix(),false,singularValues,minLength,V.getMatrix(),false);
// put back into W
for( int i = 0; i < singularValues.length; i++ )
W.set(i,i,singularValues[i]);
} else {
SingularOps.descendingOrder(U.getMatrix(),false,W.getMatrix(),V.getMatrix(),false);
}
// see if it changed the results
SimpleMatrix A_found = U.mult(W).mult(V.transpose());
assertTrue(A.isIdentical(A_found,1e-8));
// make sure singular values are descending
if( testArray ) {