void PivotMDS::pivotMDSLayout(GraphAttributes& GA) { const Graph& G = GA.constGraph(); bool use3D = GA.has(GraphAttributes::threeD) && DIMENSION_COUNT > 2; const int n = G.numberOfNodes(); // trivial cases if (n == 0) return; if (n == 1) { node v1 = G.firstNode(); GA.x(v1) = 0.0; GA.y(v1) = 0.0; if (use3D) GA.z(v1) = 0.0; return; } // check whether the graph is a path or not const node head = getRootedPath(G); if (head != nullptr) { doPathLayout(GA, head); } else { Array<Array<double> > pivDistMatrix; // compute the pivot matrix getPivotDistanceMatrix(GA, pivDistMatrix); // center the pivot matrix centerPivotmatrix(pivDistMatrix); // init the coordinate matrix Array<Array<double> > coord(DIMENSION_COUNT); for (int i = 0; i < coord.size(); i++) { coord[i].init(n); } // init the eigen values array Array<double> eVals(DIMENSION_COUNT); singularValueDecomposition(pivDistMatrix, coord, eVals); // compute the correct aspect ratio for (int i = 0; i < coord.size(); i++) { eVals[i] = sqrt(eVals[i]); for (int j = 0; j < n; j++) { coord[i][j] *= eVals[i]; } } // set the new positions to the graph int i = 0; for (node v : G.nodes) { GA.x(v) = coord[0][i]; GA.y(v) = coord[1][i]; if (use3D){ GA.z(v) = coord[2][i];//cout << coord[2][i] << "\n"; } ++i; } } }
void LinearSolver::eigen_system( DENS_MAT & eigenvalues, DENS_MAT & eigenvectors, const DENS_MAT * M) /* const */ { initialize_matrix(); // no inverse needed const DENS_MAT * Kp = NULL; const DENS_MAT * Mp =M; DENS_MAT MM; DENS_MAT KM; if (constraintHandlerType_ == CONDENSE_CONSTRAINTS) { Kp = &matrixFreeFree_; if (M) { DENS_MAT MfreeFixed; // not used M->row_partition(freeSet_,MM,MfreeFixed); Mp = &MM; } } else { if (matrixDense_.nRows() == 0) matrixDense_ =matrixSparse_->dense_copy(); Kp = &matrixDense_; } if (!M) { MM.identity(Kp->nRows()); Mp = &MM; } DENS_MAT eVecs, eVals; eVecs = eigensystem(*Kp,*Mp,eVals); eigenvalues.reset(nVariables_,1); eigenvectors.reset(nVariables_,nVariables_); set<int>::const_iterator itr; for (int i = 0; i < Kp->nRows(); i++) { // ordering is by energy not node eigenvalues(i,0) = eVals(i,0); int j = 0; for (itr = freeSet_.begin(); itr != freeSet_.end(); itr++,j++) { int jj = *itr; eigenvectors(jj,i) = eVecs(j,i); // transpose } } }