Logo ROOT   6.07/09
Reference Guide
TDecompSVD.h
Go to the documentation of this file.
1 // @(#)root/matrix:$Id$
2 // Authors: Fons Rademakers, Eddy Offermann Dec 2003
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TDecompSVD
13 #define ROOT_TDecompSVD
14 
15 ///////////////////////////////////////////////////////////////////////////
16 // //
17 // Single Value Decomposition class //
18 // //
19 ///////////////////////////////////////////////////////////////////////////
20 
21 #ifndef ROOT_TDecompBase
22 #include "TDecompBase.h"
23 #endif
24 
25 class TDecompSVD : public TDecompBase
26 {
27 protected :
28 
29  // A = fU fSig fV^T
30  TMatrixD fU; // orthogonal matrix
31  TMatrixD fV; // orthogonal matrix
32  TVectorD fSig; // diagonal of diagonal matrix
33 
34  static Bool_t Bidiagonalize(TMatrixD &v,TMatrixD &u,TVectorD &sDiag,TVectorD &oDiag);
35  static Bool_t Diagonalize (TMatrixD &v,TMatrixD &u,TVectorD &sDiag,TVectorD &oDiag);
36  static void Diag_1 (TMatrixD &v,TVectorD &sDiag,TVectorD &oDiag,Int_t k);
37  static void Diag_2 (TVectorD &sDiag,TVectorD &oDiag,Int_t k,Int_t l);
38  static void Diag_3 (TMatrixD &v,TMatrixD &u,TVectorD &sDiag,TVectorD &oDiag,Int_t k,Int_t l);
39  static void SortSingular (TMatrixD &v,TMatrixD &u,TVectorD &sDiag);
40 
41  virtual const TMatrixDBase &GetDecompMatrix() const { return fU; }
42 
43 public :
44 
45  enum {kWorkMax = 100}; // size of work array
46 
47  TDecompSVD(): fU(), fV(), fSig() {}
48  TDecompSVD(Int_t nrows,Int_t ncols);
49  TDecompSVD(Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb);
50  TDecompSVD(const TMatrixD &m,Double_t tol = 0.0);
51  TDecompSVD(const TDecompSVD &another);
52  virtual ~TDecompSVD() {}
53 
54  const TMatrixD GetMatrix ();
55  virtual Int_t GetNrows () const;
56  virtual Int_t GetNcols () const;
57  const TMatrixD &GetU () { if ( !TestBit(kDecomposed) ) Decompose();
58  return fU; }
59  const TMatrixD &GetV () { if ( !TestBit(kDecomposed) ) Decompose();
60  return fV; }
61  const TVectorD &GetSig () { if ( !TestBit(kDecomposed) ) Decompose();
62  return fSig; }
63 
64  virtual void SetMatrix (const TMatrixD &a);
65 
66  virtual Bool_t Decompose ();
67  virtual Bool_t Solve ( TVectorD &b);
68  virtual TVectorD Solve (const TVectorD& b,Bool_t &ok) { TVectorD x = b; ok = Solve(x);
69  const Int_t rowLwb = GetRowLwb();
70  x.ResizeTo(rowLwb,rowLwb+GetNcols()-1);
71  return x; }
72  virtual Bool_t Solve ( TMatrixDColumn &b);
73  virtual Bool_t TransSolve ( TVectorD &b);
74  virtual TVectorD TransSolve (const TVectorD& b,Bool_t &ok) { TVectorD x = b; ok = TransSolve(x);
75  const Int_t rowLwb = GetRowLwb();
76  x.ResizeTo(rowLwb,rowLwb+GetNcols()-1);
77  return x; }
78  virtual Bool_t TransSolve ( TMatrixDColumn &b);
79  virtual Double_t Condition ();
80  virtual void Det (Double_t &d1,Double_t &d2);
81 
83  TMatrixD Invert (Bool_t &status);
84  TMatrixD Invert () {Bool_t status; return Invert(status); }
85 
86  void Print(Option_t *opt ="") const; // *MENU*
87 
88  TDecompSVD &operator= (const TDecompSVD &source);
89 
90  ClassDef(TDecompSVD,1) // Matrix Decompositition SVD
91 };
92 
93 #endif
const TVectorD & GetSig()
Definition: TDecompSVD.h:61
virtual void Det(Double_t &d1, Double_t &d2)
Matrix determinant det = d1*TMath::Power(2.,d2)
Definition: TDecompSVD.cxx:846
TVectorT< Element > & ResizeTo(Int_t lwb, Int_t upb)
Resize the vector to [lwb:upb] .
Definition: TVectorT.cxx:292
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...
Definition: TDecompSVD.cxx:192
static void Diag_3(TMatrixD &v, TMatrixD &u, TVectorD &sDiag, TVectorD &oDiag, Int_t k, Int_t l)
Step 3 in the matrix diagonalization.
Definition: TDecompSVD.cxx:416
virtual Bool_t TransSolve(TVectorD &b)
Solve A^T x=b assuming the SVD form of A is stored . Solution returned in b.
Definition: TDecompSVD.cxx:723
const char Option_t
Definition: RtypesCore.h:62
void Print(Option_t *opt="") const
Print class members.
Definition: TDecompSVD.cxx:919
Decomposition Base class.
Definition: TDecompBase.h:36
double inv(double x)
For comparisons.
Definition: inv.h:58
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TArc * a
Definition: textangle.C:12
virtual ~TDecompSVD()
Definition: TDecompSVD.h:52
virtual void SetMatrix(const TMatrixD &a)
Set matrix to be decomposed.
Definition: TDecompSVD.cxx:582
TMatrixD fV
Definition: TDecompSVD.h:31
virtual Int_t GetNcols() const
Definition: TDecompSVD.cxx:870
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...
Definition: TDecompSVD.cxx:307
Single Value Decomposition class.
Definition: TDecompSVD.h:25
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual TVectorD Solve(const TVectorD &b, Bool_t &ok)
Definition: TDecompSVD.h:68
const TMatrixD & GetU()
Definition: TDecompSVD.h:57
virtual Bool_t Decompose()
SVD decomposition of matrix If the decomposition succeeds, bit kDecomposed is set ...
Definition: TDecompSVD.cxx:123
static void SortSingular(TMatrixD &v, TMatrixD &u, TVectorD &sDiag)
Perform a permutation transformation on the diagonal matrix S&#39;, so that matrix S&#39;&#39; = U&#39;&#39;^T ...
Definition: TDecompSVD.cxx:497
const double tol
SVector< double, 2 > v
Definition: Dict.h:5
virtual TVectorD TransSolve(const TVectorD &b, Bool_t &ok)
Definition: TDecompSVD.h:74
Bool_t TestBit(UInt_t f) const
Definition: TObject.h:159
TMarker * m
Definition: textangle.C:8
TLine * l
Definition: textangle.C:4
virtual Int_t GetNrows() const
Definition: TDecompSVD.cxx:865
TMatrixD fU
Definition: TDecompSVD.h:30
Linear Algebra Package.
Int_t GetRowLwb() const
Definition: TDecompBase.h:76
virtual Bool_t Solve(TVectorD &b)
Solve Ax=b assuming the SVD form of A is stored .
Definition: TDecompSVD.cxx:615
static void Diag_1(TMatrixD &v, TVectorD &sDiag, TVectorD &oDiag, Int_t k)
Step 1 in the matrix diagonalization.
Definition: TDecompSVD.cxx:374
double Double_t
Definition: RtypesCore.h:55
const TMatrixD GetMatrix()
Reconstruct the original matrix using the decomposition parts.
Definition: TDecompSVD.cxx:557
TMatrixD Invert()
Definition: TDecompSVD.h:84
virtual const TMatrixDBase & GetDecompMatrix() const
Definition: TDecompSVD.h:41
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
Definition: TRolke.cxx:630
TVectorD fSig
Definition: TDecompSVD.h:32
const TMatrixD & GetV()
Definition: TDecompSVD.h:59
virtual Double_t Condition()
Matrix condition number.
Definition: TDecompSVD.cxx:823
TDecompSVD & operator=(const TDecompSVD &source)
Assignment operator.
Definition: TDecompSVD.cxx:930
static void Diag_2(TVectorD &sDiag, TVectorD &oDiag, Int_t k, Int_t l)
Step 2 in the matrix diagonalization.
Definition: TDecompSVD.cxx:398