eigenvalues.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Algorithms for Eigenvalue decompositions
5  *
6  *
7  *
8  *
9  * \author O. Krause
10  * \date 2011
11  *
12  *
13  * \par Copyright 1995-2017 Shark Development Team
14  *
15  * <BR><HR>
16  * This file is part of Shark.
17  * <http://shark-ml.org/>
18  *
19  * Shark is free software: you can redistribute it and/or modify
20  * it under the terms of the GNU Lesser General Public License as published
21  * by the Free Software Foundation, either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * Shark is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU Lesser General Public License for more details.
28  *
29  * You should have received a copy of the GNU Lesser General Public License
30  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
33 #ifndef SHARK_LINALG_EIGENVALUES_H
34 #define SHARK_LINALG_EIGENVALUES_H
35 
36 #include <shark/LinAlg/Base.h>
38 
39 namespace shark{ namespace blas{
40 
41 /**
42  * \ingroup shark_globals
43  *
44  * @{
45  */
46 
47 /*!
48  * \brief Used as frontend for
49  * eigensymm for calculating the eigenvalues and the normalized eigenvectors of a symmetric matrix
50  * 'A' using the Givens and Householder reduction. Each time this frontend is called additional
51  * memory is allocated for intermediate results.
52  *
53  *
54  * \param A \f$ n \times n \f$ matrix, which must be symmetric, so only the bottom triangular matrix must contain values.
55  * \param eigenVectors \f$ n \times n \f$ matrix with the calculated normalized eigenvectors, each column contains an eigenvector.
56  * \param eigenValues n-dimensional vector with the calculated eigenvalues in descending order.
57  * \return none.
58  *
59  * \throw SharkException
60  */
61 template<class MatrixT,class MatrixU,class VectorT>
62 void eigensymm
63 (
67 )
68 {
69  SIZE_CHECK(A().size2() == A().size1());
70  std::size_t n = A().size1();
71 
72  eigenVectors().resize(n,n);
73  eigenVectors().clear();
74  eigenValues().resize(n);
75  eigenValues().clear();
76  // special case n = 1
77  if (n == 1) {
78  eigenVectors()( 0 , 0 ) = 1;
79  eigenValues()( 0 ) = A()( 0 , 0 );
80  return;
81  }
82 
83  // copy matrix
84  for (std::size_t i = 0; i < n; i++) {
85  for (std::size_t j = 0; j <= i; j++) {
86  eigenVectors()(i, j) = A()(i, j);
87  }
88  }
89 
90  kernels::syev(eigenVectors,eigenValues);
91 }
92 
93 
94 
95 /** @}*/
96 }}
97 #endif