// svd requires rows >= columns, so transpose data if necessary
if (m_numAttributes < m_numInstances) {
m_transpose = true;
trainMatrix = trainMatrix.transpose();
}
SingularValueDecomposition trainSVD = trainMatrix.svd();
m_u = trainSVD.getU(); // left singular vectors
m_s = trainSVD.getS(); // singular values
m_v = trainSVD.getV(); // right singular vectors
// find actual rank to use
int maxSingularValues = trainSVD.rank();
for (int i = 0; i < m_s.getRowDimension(); i++) {
m_sumSquaredSingularValues += m_s.get(i, i) * m_s.get(i, i);
}
if (maxSingularValues == 0) { // no nonzero singular values (shouldn't happen)
// reset values from computation