PowerEigenSolver.h

Go to the documentation of this file.
00001 //
00002 //  Copyright (C) 2004-2006 Rational Discovery LLC
00003 //
00004 //   @@ All Rights Reserved @@
00005 //  This file is part of the RDKit.
00006 //  The contents are covered by the terms of the BSD license
00007 //  which is included in the file license.txt, found at the root
00008 //  of the RDKit source tree.
00009 //
00010 
00011 #ifndef _RD_POWER_EIGENSOLVER_H
00012 #define _RD_POWER_EIGENSOLVER_H
00013 
00014 #include <Numerics/Vector.h>
00015 #include <Numerics/Matrix.h>
00016 #include <Numerics/SymmMatrix.h>
00017 
00018 namespace RDNumeric {
00019   namespace EigenSolvers {
00020     //! Compute the \c numEig largest eigenvalues and, optionally,  the corresponding
00021     //! eigenvectors. 
00022     /*!
00023       
00024     \param numEig       the number of eigenvalues we are interested in
00025     \param mat          symmetric input matrix of dimension N*N
00026     \param eigenValues  Vector used to return the eigenvalues (size = numEig)
00027     \param eigenVectors Optional matrix used to return the eigenvectors (size = N*numEig)
00028     \param seed         Optional values to seed the random value generator used to 
00029                         initialize the eigen vectors
00030     \return a boolean indicating whether or not the calculation converged.
00031     
00032     <b>Notes:</b>
00033     - The matrix, \c mat, is changed in this function
00034     
00035     <b>Algorithm:</b>
00036     
00037     We use the iterative power method, which works like this:
00038 
00039     \verbatim
00040      u = arbitrary unit vector
00041      tol = 0.001
00042      currEigVal = 0.0;
00043      prevEigVal = -1.0e100
00044      while (abs(currEigVal - prevEigVal) > tol) :
00045          v = Au
00046          prevEigVal = currEigVal
00047          currEigVal = v[i] // where i is the id os the largest absolute component
00048          u = c*v
00049     \endverbatim
00050 
00051       
00052     */
00053     bool powerEigenSolver(unsigned int numEig, DoubleSymmMatrix &mat,
00054                           DoubleVector &eigenValues,
00055                           DoubleMatrix *eigenVectors=0, 
00056                           int seed=-1);
00057     //! \overload
00058     static bool powerEigenSolver(unsigned int numEig, DoubleSymmMatrix &mat,
00059                           DoubleVector &eigenValues,
00060                           DoubleMatrix &eigenVectors, 
00061                           int seed=-1) {
00062       return powerEigenSolver(numEig,mat,eigenValues,&eigenVectors,seed);
00063     }
00064   };
00065 };
00066 
00067 #endif
00068                            
00069 
00070