I have a singular matrix which determinant is about 1e-19 and TMatrix Invert()
doesn’t work. Is there any function to calculate the Moore-Penrose pseudoinverse in root?
TDecompSVD can manipulate singular matrices.
Try:
TDecompSVD covMatrixSVD(covMatrix); // covMatrix is a TMatrixD or a TMatrixDSym
covMatrixSVD.Print();
Double_t d1, d2;
covMatrixSVD.Det(d1, d2);
cout << "determinant = " << d1 * TMath::Power(2., d2) << endl;
Hi,
We don’t have this algorithm in ROOT.
Lorenzo
We do have the algorithm(s) to calculate the (Moore-Penrose) pseudo inverse, please see the tutorial here , entry 3 and 4.
I will write them out explicitly for future reference:
- The Invert function of the TDecompSVD class returns the Moore-Penrose matrix
TMatrixD A;
TDecompSVD svd(A);
const TMatrixD pseudo_A = svd.Invert()
or
- An explicit matrix multiplication
TMatrixD A;
TMatrixDSym AtA(TMatrixDSym::kAtA,A);
const TMatrixD pseudo_A = AtA.Invert() * A.T();
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.