• Main Page
  • Classes
  • Files
  • File List

src/linalg.h

00001 /*
00002  *   See COPYING file distributed along with the psignifit package for
00003  *   the copyright and license terms
00004  */
00005 #ifndef LINALG_H
00006 #define LINALG_H
00007 
00008 #include <vector>
00009 #include <iostream>
00010 #include <iomanip>
00011 #include <cmath>
00012 
00013 /***************************************************************************************
00014  * This file defines vary basic linear algebra facilities
00015  *
00016  * These are not particularly fast or fancy implementations. They are just intended
00017  * to keep the number of dependencies low.
00018  */
00019 
00020 class MatrixError
00021 {
00022 };
00023 
00025 class Matrix
00026 {
00027         private:
00028                 double *data;
00029                 unsigned int nrows;
00030                 unsigned int ncols;
00031                 // given a decomposition A=LU these two methods help solving the equation Ax=b:
00032                 std::vector<double> forward ( const Matrix* LU, const std::vector<double>& b );    // forward solution of Ly=b
00033                 std::vector<double> backward ( const Matrix*LU, const std::vector<double>& y );    // backward solution of Ux=y
00034         public:
00035                 Matrix ( const std::vector< std::vector<double> >& A );      
00036                 Matrix ( unsigned int nrows, unsigned int ncols);                   
00037                 Matrix ( const Matrix& A );                                  
00038                 ~Matrix ( void ) { delete [] data; }                         
00039                 double& operator() ( unsigned int i, unsigned int j ) const; 
00040                 void print ( void );                                         
00041                 unsigned int getnrows ( void ) const { return nrows; }       
00042                 unsigned int getncols ( void ) const { return ncols; }       
00043                 Matrix* cholesky_dec ( void ) const;                         
00044                 Matrix* lu_dec ( void ) const;                               
00045                 Matrix * qr_dec ( void ) const;                              
00046                 Matrix * inverse_qr ( void ) const;                          
00047                 Matrix * regularized_inverse ( double alpha ) const;         
00048                 std::vector<double> solve ( const std::vector<double>& b );  
00049                 Matrix* inverse ( void );                                    
00050                 std::vector<double> operator* ( std::vector<double>& x );    
00051                 void scale ( double a );                                     
00052                 bool symmetric ( void );                                     
00053 };
00054 
00055 std::vector<double> leastsq ( const Matrix *A, const std::vector<double>& b );  
00056 
00057 std::vector<double> leastsq ( const Matrix *M ); 
00058 
00059 #endif

Generated on Mon Jul 4 2011 14:52:04 for Psi++ by  doxygen 1.7.1