示例#1
0
double Max(CMatrix &mat) {
  double dMax;
  if(! mat.Defined()) {throw ELENotDefined; }
  
  dMax = mat[0];
  for(int i=0; i<mat.m_pnDimSize[0]; i++) {
    if(mat[i] > dMax) dMax = double(mat[i]);
  } // for i

  if(mat.Allocated()) {delete &mat; } // This should call for the destructor
  return dMax;
} // Max
示例#2
0
double Trace(CMatrix &mat) {
  double dTrace=0;
  if(! mat.Defined()) {throw ELENotDefined; }
  if(mat.m_pnDimSize[0] != mat.m_pnDimSize[1]) {throw ELEDimensionMisMatch; }

  for(int i=0; i<mat.m_pnDimSize[0]; i++) {
    dTrace += double(mat[i][i]);
  } // for i

  if(mat.Allocated()) {delete &mat; } // This should call for the destructor
  return dTrace;
} // Trace
示例#3
0
double Prod(CMatrix &mat) {
  double dProd=1;
  if(! mat.Defined()) {throw ELENotDefined; }

  for(int i=0; i<mat.m_pnDimSize[0]; i++) {
    for(int j=0; j<mat.m_pnDimSize[1]; j++) {
      dProd *= double(mat[i][j]);
    } // for j
  } // for i

  if(mat.Allocated()) {delete &mat; } // This should call for the destructor
  return dProd;
} // Prod
示例#4
0
double Det(CMatrix &mat) {
  double dDet=1;
  CVector vdEigenvalues;
  if(! mat.Defined()) {throw ELENotDefined; }
  if(mat.m_pnDimSize[0] != mat.m_pnDimSize[1]) {throw ELEDimensionMisMatch; }

  vdEigenvalues = mat.Eigenvalues();

  for(int i=0; i<vdEigenvalues.m_pnDimSize[0]; i++) {
    dDet *= double(vdEigenvalues[i]);
  } // for i

  if(mat.Allocated()) {delete &mat; } // This should call for the destructor
  return dDet;
} // Det
示例#5
0
// Log(Det(mat))  (=Trace(Log(mat)) ) <- Use Cholesky and gmp library!
double LogDetCholGmp(CMatrix &mat, int nBits){
  double dLogDet=0;
  CVector vdFact;
  if(! mat.Defined()) {throw ELENotDefined; }
  if(mat.m_pnDimSize[0] != mat.m_pnDimSize[1]) {throw ELEDimensionMisMatch; }

// Use Cholesky
  vdFact = CholeskyGmp(mat, nBits);

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

  if(mat.Allocated()) {delete &mat; } // This should call for the destructor
  return dLogDet;
} // LogDetCholGmp
示例#6
0
/*********************************  This function is doesn't work!  *********************************/
double LogDet(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.LUFact();

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

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