55 Error(
"TDecompSVD(Int_t,Int_t",
"matrix rows should be >= columns");
68 const Int_t nrows = row_upb-row_lwb+1;
69 const Int_t ncols = col_upb-col_lwb+1;
72 Error(
"TDecompSVD(Int_t,Int_t,Int_t,Int_t",
"matrix rows should be >= columns");
89 Error(
"TDecompSVD(const TMatrixD &",
"matrix rows should be >= columns");
128 Error(
"Decompose()",
"Matrix has not been set");
132 const Int_t nCol = this->
GetNcols();
139 else offDiag.
Use(nCol,work);
199 TArrayD betas(nCol_v);
201 for (Int_t i = 0; i < nCol_v; i++) {
205 if (i < nCol_v-1 || nRow_v > nCol_v) {
212 for (Int_t j = i; j < nCol_v; j++) {
218 for (Int_t j = 0; j < nCol_u; j++)
237 for (Int_t j = i; j < nRow_v; j++) {
243 for (Int_t k = i+2; k < nCol_v; k++)
252 for (Int_t i = 1; i < nCol_v; i++)
261 for (Int_t i = nCol_v-1; i >= 0; i--) {
268 for (Int_t k = i; k < nCol_v; k++) {
311 Double_t bmx = sDiag(0);
316 for (Int_t i = 1; i < nCol_v; i++)
317 bmx = TMath::Max(TMath::Abs(sDiag(i))+TMath::Abs(oDiag(i)),bmx);
322 const Int_t niterm = 10*nCol_v;
323 for (Int_t k = nCol_v-1; k >= 0; k--) {
327 if (TMath::Abs(sDiag(k)) < eps*bmx)
337 for (Int_t ll = k; ll >= 0 ; ll--) {
342 }
else if (TMath::Abs(oDiag(l)) < eps*bmx) {
345 }
else if (TMath::Abs(sDiag(l-1)) < eps*bmx)
348 if (l > 0 && !elzero)
352 Diag_3(v,u,sDiag,oDiag,k,l);
354 if (niter <= niterm)
goto loop;
355 ::Error(
"TDecompSVD::Diagonalize",
"no convergence after %d steps",niter);
362 sDiag(k) = -sDiag(k);
379 for (Int_t i = k-1; i >= 0; i--) {
390 for (Int_t j = 0; j < nCol_v; j++)
400 for (Int_t i = l; i <= k; i++) {
423 const Double_t psk1 = pS[k-1];
424 const Double_t psk = pS[k];
425 const Double_t pok1 = pO[k-1];
426 const Double_t pok = pO[k];
427 const Double_t psl = pS[l];
430 if (psl == 0.0 || pok == 0.0 || psk1 == 0.0) {
431 const Double_t
b = ((psk1-psk)*(psk1+psk)+pok1*pok1)/2.0;
432 const Double_t c = (psk*pok1)*(psk*pok1);
434 Double_t shift = 0.0;
435 if ((b != 0.0) | (c != 0.0)) {
442 f = (psl+psk)*(psl-psk)+shift;
444 f = ((psk1-psk)*(psk1+psk)+(pok1-pok)*(pok1+pok))/(2.*pok*psk1);
446 const Double_t t = (f >= 0.) ? f+g : f-g;
448 f = ((psl-psk)*(psl+psk)+pok*(psk1/t-pok))/psl;
456 for (Int_t i = l; i <= k-1; i++) {
470 for (j = 0; j < nCol_v; j++)
482 for (j = 0; j < nCol_u; j++)
511 Bool_t found = kFALSE;
513 while (!found && i < nCol_v) {
520 for (i = 1; i < nCol_v; i++) {
521 Double_t t = pS[i-1];
523 for (j = i; j < nCol_v; j++) {
534 for (j = 0; j < nCol_v; j++) {
535 const Int_t off_j = j*nCol_v;
537 pV[off_j+k] = pV[off_j+i-1];
541 for (j = 0; j < nCol_u; j++) {
542 const Int_t off_k = k*nCol_u;
543 const Int_t off_i1 = (i-1)*nCol_u;
545 pU[off_k+j] = pU[off_i1+j];
560 Error(
"GetMatrix()",
"Matrix is singular");
565 Error(
"GetMatrix()",
"Decomposition failed");
588 Error(
"TDecompSVD(const TMatrixD &",
"matrix rows should be >= columns");
629 Error(
"Solve(TVectorD &",
"vector and matrix incompatible");
639 const Double_t threshold =
fSig(lwb)*
fTol;
642 for (Int_t irow = lwb; irow <= upb; irow++) {
644 if (
fSig(irow) > threshold) {
685 Error(
"Solve(TMatrixDColumn &",
"vector and matrix incompatible");
695 const Double_t threshold =
fSig(lwb)*
fTol;
699 for (Int_t irow = lwb; irow <= upb; irow++) {
701 if (
fSig(irow) > threshold) {
736 Error(
"TransSolve(TVectorD &",
"matrix should be square");
742 Error(
"TransSolve(TVectorD &",
"vector and matrix incompatible");
752 const Double_t threshold =
fSig(lwb)*
fTol;
755 for (Int_t i = lwb; i <= upb; i++) {
757 if (
fSig(i) > threshold) {
786 Error(
"TransSolve(TMatrixDColumn &",
"matrix should be square");
792 Error(
"TransSolve(TMatrixDColumn &",
"vector and matrix incompatible");
802 const Double_t threshold =
fSig(lwb)*
fTol;
806 for (Int_t i = lwb; i <= upb; i++) {
808 if (
fSig(i) > threshold) {
835 const Double_t max =
fSig(colLwb);
836 const Double_t min =
fSig(colLwb+nCols-1);
889 Error(
"Invert(TMatrixD &",
"Input matrix has wrong shape");
932 if (
this != &source) {
virtual TMatrixTBase< Element > & UnitMatrix()
Make a unit matrix (matrix need not be a square one).
virtual void Det(Double_t &d1, Double_t &d2)
Matrix determinant det = d1*TMath::Power(2.,d2)
virtual TMatrixTBase< Element > & Shift(Int_t row_shift, Int_t col_shift)
Shift the row index by adding row_shift and the column index by adding col_shift, respectively...
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
static Bool_t Bidiagonalize(TMatrixD &v, TMatrixD &u, TVectorD &sDiag, TVectorD &oDiag)
Bidiagonalize the (m x n) - matrix a (stored in v) through a series of Householder transformations ap...
virtual Bool_t MultiSolve(TMatrixD &B)
Solve set of equations with RHS in columns of B.
TMatrixT< Element > & Transpose(const TMatrixT< Element > &source)
Transpose matrix source.
static void Diag_3(TMatrixD &v, TMatrixD &u, TVectorD &sDiag, TVectorD &oDiag, Int_t k, Int_t l)
Step 3 in the matrix diagonalization.
virtual Bool_t TransSolve(TVectorD &b)
Solve A^T x=b assuming the SVD form of A is stored . Solution returned in b.
virtual const Element * GetMatrixArray() const
Decomposition Base class.
TMatrixTColumn_const< Double_t > TMatrixDColumn_const
virtual void SetMatrix(const TMatrixD &a)
Set matrix to be decomposed.
void Print(Option_t *option="") const
Print the vector as a list of elements.
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1)
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
Bool_t DefHouseHolder(const TVectorD &vc, Int_t lp, Int_t l, Double_t &up, Double_t &b, Double_t tol=0.0)
Define a Householder-transformation through the parameters up and b .
double beta(double x, double y)
Calculates the beta function.
static Bool_t Diagonalize(TMatrixD &v, TMatrixD &u, TVectorD &sDiag, TVectorD &oDiag)
Diagonalizes in an iterative fashion the bidiagonal matrix C as described through sDiag and oDiag...
Single Value Decomposition class.
TVectorT< Element > & Use(Int_t lwb, Int_t upb, Element *data)
Use the array data to fill the vector lwb..upb].
TDecompBase & operator=(const TDecompBase &source)
Assignment operator.
TVectorT< Element > & SetSub(Int_t row_lwb, const TVectorT< Element > &source)
Insert vector source starting at [row_lwb], thereby overwriting the part [row_lwb..row_lwb+nrows_source];.
void ApplyGivens(Double_t &z1, Double_t &z2, Double_t c, Double_t s)
Apply a Givens transformation as defined by c and s to the vector components v1 and v2 ...
TMatrixTRow_const< Double_t > TMatrixDRow_const
static void DiagProd(const TVectorD &diag, Double_t tol, Double_t &d1, Double_t &d2)
virtual Bool_t Decompose()
SVD decomposition of matrix If the decomposition succeeds, bit kDecomposed is set ...
TMatrixTRow< Double_t > TMatrixDRow
TVectorT< Element > & Shift(Int_t row_shift)
Element * GetMatrixArray()
TMatrixT< Double_t > TMatrixD
static void SortSingular(TMatrixD &v, TMatrixD &u, TVectorD &sDiag)
Perform a permutation transformation on the diagonal matrix S', so that matrix S'' = U''^T ...
virtual Int_t GetNcols() const
void ApplyHouseHolder(const TVectorD &vc, Double_t up, Double_t b, Int_t lp, Int_t l, TMatrixDRow &cr)
Apply Householder-transformation.
void DefGivens(Double_t v1, Double_t v2, Double_t &c, Double_t &s)
Defines a Givens-rotation by calculating 2 rotation parameters c and s.
void Print(Option_t *opt="") const
Print class members.
TMatrixTDiag< Double_t > TMatrixDDiag
virtual Bool_t Solve(TVectorD &b)
Solve Ax=b assuming the SVD form of A is stored .
static void Diag_1(TMatrixD &v, TVectorD &sDiag, TVectorD &oDiag, Int_t k)
Step 1 in the matrix diagonalization.
virtual Int_t GetNrows() const
Double_t Hypot(Double_t x, Double_t y)
void Print(Option_t *name="") const
Print the matrix as a table of elements.
const TMatrixTBase< Element > * GetMatrix() const
TMatrixTColumn< Double_t > TMatrixDColumn
const TMatrixD GetMatrix()
Reconstruct the original matrix using the decomposition parts.
void DefAplGivens(Double_t &v1, Double_t &v2, Double_t &c, Double_t &s)
Define and apply a Givens-rotation by calculating 2 rotation parameters c and s.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
virtual Double_t Condition()
Matrix condition number.
Double_t Sqrt(Double_t x)
TDecompSVD & operator=(const TDecompSVD &source)
Assignment operator.
static void Diag_2(TVectorD &sDiag, TVectorD &oDiag, Int_t k, Int_t l)
Step 2 in the matrix diagonalization.
void Print(Option_t *opt="") const
Print class members.