00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef MATVEC_BG_MATRIX_H
00023 #define MATVEC_BG_MATRIX_H
00024
00025 #include <string>
00026 #include <fstream>
00027 #include "session.h"
00028 #include "matrix.h"
00029 #include "vector.h"
00030 #include "bg.h"
00031
00032 namespace matvec {
00033 class BGMatrix : public Matrix<BG> {
00034 friend class Model;
00035 public:
00036 BGMatrix(void) : Matrix<BG>() {}
00037 BGMatrix(const doubleMatrix &a);
00038 explicit BGMatrix(const size_type m,const size_type n) : Matrix<BG>(m,n){}
00039 BGMatrix(const size_type m,const size_type n,const BG** a) : Matrix<BG>(m,n,a){}
00040 BGMatrix(const BGMatrix& a) : Matrix<BG>(a) { }
00041 BGMatrix(const Matrix<BG>& a) : Matrix<BG>(a) { }
00042
00043 BGMatrix& operator = (const Matrix<BG> &a) { copy(a); return *this; }
00044 BGMatrix& operator = (const Matrix<bool> &a);
00045
00046 bool psd(void) const;
00047
00048
00049 BGMatrix& inv();
00050 BGMatrix ginv0(void) const;
00051 BGMatrix splines(const BGMatrix knots,const unsigned type=0) const;
00052 BGMatrix& ginv1(unsigned *irank=0);
00053 BGMatrix mat_log(double tol=0.0) const;
00054 BGMatrix mat_exp(double tol=0.0) const;
00055 void mat_exp_der(Vector<BGMatrix> &der,double tol=0.0) const;
00056 BGMatrix covariance(const BGMatrix &B) const;
00057 Vector<BG> variance(orientation orien = COLUMN) const;
00058 BGMatrix lu_solve(const BGMatrix& rhs);
00059 Vector<BG> lu_solve(const Vector<BG>& rhs);
00060 void gs_solve(const BGMatrix& v,BGMatrix& solmat,const double relax=1.0,
00061 const double stopval=0.001,const int mxiter=1000);
00062 void gs_solve(const Vector<BG>& v,Vector<BG>& solvec,const double relax=1.0,
00063 const double stopval=0.001,const int mxiter=1000);
00064
00065
00066 BG cond(void);
00067 BG det(void) const;
00068 BG norm(const int p) const;
00069 BG norm(const std::string &s) const;
00070 BG logdet(void);
00071 BG quadratic(const Vector<BG> &a,const Vector<BG> &b) const;
00072 BGMatrix& sqrtm(void);
00073 BGMatrix& identity(const int m,const int n);
00074 BGMatrix& identity(const int m) {return identity(m,m);}
00075 BGMatrix& identity(void) {return identity(num_rows(),num_cols());}
00076
00077
00078 bool symmetric(void) const {
00079 if (!me) return false;
00080 for (int i=1; i<nrow; ++i) {
00081 for (int j=0; j<i; ++j) {
00082 if (fabs(me[i][j]-me[j][i])> (fabs(me[i][j]+me[j][i])*SESSION.epsilon) && fabs(me[i][j]-me[j][i]) > SESSION.epsilon) return false;
00083 }
00084 }
00085 return true;
00086 } ;
00087
00088 protected:
00089
00090
00091 };
00092
00093 }
00094 #endif
00095