Эх сурвалжийг харах

Merge branch 'master' of /home/dbv/git/nice

Alexander Freytag 11 жил өмнө
parent
commit
c7f9995de6

+ 16 - 4
core/algebra/EigValues.cpp

@@ -71,7 +71,9 @@ EVArnoldi::getEigenvalues ( const GenericMatrix & data, Vector & eigenvalues,
   uint iteration = 0;
   while ( delta > mindelta && iteration < maxiterations )
   {
-    NICE::Vector rold ( rmatrix.getColumn ( k - 1 ) );
+    //replace Vector rold by matrix rold to check for convergence of all eigenvectors
+    //NICE::Vector rold ( rmatrix.getColumn ( k - 1 ) );
+    NICE::Matrix rold(rmatrix);
     // meta-comment: i is an index for the iteration, j is an index for the basis
     // element (1 <= j <= k)
     for ( uint reduceddim = 0; reduceddim < k; reduceddim++ )
@@ -96,9 +98,19 @@ EVArnoldi::getEigenvalues ( const GenericMatrix & data, Vector & eigenvalues,
           ( qmatrix.getColumn ( j ).
             scalarProduct ( rmatrix.getColumn ( reduceddim ) ) );
     }
-    //convergence stuff
-    NICE::Vector diff = rold - rmatrix.getColumn ( k - 1 );
-    delta = diff.normL2 ();
+    //convergence stuff (replaced by checking all eigenvectors instead of a single one
+    //NICE::Vector diff = rold - rmatrix.getColumn ( k - 1 );
+    //delta = diff.normL2 ();
+    NICE::Vector tmpDiff;
+    double norm_tmpDiff;
+    delta = 0.0;
+    for ( uint j = 0; j < k; j++ )
+    {
+      tmpDiff = rold.getColumn(j) - rmatrix.getColumn(j);
+      norm_tmpDiff = tmpDiff.normL2();
+      if (norm_tmpDiff > delta)
+        delta = norm_tmpDiff;
+    }
     iteration++;
 
     if ( verbose )

+ 2 - 1
core/basics/Config.cpp

@@ -232,6 +232,7 @@ void Config::restore (istream & is, int format)
         continue;
 
       line = StringTools::chomp ( line );
+      len = line.size();
 
   #if defined DEBUGCONFIG
       DEBUGPRINT ("Config: (%d) '%s' (len = %d) / %s\n", (int)count, line.c_str(), (int)len,
@@ -274,7 +275,7 @@ void Config::restore (istream & is, int format)
       while ( (line[p]!='=') && (p<len) ) p++;
       if ( (p >= len-1) || (p<=i) ) continue;
       key = line.substr( i, p-i );
-      value = line.substr( p+1, len-p );
+      value = line.substr( p+1 ); // with only one argument, substr copies from the specified position until the end of the string
 
       StringTools::normalize_string(value);
       StringTools::normalize_string(key);

+ 23 - 2
core/basics/StringTools.cpp

@@ -136,8 +136,29 @@ void StringTools::trimbounds ( std::string & value, char trimChar )
 /** @author Matti Bickel */
 std::string StringTools::trim(string s, const std::string& drop)
 {
-    std::string r=s.erase(s.find_last_not_of(drop)+1);
-    return r.erase(0,r.find_first_not_of(drop));
+    size_t findLastIndex = s.find_last_not_of(drop);
+    if ( findLastIndex < s.size() )
+    {
+      std::string r=s.erase(findLastIndex+1);
+      
+      size_t findFirstIndex = r.find_first_not_of(drop);
+      
+      if ( findFirstIndex > 0 )
+        return r.erase(0,findFirstIndex);
+      else
+        return r;
+      
+    } else
+    {
+      size_t findFirstIndex = s.find_first_not_of(drop);
+
+      if ( findFirstIndex > 0 )
+        return s.erase(0,findFirstIndex);
+      else
+        return s;
+      
+    }
+      
 }
 
 std::string StringTools::chomp(string s)

+ 6 - 0
core/progs/imageDemo.cpp

@@ -26,11 +26,15 @@ int main ( int argc, char **argv )
 	ColorImage srcColor ( argv[1] );
 
   // show the image and wait for the window being closed manually
+#ifdef NICE_USELIB_GLUT
 #ifdef NICE_USELIB_QT
   showImage ( srcColor );
 #else
   cerr << "Visualization disabled: no QT library available" << endl;
 #endif
+#else 
+  cerr << "Visualization disabled: no GLUT library available" << endl;
+#endif
 
   // simple grayvalue image
   Image src;
@@ -48,9 +52,11 @@ int main ( int argc, char **argv )
   ColorImage gradientColor;
   imageToPseudoColor ( gradient, gradientColor );
 
+#ifdef NICE_USELIB_GLUT
 #ifdef NICE_USELIB_QT
   showImage ( gradientColor );
 #endif
+#endif
 
 
 }

+ 15 - 1
core/vector/Algorithms.cpp

@@ -105,7 +105,21 @@ void choleskySolveMatrixLargeScale ( const Matrix & G, Matrix & B )
 	#warning "LinAl is not installed: choleskyInvertLargeScale will not be optimized."
   #define CHOLESKYLINAL_WARNING
   #endif
-	choleskyInvert ( G, B );
+  if (G.rows() != G.cols())
+    fthrow(Exception, "Matrix G is not quadratic !");
+  if ( G.rows() != B.rows() )
+    fthrow(Exception, "Matrices sizes do not fit together.");
+  if (B.rows() == B.cols())
+    choleskyInvert ( G, B );
+  else
+  {
+    Vector b(B.rows(),0.0);
+    for (size_t i=0;i<B.cols();i++)
+    {
+      choleskySolveLargeScale (G, B.getColumn(i), b);
+      B.getColumnRef(i) = b;
+    }
+  }
 #endif
 }
 

+ 1 - 1
core/vector/SparseVectorT.tcc

@@ -443,7 +443,7 @@ bool SparseVectorT<I,V>::set ( I i , V newValue )
   {
     // behavior change (2/2/2012 by erik)
     if ( newValue > 1e-20 )
-      insert ( std::pair<I, V> ( i, newValue ) );
+      this->insert ( std::pair<I, V> ( i, newValue ) );
     //update our dimensions
     if ( i > dim ) //changed on 10-02-2012 by alex
       dim = i;