![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 00002 /* 00003 - begin : 2005-08-24 00004 - copyright : (C) 2005 by Gunter Winkler, Konstantin Kutzkow 00005 - email : guwi17@gmx.de 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 */ 00022 00023 #ifndef _H_CHOLESKY_HPP_ 00024 #define _H_CHOLESKY_HPP_ 00025 00026 #include <cassert> 00027 00028 #include <boost/numeric/ublas/vector.hpp> 00029 #include <boost/numeric/ublas/vector_proxy.hpp> 00030 #include <boost/numeric/ublas/matrix.hpp> 00031 #include <boost/numeric/ublas/matrix_proxy.hpp> 00032 #include <boost/numeric/ublas/vector_expression.hpp> 00033 #include <boost/numeric/ublas/matrix_expression.hpp> 00034 #include <boost/numeric/ublas/triangular.hpp> 00035 00036 using namespace boost::numeric::ublas; 00037 00038 template < class MATRIX > 00039 size_t choleskyDecompose(MATRIX& A) 00040 { 00041 typedef typename MATRIX::value_type T; 00042 const MATRIX& A_c(A); 00043 const size_t n = A.size1(); 00044 00045 for (size_t k=0 ; k < n; k++) 00046 { 00047 double qL_kk = A_c(k,k) - inner_prod( project( row(A_c, k), range(0, k) ), 00048 project( row(A_c, k), range(0, k) ) ); 00049 00050 if (qL_kk <= 0) 00051 { 00052 return 1 + k; 00053 } 00054 else 00055 { 00056 double L_kk = sqrt( qL_kk ); 00057 00058 matrix_column<MATRIX> cLk(A, k); 00059 project( cLk, range(k+1, n) ) 00060 = ( project( column(A_c, k), range(k+1, n) ) 00061 - prod( project(A_c, range(k+1, n), range(0, k)), 00062 project(row(A_c, k), range(0, k) ) ) ) / L_kk; 00063 A(k,k) = L_kk; 00064 } 00065 } 00066 return 0; 00067 } 00068 00069 #endif
1.5.5