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");
88 if (
a.GetNrows() <
a.GetNcols()) {
89 Error(
"TDecompSVD(const TMatrixD &",
"matrix rows should be >= columns");
100 const Int_t nRow =
a.GetNrows();
101 const Int_t nCol =
a.GetNcols();
128 Error(
"Decompose()",
"Matrix has not been set");
139 else offDiag.
Use(nCol,work);
194 const Int_t nRow_v =
v.GetNrows();
195 const Int_t nCol_v =
v.GetNcols();
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++) {
313 const Int_t nCol_v =
v.GetNcols();
316 for (
Int_t i = 1; i < nCol_v; i++)
320 const Double_t eps = std::numeric_limits<double>::epsilon();
322 const Int_t niterm = 10*nCol_v;
323 for (
Int_t k = nCol_v-1; k >= 0; k--) {
337 for (
Int_t ll = k; ll >= 0 ; ll--) {
348 if (
l > 0 && !elzero)
354 if (niter <= niterm)
goto loop;
355 ::Error(
"TDecompSVD::Diagonalize",
"no convergence after %d steps",niter);
362 sDiag(k) = -sDiag(k);
376 const Int_t nCol_v =
v.GetNcols();
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++) {
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);
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);
448 f = ((psl-psk)*(psl+psk)+pok*(psk1/t-pok))/psl;
451 const Int_t nCol_v =
v.GetNcols();
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++)
499 const Int_t nCol_v =
v.GetNcols();
513 while (!found && i < nCol_v) {
520 for (i = 1; i < nCol_v; i++) {
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");
587 if (
a.GetNrows() <
a.GetNcols()) {
588 Error(
"TDecompSVD(const TMatrixD &",
"matrix rows should be >= columns");
597 const Int_t nRow =
a.GetNrows();
598 const Int_t nCol =
a.GetNcols();
629 Error(
"Solve(TVectorD &",
"vector and matrix incompatible");
642 for (
Int_t irow = lwb; irow <= upb; irow++) {
644 if (
fSig(irow) > threshold) {
654 tmp2.
Use(lwb,upb,
b.GetMatrixArray());
685 Error(
"Solve(TMatrixDColumn &",
"vector and matrix incompatible");
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");
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");
806 for (
Int_t i = lwb; i <= upb; i++) {
808 if (
fSig(i) > threshold) {
887 if (
inv.GetNrows() != nRows ||
inv.GetNcols() != nRows ||
888 inv.GetRowLwb() != rowLwb ||
inv.GetColLwb() != colLwb) {
889 Error(
"Invert(TMatrixD &",
"Input matrix has wrong shape");
932 if (
this != &source) {
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 .
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 .
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 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.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
TMatrixTRow< Double_t > TMatrixDRow
TMatrixTColumn_const< Double_t > TMatrixDColumn_const
TMatrixTDiag< Double_t > TMatrixDDiag
TMatrixTRow_const< Double_t > TMatrixDRow_const
TMatrixTColumn< Double_t > TMatrixDColumn
TMatrixT< Double_t > TMatrixD
Array of doubles (64 bits per element).
Decomposition Base class.
static void DiagProd(const TVectorD &diag, Double_t tol, Double_t &d1, Double_t &d2)
virtual Bool_t MultiSolve(TMatrixD &B)
Solve set of equations with RHS in columns of B.
TDecompBase & operator=(const TDecompBase &source)
Assignment operator.
void Print(Option_t *opt="") const override
Print class members.
Single Value Decomposition class.
void Det(Double_t &d1, Double_t &d2) override
Matrix determinant det = d1*TMath::Power(2.,d2)
static void Diag_3(TMatrixD &v, TMatrixD &u, TVectorD &sDiag, TVectorD &oDiag, Int_t k, Int_t l)
Step 3 in the matrix diagonalization.
static void Diag_2(TVectorD &sDiag, TVectorD &oDiag, Int_t k, Int_t l)
Step 2 in the matrix diagonalization.
TDecompSVD & operator=(const TDecompSVD &source)
Assignment operator.
Bool_t Solve(TVectorD &b) override
Solve Ax=b assuming the SVD form of A is stored .
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...
static void Diag_1(TMatrixD &v, TVectorD &sDiag, TVectorD &oDiag, Int_t k)
Step 1 in the matrix diagonalization.
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,...
Double_t Condition() override
Matrix condition number.
Bool_t Decompose() override
SVD decomposition of matrix If the decomposition succeeds, bit kDecomposed is set ,...
Int_t GetNrows() const override
const TMatrixD GetMatrix()
Reconstruct the original matrix using the decomposition parts.
Bool_t TransSolve(TVectorD &b) override
Solve A^T x=b assuming the SVD form of A is stored . Solution returned in b.
virtual void SetMatrix(const TMatrixD &a)
Set matrix to be decomposed.
Int_t GetNcols() const override
static void SortSingular(TMatrixD &v, TMatrixD &u, TVectorD &sDiag)
Perform a permutation transformation on the diagonal matrix S', so that matrix S'' = U''^T .
void Print(Option_t *opt="") const override
Print class members.
virtual TMatrixTBase< Element > & UnitMatrix()
Make a unit matrix (matrix need not be a square one).
void Print(Option_t *name="") const override
Print the matrix as a table of elements.
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.
const TMatrixTBase< Element > * GetMatrix() const
const Element * GetMatrixArray() const override
TMatrixT< Element > & Transpose(const TMatrixT< Element > &source)
Transpose matrix source.
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TVectorT< Element > & Shift(Int_t row_shift)
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
TVectorT< Element > & SetSub(Int_t row_lwb, const TVectorT< Element > &source)
Insert vector source starting at [row_lwb], thereby overwriting the part [row_lwb....
TVectorT< Element > & Use(Int_t lwb, Int_t upb, Element *data)
Use the array data to fill the vector lwb..upb].
void Print(Option_t *option="") const override
Print the vector as a list of elements.
Element * GetMatrixArray()
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Double_t Sqrt(Double_t x)
Returns the square root of x.
Double_t Hypot(Double_t x, Double_t y)
Returns sqrt(x*x + y*y)
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
void inv(rsa_NUMBER *, rsa_NUMBER *, rsa_NUMBER *)