Eigen.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef EIGEN_H
  2. #define EIGEN_H
  3. /*
  4. * NICE-Core - efficient algebra and computer vision methods
  5. * - libbasicvector - A simple vector library
  6. * See file License for license information.
  7. */
  8. #include "core/vector/ippwrapper.h"
  9. #include "core/vector/VectorT.h"
  10. #include "core/vector/MatrixT.h"
  11. #include "core/vector/RowMatrixT.h"
  12. #include <cmath>
  13. namespace NICE {
  14. /**
  15. * Compute the eigenvector of the eigenvalue with largest absolute eigenvalue
  16. * of a <b>symmetric</b> matrix.
  17. * @param a symmetric matrix
  18. * @return resulting eigenvector
  19. * @note If the matrix is not symmetric, the result will just be nonsense.
  20. * (No exception or other error notification).
  21. */
  22. template<class T>
  23. VectorT<T> maxEigenVector(const MatrixT<T>& a);
  24. /**
  25. * Calculate eigenvalues of a <b>symmetric</b> matrix.
  26. * @param A symmetric matrix
  27. * @param evals eigenvalue buffer
  28. * @return eigenvalues
  29. */
  30. template<class T>
  31. VectorT<T> *eigenvalues(const MatrixT<T> &A, VectorT<T> *evals=NULL);
  32. /**
  33. * Calculate eigenvalues of a <b>symmetric</b> matrix.
  34. * See \c eigenvalues(const MatrixT<T>&, VectorT<T>*)
  35. */
  36. template<class T>
  37. VectorT<T> *eigenvalues(const RowMatrixT<T> &A, VectorT<T> *evals=NULL);
  38. /**
  39. * Calculate eigenvectors and eigenvalues of a <b>symmetric</b> matrix.
  40. * Eigenvectors are columns of the parameter evecs.
  41. * A = evecs * diag(evals) * evecs^T
  42. * @param A symmetric matrix
  43. * @param evecs eigenvector matrix
  44. * @param evals vector of eigenvalues (decreasing order)
  45. */
  46. template<class T>
  47. void eigenvectorvalues(const MatrixT<T> &A, MatrixT<T> &evecs, VectorT<T> &evals);
  48. /**
  49. * Calculate eigenvectors and eigenvalues of a <b>symmetric</b> matrix.
  50. * See \c eigenvectorvalues(const MatrixT<T> &A, MatrixT<T> &evecs, VectorT<T> &evals).
  51. */
  52. template<class T>
  53. void eigenvectorvalues(const RowMatrixT<T> &A, RowMatrixT<T> &evecs, VectorT<T> &evals);
  54. /*
  55. * Calculate Eigenvectors of a <b>symmetric</b> matrix.
  56. * @param A symmetric matrix
  57. * @param v start vector
  58. * @return eigenvector
  59. */
  60. /*
  61. template<class T>
  62. VectorT<T> *Arnoldi_MGS(const MatrixT<T> &A, size_t nr, VectorT<T> *v=NULL)
  63. int vsize=A.cols();
  64. if(v==NULL)
  65. v=new VectorT<T>(vsize,static_cast<T>(1));
  66. MatrixT<T> Q(vsize,nr);
  67. VectorT<T> q(Q,vsize,VectorBase::external);
  68. for(int k=0;k<nr;k++) {
  69. Q = v/v.normL2();
  70. v = A * q[k];
  71. for(int j=1;j<=k;j++) {
  72. v -= q[j] * (q[j].transpose() * v);
  73. }
  74. }
  75. return v;
  76. }
  77. */
  78. }
  79. //#ifdef __GNUC__
  80. #include <core/vector/Eigen.tcc>
  81. //#endif
  82. #endif // EIGEN_H