ROOT logo
// @(#)root/matrix:$Id: TDecompSVD.h 20882 2007-11-19 11:31:26Z rdm $
// Authors: Fons Rademakers, Eddy Offermann   Dec 2003

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TDecompSVD
#define ROOT_TDecompSVD

///////////////////////////////////////////////////////////////////////////
//                                                                       //
// Single Value Decomposition class                                      //
//                                                                       //
///////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TDecompBase
#include "TDecompBase.h"
#endif

class TDecompSVD : public TDecompBase
{
protected :

   //  A = fU fSig fV^T
   TMatrixD fU;    // orthogonal matrix
   TMatrixD fV;    // orthogonal matrix
   TVectorD fSig;  // diagonal of diagonal matrix

   static Bool_t Bidiagonalize(TMatrixD &v,TMatrixD &u,TVectorD &sDiag,TVectorD &oDiag);
   static Bool_t Diagonalize  (TMatrixD &v,TMatrixD &u,TVectorD &sDiag,TVectorD &oDiag);
   static void   Diag_1       (TMatrixD &v,TVectorD &sDiag,TVectorD &oDiag,Int_t k);
   static void   Diag_2       (TVectorD &sDiag,TVectorD &oDiag,Int_t k,Int_t l);
   static void   Diag_3       (TMatrixD &v,TMatrixD &u,TVectorD &sDiag,TVectorD &oDiag,Int_t k,Int_t l);
   static void   SortSingular (TMatrixD &v,TMatrixD &u,TVectorD &sDiag);

   virtual const TMatrixDBase &GetDecompMatrix() const { return fU; }

public :

   enum {kWorkMax = 100}; // size of work array

   TDecompSVD(): fU(), fV(), fSig() {}
   TDecompSVD(Int_t nrows,Int_t ncols);
   TDecompSVD(Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb);
   TDecompSVD(const TMatrixD &m,Double_t tol = 0.0);
   TDecompSVD(const TDecompSVD &another);
   virtual ~TDecompSVD() {}

           const TMatrixD  GetMatrix ();
   virtual       Int_t     GetNrows  () const { return fU.GetNrows(); }
   virtual       Int_t     GetNcols  () const { return fV.GetNcols(); }
           const TMatrixD &GetU      ()       { if ( !TestBit(kDecomposed) ) Decompose();
                                                 return fU; }
           const TMatrixD &GetV      ()       { if ( !TestBit(kDecomposed) ) Decompose();
                                                return fV; }
           const TVectorD &GetSig    ()       { if ( !TestBit(kDecomposed) ) Decompose();
                                                return fSig; }

   virtual       void      SetMatrix (const TMatrixD &a);

   virtual Bool_t   Decompose  ();
   virtual Bool_t   Solve      (      TVectorD &b);
   virtual TVectorD Solve      (const TVectorD& b,Bool_t &ok) { TVectorD x = b; ok = Solve(x); 
                                                                const Int_t rowLwb = GetRowLwb();
                                                                x.ResizeTo(rowLwb,rowLwb+GetNcols()-1);
                                                                return x; }
   virtual Bool_t   Solve      (      TMatrixDColumn &b);
   virtual Bool_t   TransSolve (      TVectorD &b);
   virtual TVectorD TransSolve (const TVectorD& b,Bool_t &ok) { TVectorD x = b; ok = TransSolve(x);
                                                                const Int_t rowLwb = GetRowLwb();
                                                                x.ResizeTo(rowLwb,rowLwb+GetNcols()-1);
                                                                return x; }
   virtual Bool_t   TransSolve (      TMatrixDColumn &b);
   virtual Double_t Condition  ();
   virtual void     Det        (Double_t &d1,Double_t &d2);

           Bool_t   Invert     (TMatrixD &inv);
           TMatrixD Invert     (Bool_t &status);
           TMatrixD Invert     () {Bool_t status; return Invert(status); }

   void Print(Option_t *opt ="") const; // *MENU*

   TDecompSVD &operator= (const TDecompSVD &source);

   ClassDef(TDecompSVD,1) // Matrix Decompositition SVD
};

#endif
 TDecompSVD.h:1
 TDecompSVD.h:2
 TDecompSVD.h:3
 TDecompSVD.h:4
 TDecompSVD.h:5
 TDecompSVD.h:6
 TDecompSVD.h:7
 TDecompSVD.h:8
 TDecompSVD.h:9
 TDecompSVD.h:10
 TDecompSVD.h:11
 TDecompSVD.h:12
 TDecompSVD.h:13
 TDecompSVD.h:14
 TDecompSVD.h:15
 TDecompSVD.h:16
 TDecompSVD.h:17
 TDecompSVD.h:18
 TDecompSVD.h:19
 TDecompSVD.h:20
 TDecompSVD.h:21
 TDecompSVD.h:22
 TDecompSVD.h:23
 TDecompSVD.h:24
 TDecompSVD.h:25
 TDecompSVD.h:26
 TDecompSVD.h:27
 TDecompSVD.h:28
 TDecompSVD.h:29
 TDecompSVD.h:30
 TDecompSVD.h:31
 TDecompSVD.h:32
 TDecompSVD.h:33
 TDecompSVD.h:34
 TDecompSVD.h:35
 TDecompSVD.h:36
 TDecompSVD.h:37
 TDecompSVD.h:38
 TDecompSVD.h:39
 TDecompSVD.h:40
 TDecompSVD.h:41
 TDecompSVD.h:42
 TDecompSVD.h:43
 TDecompSVD.h:44
 TDecompSVD.h:45
 TDecompSVD.h:46
 TDecompSVD.h:47
 TDecompSVD.h:48
 TDecompSVD.h:49
 TDecompSVD.h:50
 TDecompSVD.h:51
 TDecompSVD.h:52
 TDecompSVD.h:53
 TDecompSVD.h:54
 TDecompSVD.h:55
 TDecompSVD.h:56
 TDecompSVD.h:57
 TDecompSVD.h:58
 TDecompSVD.h:59
 TDecompSVD.h:60
 TDecompSVD.h:61
 TDecompSVD.h:62
 TDecompSVD.h:63
 TDecompSVD.h:64
 TDecompSVD.h:65
 TDecompSVD.h:66
 TDecompSVD.h:67
 TDecompSVD.h:68
 TDecompSVD.h:69
 TDecompSVD.h:70
 TDecompSVD.h:71
 TDecompSVD.h:72
 TDecompSVD.h:73
 TDecompSVD.h:74
 TDecompSVD.h:75
 TDecompSVD.h:76
 TDecompSVD.h:77
 TDecompSVD.h:78
 TDecompSVD.h:79
 TDecompSVD.h:80
 TDecompSVD.h:81
 TDecompSVD.h:82
 TDecompSVD.h:83
 TDecompSVD.h:84
 TDecompSVD.h:85
 TDecompSVD.h:86
 TDecompSVD.h:87
 TDecompSVD.h:88
 TDecompSVD.h:89
 TDecompSVD.h:90
 TDecompSVD.h:91
 TDecompSVD.h:92
 TDecompSVD.h:93