24 #define GRT_DLL_EXPORTS 30 errorLog.
setKey(
"[ERROR LUdcmp]");
31 warningLog.setKey(
"[WARNING LUdcmp]");
36 Cholesky::Cholesky(
MatrixFloat &a) : N(a.getNumRows()), el(a) {
38 errorLog.setKey(
"[ERROR LUdcmp]");
39 warningLog.setKey(
"[WARNING LUdcmp]");
45 if( el.getNumCols() != N ){
46 errorLog <<
"The input matrix is not square!" << std::endl;
53 for (sum=el[i][j],k=i-1;k>=0;k--) sum -= el[i][k]*el[j][k];
56 errorLog <<
"Sum is <=0.0" << std::endl;
60 }
else el[j][i]=sum/el[i][i];
75 if (b.size() != N || x.size() != N){
76 errorLog <<
":solve(vector<Float> &b, vector<Float> &x) - The input vectors are not the same size!" << std::endl;
80 for(sum=b[i],k=i-1;k>=0;k--) sum -= el[i][k]*x[k];
83 for (i=n-1; i>=0; i--) {
84 for (sum=x[i],k=i+1;k<n;k++) sum -= el[k][i]*x[k];
92 if (b.size() != N || y.size() != N){
93 errorLog <<
"elmult(vector<Float> &y vector<Float> &b) - The input vectors are not the same size!" << std::endl;
98 for (j=0; j<=i; j++) b[i] += el[i][j]*y[j];
107 if (b.size() != N || y.size() != N){
108 errorLog <<
"elsolve(vector<Float> &b vector<Float> &y) - The input vectors are not the same size!" << std::endl;
111 for (i=0; i<N; i++) {
112 for (sum=b[i],j=0; j<i; j++) sum -= el[i][j]*y[j];
120 const int n = int(N);
124 for(i=0; i<n; i++)
for(j=0; j<=i; j++){
125 sum = (i==j? 1. : 0.);
126 for(k=i-1; k>=j; k--) sum -= el[i][k]*ainv[j][k];
127 ainv[j][i]= sum/el[i][i];
129 for(i=n-1; i>=0; i--)
for(j=0; j<=i; j++){
130 sum = (i<j? 0. : ainv[j][i]);
131 for(k=i+1; k<n; k++) sum -= el[k][i]*ainv[j][k];
132 ainv[i][j] = ainv[j][i] = sum/el[i][i];
137 Float Cholesky::logdet(){
139 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 setKey(const std::string &key)
sets the key that gets written at the start of each message, this will be written in the format 'key ...
virtual bool resize(const unsigned int r, const unsigned int c)