STK++ 1.0
STK_Svd.h
Go to the documentation of this file.
00001 /*--------------------------------------------------------------------*/
00002 /*     Copyright (C) 2004-2007  Serge Iovleff
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU Lesser General Public License as
00006     published by the Free Software Foundation; either version 2 of the
00007     License, or (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this program; if not, write to the
00016     Free Software Foundation, Inc.,
00017     59 Temple Place,
00018     Suite 330,
00019     Boston, MA 02111-1307
00020     USA
00021 
00022     Contact : Serge.Iovleff@stkpp.org
00023 */
00024 
00025 /*
00026  * Project:  Algebra
00027  * Purpose:  Define The Svd Class.
00028  * Author:   Serge Iovleff, serge.iovleff@stkpp.org
00029  *
00030  **/
00031 
00036 #ifndef STK_SVD_H
00037 #define STK_SVD_H
00038 
00039 #include "../../Arrays/include/STK_Matrix.h"
00040 #include "../../Arrays/include/STK_MatrixSquare.h"
00041 
00042 namespace STK
00043 {
00044 
00060 class Svd
00061 {
00062   protected:
00063     /* containers */
00064     Matrix       U_;    
00065     MatrixSquare V_;    
00066     Point        D_;    
00067 
00068     /* dimensions */
00069     Integer ncolV_;   
00070     Integer ncolD_;   
00071     Integer ncolU_;   
00072     Integer nrowU_;   
00073 
00074     /* flags */
00075     bool withU_;        
00076     bool withV_;        
00077     bool ref_;          
00078 
00079     /* results */
00080     Real    norm_;       
00081     Integer rank_;       
00082     bool    error_;      
00083 
00084   public :   
00093     Svd( Matrix const&    A       = Matrix()
00094        , bool      ref     = false
00095        , bool      withU   = true
00096        , bool      withV   = true
00097        );
00098 
00102     Svd( const Svd &S);
00103 
00106     virtual ~Svd();
00107  
00111     Svd& operator=(const Svd &S);
00112 
00114     void clearU();
00115 
00117     void clearV();
00118 
00120     void clear();
00121 
00131     void newSvd( Matrix const&    A       = Matrix()
00132                , bool      withU   = true
00133                , bool      withV   = true
00134                );
00135 
00144     static Real bidiag(const Matrix& M, Point& D, Vector& F);
00145 
00154     static void rightEliminate( Point& D
00155                               , Vector& F
00156                               , Integer const& nrow
00157                               , MatrixSquare& V
00158                               , bool withV = true
00159                               , Real const& tol = Arithmetic<Real>::epsilon()
00160                               );
00161 
00170     static void leftEliminate( Point& D
00171                              , Vector& F
00172                              , Integer const& nrow
00173                              , Matrix& U
00174                              , bool withU = true
00175                              , Real const& tol = Arithmetic<Real>::epsilon()
00176                              );
00177 
00187     static bool diag( Point& D
00188                     , Vector& F
00189                     , Matrix& U
00190                     , MatrixSquare& V
00191                     , bool withU = true
00192                     , bool withV = true
00193                     , Real const& tol = Arithmetic<Real>::epsilon()
00194                     );
00195 
00197     inline Integer nrowU() const { return U_.sizeVe();}
00199     inline Integer ncolU() const { return U_.sizeHo();}
00201     inline Integer ncolD() const { return ncolD_;}
00203     inline Integer nrowV() const { return V_.sizeVe();}
00205     inline Integer ncolV() const { return V_.sizeHo();}
00207     inline Real normSup()  const { return norm_;}
00209     inline Integer rank()  const { return rank_;}
00211     inline bool error()    const { return error_;}
00213     inline Matrix const&       getU() const { return U_;}
00215     inline MatrixSquare const& getV() const { return V_;}
00217     inline const Point&        getD() const { return D_;}
00218     
00220     inline Matrix&       getU() { return U_;}
00222     inline MatrixSquare& getV() { return V_;}
00224     inline Point&        getD() { return D_;}
00225     
00226   private:
00228     Vector F_;
00230     void init();
00232     void compSvd();
00234     void compU();
00236     void compV();
00237 };
00238 
00239 } // namespace STK
00240 
00241 #endif
00242 // STK_SVD_H