Erik Rodner 13 years ago
parent
commit
4ff306eafb
1 changed files with 7 additions and 1 deletions
  1. 7 1
      math/cluster/SpectralCluster.cpp

+ 7 - 1
math/cluster/SpectralCluster.cpp

@@ -139,7 +139,13 @@ void SpectralCluster::cluster ( const VVector & features,
 
     NICE::Matrix eigvect;
     NICE::Vector eigvals;
-    NICE::eigenvectorvalues ( laplacian, eigvect, eigvals );
+    try {
+      NICE::eigenvectorvalues ( laplacian, eigvect, eigvals );
+    } catch (...) {
+      cerr << "You should adjust the alpha parameter, or the features are somehow weird" << endl;
+      cerr << "Laplacian = " << laplacian(0, 0, min((int)laplacian.rows()-1, 5), min((int)laplacian.cols()-1, 5)) << endl;
+      throw Exception ("Laplacian matrix is singular or not well-conditioned!");
+    }
 
     std::map<double, int> eigvals_sorted;
 	for ( int i = 0 ; i < (int)eigvals.size(); i++ )