diff --git a/src/analysis/ClassicalScaling.cpp b/src/analysis/ClassicalScaling.cpp index c4e1eff02c3a46edd26264ffb71bbec62db37fc0..39588bc0a6c4362688cda51b48f44dd0f155b72e 100644 --- a/src/analysis/ClassicalScaling.cpp +++ b/src/analysis/ClassicalScaling.cpp @@ -46,15 +46,6 @@ void ClassicalScaling::run( PointWiseMapping* mymap ){ std::vector<double> eigval(n); Matrix<double> eigvec(n,n); diagMat( distances, eigval, eigvec ); - // This change eigenvectors so that the sum of the elements is positive - // We can do it because the phase is arbitrary, and helps making - // the result reproducible - for(unsigned i=0;i<n;++i){ - double s=0.0; - for(unsigned j=0;j<n;++j) s+=eigvec[i][j]; - if(s<0.0) for(unsigned j=0;j<n;++j) eigvec[i][j]*=-1; - } - // Pass final projections to map object for(unsigned i=0;i<n;++i){ for(unsigned j=0;j<mymap->getNumberOfProperties();++j) mymap->setProjectionCoordinate( i, j, sqrt(eigval[n-1-j])*eigvec(n-1-j,i) ); diff --git a/src/tools/Matrix.h b/src/tools/Matrix.h index 5f824ace9f5cfb9df3f1bfd72a1a9418d7b1e3e7..b5fc45009c9a1186ffbc6106a3541b20b9a71f1f 100644 --- a/src/tools/Matrix.h +++ b/src/tools/Matrix.h @@ -237,6 +237,15 @@ template <typename T> int diagMat( const Matrix<T>& A, std::vector<double>& eige for(unsigned j=0;j<A.rw;++j){ eigenvecs(i,j)=evecs[k++]; } } + // This changes eigenvectors so that the sum of the elements is positive + // We can do it because the phase is arbitrary, and helps making + // the result reproducible + for(unsigned i=0;i<n;++i){ + double s=0.0; + for(unsigned j=0;j<n;++j) s+=eigenvecs(i,j); + if(s<0.0) for(unsigned j=0;j<n;++j) eigenvecs(i,j)*=-1; + } + // Deallocate all the memory used by the various arrays delete[] da; delete [] work; delete [] evals; delete[] evecs; delete [] iwork; delete [] isup; return 0;