29 debugLog.setProceedingText(
"[DEBUG LUdcmp]");
30 errorLog.setProceedingText(
"[ERROR LUdcmp]");
31 warningLog.setProceedingText(
"[WARNING LUdcmp]");
36 Cholesky::Cholesky(
MatrixFloat &a) : N(a.getNumRows()), el(a) {
38 debugLog.setProceedingText(
"[DEBUG LUdcmp]");
39 errorLog.setProceedingText(
"[ERROR LUdcmp]");
40 warningLog.setProceedingText(
"[WARNING LUdcmp]");
46 if( el.getNumCols() != N ){
47 errorLog <<
"The input matrix is not square!" << std::endl;
54 for (sum=el[i][j],k=i-1;k>=0;k--) sum -= el[i][k]*el[j][k];
57 errorLog <<
"Sum is <=0.0" << std::endl;
61 }
else el[j][i]=sum/el[i][i];
76 if (b.size() != N || x.size() != N){
77 errorLog <<
":solve(vector<Float> &b, vector<Float> &x) - The input vectors are not the same size!" << std::endl;
81 for(sum=b[i],k=i-1;k>=0;k--) sum -= el[i][k]*x[k];
84 for (i=n-1; i>=0; i--) {
85 for (sum=x[i],k=i+1;k<n;k++) sum -= el[k][i]*x[k];
93 if (b.size() != N || y.size() != N){
94 errorLog <<
"elmult(vector<Float> &y vector<Float> &b) - The input vectors are not the same size!" << std::endl;
99 for (j=0; j<=i; j++) b[i] += el[i][j]*y[j];
108 if (b.size() != N || y.size() != N){
109 errorLog <<
"elsolve(vector<Float> &b vector<Float> &y) - The input vectors are not the same size!" << std::endl;
112 for (i=0; i<N; i++) {
113 for (sum=b[i],j=0; j<i; j++) sum -= el[i][j]*y[j];
121 const int n = int(N);
125 for(i=0; i<n; i++)
for(j=0; j<=i; j++){
126 sum = (i==j? 1. : 0.);
127 for(k=i-1; k>=j; k--) sum -= el[i][k]*ainv[j][k];
128 ainv[j][i]= sum/el[i][i];
130 for(i=n-1; i>=0; i--)
for(j=0; j<=i; j++){
131 sum = (i<j? 0. : ainv[j][i]);
132 for(k=i+1; k<n; k++) sum -= el[k][i]*ainv[j][k];
133 ainv[i][j] = ainv[j][i] = sum/el[i][i];
138 Float Cholesky::logdet(){
140 for(
unsigned int i=0; i<N; i++) sum += log(el[i][i]);
This code is based on the LU Decomposition code from Numerical Recipes (3rd Edition) ...
virtual bool resize(const unsigned int r, const unsigned int c)