Logo ROOT  
Reference Guide
Go to the documentation of this file.
1// @(#)root/matrix:$Id$
2// Authors: Fons Rademakers, Eddy Offermann Dec 2003
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 *************************************************************************/
12#ifndef ROOT_TDecompSVD
13#define ROOT_TDecompSVD
16// //
17// Single Value Decomposition class //
18// //
21#include "TDecompBase.h"
23class TDecompSVD : public TDecompBase
25protected :
27 // A = fU fSig fV^T
28 TMatrixD fU; // orthogonal matrix
29 TMatrixD fV; // orthogonal matrix
30 TVectorD fSig; // diagonal of diagonal matrix
32 static Bool_t Bidiagonalize(TMatrixD &v,TMatrixD &u,TVectorD &sDiag,TVectorD &oDiag);
33 static Bool_t Diagonalize (TMatrixD &v,TMatrixD &u,TVectorD &sDiag,TVectorD &oDiag);
34 static void Diag_1 (TMatrixD &v,TVectorD &sDiag,TVectorD &oDiag,Int_t k);
35 static void Diag_2 (TVectorD &sDiag,TVectorD &oDiag,Int_t k,Int_t l);
36 static void Diag_3 (TMatrixD &v,TMatrixD &u,TVectorD &sDiag,TVectorD &oDiag,Int_t k,Int_t l);
37 static void SortSingular (TMatrixD &v,TMatrixD &u,TVectorD &sDiag);
39 const TMatrixDBase &GetDecompMatrix() const override { return fU; }
41public :
43 enum {kWorkMax = 100}; // size of work array
45 TDecompSVD(): fU(), fV(), fSig() {}
46 TDecompSVD(Int_t nrows,Int_t ncols);
47 TDecompSVD(Int_t row_lwb,Int_t row_upb,Int_t col_lwb,Int_t col_upb);
48 TDecompSVD(const TMatrixD &m,Double_t tol = 0.0);
49 TDecompSVD(const TDecompSVD &another);
50 ~TDecompSVD() override {}
52 const TMatrixD GetMatrix ();
53 Int_t GetNrows () const override;
54 Int_t GetNcols () const override;
55 const TMatrixD &GetU () { if ( !TestBit(kDecomposed) ) Decompose();
56 return fU; }
57 const TMatrixD &GetV () { if ( !TestBit(kDecomposed) ) Decompose();
58 return fV; }
60 return fSig; }
62 virtual void SetMatrix (const TMatrixD &a);
64 Bool_t Decompose () override;
65 Bool_t Solve ( TVectorD &b) override;
66 TVectorD Solve (const TVectorD& b,Bool_t &ok) override { TVectorD x = b; ok = Solve(x);
67 const Int_t rowLwb = GetRowLwb();
68 x.ResizeTo(rowLwb,rowLwb+GetNcols()-1);
69 return x; }
70 Bool_t Solve ( TMatrixDColumn &b) override;
71 Bool_t TransSolve ( TVectorD &b) override;
72 TVectorD TransSolve (const TVectorD& b,Bool_t &ok) override { TVectorD x = b; ok = TransSolve(x);
73 const Int_t rowLwb = GetRowLwb();
74 x.ResizeTo(rowLwb,rowLwb+GetNcols()-1);
75 return x; }
76 Bool_t TransSolve ( TMatrixDColumn &b) override;
77 Double_t Condition () override;
78 void Det (Double_t &d1,Double_t &d2) override;
81 TMatrixD Invert (Bool_t &status);
82 TMatrixD Invert () {Bool_t status; return Invert(status); }
84 void Print(Option_t *opt ="") const override; // *MENU*
86 TDecompSVD &operator= (const TDecompSVD &source);
88 ClassDefOverride(TDecompSVD,1) // Matrix Decompositition SVD
bool Bool_t
Definition: RtypesCore.h:63
int Int_t
Definition: RtypesCore.h:45
double Double_t
Definition: RtypesCore.h:59
const char Option_t
Definition: RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
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 Float_t Float_t b
Decomposition Base class.
Definition: TDecompBase.h:34
Int_t GetRowLwb() const
Definition: TDecompBase.h:73
Single Value Decomposition class.
Definition: TDecompSVD.h:24
void Det(Double_t &d1, Double_t &d2) override
Matrix determinant det = d1*TMath::Power(2.,d2)
Definition: TDecompSVD.cxx:846
TVectorD fSig
Definition: TDecompSVD.h:30
const TMatrixDBase & GetDecompMatrix() const override
Definition: TDecompSVD.h:39
~TDecompSVD() override
Definition: TDecompSVD.h:50
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
static void Diag_2(TVectorD &sDiag, TVectorD &oDiag, Int_t k, Int_t l)
Step 2 in the matrix diagonalization.
Definition: TDecompSVD.cxx:398
TDecompSVD & operator=(const TDecompSVD &source)
Assignment operator.
Definition: TDecompSVD.cxx:930
Bool_t Solve(TVectorD &b) override
Solve Ax=b assuming the SVD form of A is stored .
Definition: TDecompSVD.cxx:615
TMatrixD Invert()
Definition: TDecompSVD.h:82
TMatrixD fV
Definition: TDecompSVD.h:29
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_1(TMatrixD &v, TVectorD &sDiag, TVectorD &oDiag, Int_t k)
Step 1 in the matrix diagonalization.
Definition: TDecompSVD.cxx:374
TMatrixD fU
Definition: TDecompSVD.h:28
const TVectorD & GetSig()
Definition: TDecompSVD.h:59
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
Double_t Condition() override
Matrix condition number.
Definition: TDecompSVD.cxx:823
const TMatrixD & GetV()
Definition: TDecompSVD.h:57
Bool_t Decompose() override
SVD decomposition of matrix If the decomposition succeeds, bit kDecomposed is set ,...
Definition: TDecompSVD.cxx:123
Int_t GetNrows() const override
Definition: TDecompSVD.cxx:865
const TMatrixD GetMatrix()
Reconstruct the original matrix using the decomposition parts.
Definition: TDecompSVD.cxx:557
Bool_t TransSolve(TVectorD &b) override
Solve A^T x=b assuming the SVD form of A is stored . Solution returned in b.
Definition: TDecompSVD.cxx:723
TVectorD Solve(const TVectorD &b, Bool_t &ok) override
Definition: TDecompSVD.h:66
virtual void SetMatrix(const TMatrixD &a)
Set matrix to be decomposed.
Definition: TDecompSVD.cxx:582
const TMatrixD & GetU()
Definition: TDecompSVD.h:55
Int_t GetNcols() const override
Definition: TDecompSVD.cxx:870
static void SortSingular(TMatrixD &v, TMatrixD &u, TVectorD &sDiag)
Perform a permutation transformation on the diagonal matrix S', so that matrix S'' = U''^T .
Definition: TDecompSVD.cxx:497
void Print(Option_t *opt="") const override
Print class members.
Definition: TDecompSVD.cxx:919
TVectorD TransSolve(const TVectorD &b, Bool_t &ok) override
Definition: TDecompSVD.h:72
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition: TObject.h:201
Double_t x[n]
Definition: legend1.C:17
void inv(rsa_NUMBER *, rsa_NUMBER *, rsa_NUMBER *)
Definition: rsaaux.cxx:949
TMarker m
Definition: textangle.C:8
TLine l
Definition: textangle.C:4
TArc a
Definition: textangle.C:12