Ejemplo n.º 1
0
// Log(Det(mat))   (= Trace(Log(mat)) )  <- Use Cholesky
double LogDetChol(CMatrix &mat) {
  double dLogDet=0;
//  CVector vdEigenvalues;
  CMatrix mdFact;
  if(! mat.Defined()) {throw ELENotDefined; }
  if(mat.m_pnDimSize[0] != mat.m_pnDimSize[1]) {throw ELEDimensionMisMatch; }

// Use Cholesky
  mdFact = mat.Cholesky();

  for(int i =0; i<mdFact.m_pnDimSize[0]; i++) {
    if(double(mdFact[i][i]) > 0) dLogDet += log(double(mdFact[i][i]));
  } // for i
  dLogDet *= 2;

  if(mat.Allocated()) {delete &mat; } // This should call for the destructor
  return dLogDet;
} // LogDetChol