Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

matvec::BGMatrix Class Reference

#include <bgmatrix.h>

Inheritance diagram for matvec::BGMatrix:

matvec::Matrix< BG > List of all members.

Public Types

typedef int size_type
typedef BG value_type
typedef BG element_type
typedef BGpointer
typedef BGiterator
typedef BGreference
typedef const BGconst_iterator
typedef const BGconst_pointer
typedef const BGconst_reference
typedef std::reverse_iterator<
iterator
reverse_iterator
typedef std::reverse_iterator<
const_iterator
const_reverse_iterator

Public Methods

 BGMatrix (void)
 BGMatrix (const doubleMatrix &a)
 BGMatrix (const size_type m, const size_type n)
 BGMatrix (const size_type m, const size_type n, const BG **a)
 BGMatrix (const BGMatrix &a)
 BGMatrix (const Matrix< BG > &a)
BGMatrix & operator= (const Matrix< BG > &a)
BGMatrix & operator= (const Matrix< bool > &a)
bool psd (void) const
BGMatrix & inv ()
BGMatrix ginv0 (void) const
BGMatrix splines (const BGMatrix knots, const unsigned type=0) const
BGMatrix & ginv1 (unsigned *irank=0)
BGMatrix mat_log (double tol=0.0) const
BGMatrix mat_exp (double tol=0.0) const
void mat_exp_der (Vector< BGMatrix > &der, double tol=0.0) const
BGMatrix covariance (const BGMatrix &B) const
Vector< BGvariance (orientation orien=COLUMN) const
BGMatrix lu_solve (const BGMatrix &rhs)
Vector< BGlu_solve (const Vector< BG > &rhs)
void gs_solve (const BGMatrix &v, BGMatrix &solmat, const double relax=1.0, const double stopval=0.001, const int mxiter=1000)
void gs_solve (const Vector< BG > &v, Vector< BG > &solvec, const double relax=1.0, const double stopval=0.001, const int mxiter=1000)
BG cond (void)
BG det (void) const
BG norm (const int p) const
BG norm (const std::string &s) const
BG logdet (void)
BG quadratic (const Vector< BG > &a, const Vector< BG > &b) const
BGMatrix & sqrtm (void)
BGMatrix & identity (const int m, const int n)
BGMatrix & identity (const int m)
BGMatrix & identity (void)
bool symmetric (void) const
BG ** begin (void)
const BG ** begin (void) const
void copy (const Matrix &a)
Matrixassign (const Matrix &a)
Matrixassign (const BG &x)
Matrixresize (const size_type n, const size_type m, const BG &val=BG())
Matrixresize (const size_type n, const size_type m, const BG *a)
Matrixresize (const Matrix &a)
Matrixreserve (const size_type n, const size_type m)
Matrix operator+ (const Matrix &a) const
Matrix operator+ (const BG &x) const
Matrixoperator+ (void)
Matrix operator- (const Matrix &a) const
Matrix operator- (const BG &x) const
Matrix operator- (void) const
Matrix operator * (const Matrix &a) const
Vector< BGoperator * (const Vector< BG > &a) const
Matrix operator * (const BG &x) const
Matrix operator/ (const Matrix &a) const
Matrix operator/ (const BG &x) const
Matrixoperator+= (const Matrix &a)
Matrixoperator+= (const BG &x)
Matrixoperator-= (const Matrix &a)
Matrixoperator-= (const BG &x)
Matrixoperator *= (const Matrix &a)
Matrixoperator *= (const BG &x)
Matrixoperator/= (const Matrix &a)
Matrixoperator/= (const BG &x)
BGoperator[] (const size_type i)
const BGoperator[] (const size_type i) const
BGoperator() (const size_type i, const size_type j)
Matrix< bool > operator! (void) const
Matrix< bool > operator== (const Matrix &a) const
Matrix< bool > operator== (const BG &x) const
Matrix< bool > operator< (const Matrix &a) const
Matrix< bool > operator< (const BG &x) const
Matrix< bool > operator> (const Matrix &a) const
Matrix< bool > operator> (const BG &x) const
Matrix< bool > operator!= (const Matrix &a) const
Matrix< bool > operator!= (const BG &x) const
Matrix< bool > operator<= (const Matrix &a) const
Matrix< bool > operator<= (const BG &x) const
Matrix< bool > operator>= (const Matrix &a) const
Matrix< bool > operator>= (const BG &x) const
bool all (void) const
bool any (void) const
bool empty (void) const
bool save (const std::string &fname, const int io_mode=std::ios::out) const
Matrix apply (BG(*f)(BG)) const
Matrix apply (BG(*f)(BG, BG), const Matrix &b) const
Matrix apply (BG(*f)(BG, BG), const BG &b) const
Matrix submat (const size_type idx1, const size_type idx2, const int len1=0, const int len2=0) const
Matrix submat (const Matrix< bool > &a) const
Matrix transpose (void) const
Matrix kron (const Matrix &b) const
Matrix reshape (const size_type m, const size_type n, orientation orient=COLUMN) const
Matrix diag (void) const
Vector< BGdiag (const size_type k) const
Vector< BGvec (orientation orient=COLUMN) const
Vector< BGsum (orientation orient=COLUMN) const
Vector< BGsumsq (orientation orient=COLUMN) const
Vector< BGmax (orientation orient=COLUMN) const
Vector< BGmin (orientation orient=COLUMN) const
virtual std::ostream & print (std::ostream &os=std::cout) const
BG trace (BG init=BG()) const
BGat (const size_type i, const size_type j)
Matrixsortby (orientation orient, const size_type k)
int size (void) const
int num_rows (void) const
int num_cols (void) const
void clear (void)
void input (const std::string &fname, const size_type m, const size_type n)
void initialize (const size_type m, const size_type n, const BG **a)

Public Attributes

BG ** me
int nrow
int ncol

Friends

class Model

Member Typedef Documentation

typedef const BG* matvec::Matrix< BG >::const_iterator [inherited]
 

Definition at line 50 of file matrix.h.

typedef const BG* matvec::Matrix< BG >::const_pointer [inherited]
 

Definition at line 51 of file matrix.h.

typedef const BG& matvec::Matrix< BG >::const_reference [inherited]
 

Definition at line 52 of file matrix.h.

typedef std::reverse_iterator<const_iterator> matvec::Matrix< BG >::const_reverse_iterator [inherited]
 

Definition at line 54 of file matrix.h.

typedef BG matvec::Matrix< BG >::element_type [inherited]
 

Definition at line 46 of file matrix.h.

typedef BG* matvec::Matrix< BG >::iterator [inherited]
 

Definition at line 48 of file matrix.h.

typedef BG* matvec::Matrix< BG >::pointer [inherited]
 

Definition at line 47 of file matrix.h.

typedef BG& matvec::Matrix< BG >::reference [inherited]
 

Definition at line 49 of file matrix.h.

typedef std::reverse_iterator<iterator> matvec::Matrix< BG >::reverse_iterator [inherited]
 

Definition at line 53 of file matrix.h.

typedef int matvec::Matrix< BG >::size_type [inherited]
 

Definition at line 44 of file matrix.h.

Referenced by BGMatrix().

typedef BG matvec::Matrix< BG >::value_type [inherited]
 

Definition at line 45 of file matrix.h.


Constructor & Destructor Documentation

matvec::BGMatrix::BGMatrix void    [inline]
 

Definition at line 36 of file bgmatrix.h.

00036 : Matrix<BG>() {}

matvec::BGMatrix::BGMatrix const doubleMatrix   a
 

Definition at line 34 of file bgmatrix.cpp.

References matvec::Matrix< double >::num_cols(), matvec::Matrix< double >::num_rows(), and matvec::Matrix< BG >::resize().

00035 {
00036    resize(a.num_rows(),a.num_cols());
00037    for (int j,i=0; i<a.num_rows(); ++i) {
00038      for (j=0; j<a.num_cols(); ++j) {
00039        Matrix<BG>::me[i][j] = a[i][j];
00040      }
00041    }
00042 }

matvec::BGMatrix::BGMatrix const size_type    m,
const size_type    n
[inline, explicit]
 

Definition at line 38 of file bgmatrix.h.

References matvec::Matrix< BG >::size_type.

00038 : Matrix<BG>(m,n){}

matvec::BGMatrix::BGMatrix const size_type    m,
const size_type    n,
const BG **    a
[inline]
 

Definition at line 39 of file bgmatrix.h.

References matvec::Matrix< BG >::size_type.

00039 : Matrix<BG>(m,n,a){}

matvec::BGMatrix::BGMatrix const BGMatrix &    a [inline]
 

Definition at line 40 of file bgmatrix.h.

00040 : Matrix<BG>(a) { }

matvec::BGMatrix::BGMatrix const Matrix< BG > &    a [inline]
 

Definition at line 41 of file bgmatrix.h.

00041 : Matrix<BG>(a) { }


Member Function Documentation

bool matvec::Matrix< BG >::all void    const [inherited]
 

bool matvec::Matrix< BG >::any void    const [inherited]
 

Matrix matvec::Matrix< BG >::apply BG(*    f)(BG, BG),
const BG   b
const [inherited]
 

Matrix matvec::Matrix< BG >::apply BG(*    f)(BG, BG),
const Matrix< BG > &    b
const [inherited]
 

Matrix matvec::Matrix< BG >::apply BG(*    f)(BG) const [inherited]
 

Matrix& matvec::Matrix< BG >::assign const BG   x [inherited]
 

Matrix& matvec::Matrix< BG >::assign const Matrix< BG > &    a [inline, inherited]
 

Definition at line 81 of file matrix.h.

00081 {copy(a); return *this;}

BG& matvec::Matrix< BG >::at const size_type    i,
const size_type    j
[inherited]
 

const BG** matvec::Matrix< BG >::begin void    const [inline, inherited]
 

Definition at line 76 of file matrix.h.

00076 { return (const T**)me; }

BG** matvec::Matrix< BG >::begin void    [inline, inherited]
 

Definition at line 75 of file matrix.h.

Referenced by det(), ginv1(), identity(), psd(), and sqrtm().

00075 { return me; }

void matvec::Matrix< BG >::clear void    [inherited]
 

BG matvec::BGMatrix::cond void   
 

void matvec::Matrix< BG >::copy const Matrix< BG > &    a [inherited]
 

Referenced by operator=().

BGMatrix matvec::BGMatrix::covariance const BGMatrix &    B const
 

Definition at line 314 of file bgmatrix.cpp.

References matvec::Matrix< BG >::me, matvec::Matrix< BG >::ncol, matvec::Matrix< BG >::nrow, matvec::Matrix< BG >::num_cols(), and matvec::Matrix< BG >::num_rows().

00315 {
00316    int nrow =  Matrix<BG>::nrow;
00317    int ncol =  Matrix<BG>::ncol;
00318    BG** me =  Matrix<BG>::me;
00319 
00320    assert (nrow == B.num_rows() && ncol == B.num_cols());
00321    BGMatrix temp(ncol,ncol);
00322    int i,j,k;
00323    BG ss,sx,sy;
00324    for (i=0; i<ncol; ++i) {
00325       for (j=0; j<=i; ++j) {
00326          for (ss=0.0,sx=0.0,sy=0.0,k=0; k<nrow; ++k) {
00327             ss += me[k][i]*B[k][j];
00328             sx += me[k][i];
00329             sy += B[k][j];
00330          }
00331          temp[i][j] = temp[j][i] = (ss - sx*sy/ncol)/(ncol - 1);
00332       }
00333    }
00334    return temp;
00335 }

BG matvec::BGMatrix::det void    const
 

Definition at line 223 of file bgmatrix.cpp.

References matvec::Vector< T >::begin(), matvec::Matrix< BG >::begin(), matvec::Session::epsilon, matvec::ludcmp(), matvec::Matrix< BG >::ncol, matvec::Matrix< BG >::nrow, and matvec::SESSION.

00224 {
00225    int nrow =  Matrix<BG>::nrow;
00226    int ncol =  Matrix<BG>::ncol;
00227 
00228    BG detval = 0.0;
00229    if ( nrow != ncol ) throw exception("BGMatrix::det(): matrix must be square");
00230    int i,d;
00231    Vector<int> indx(nrow);
00232    BGMatrix temp(*this);
00233    ludcmp(temp.begin(),nrow,indx.begin(),d, SESSION.epsilon);
00234    detval = (BG)d;
00235    for (i=0; i<nrow; i++) detval *= temp[i][i];
00236    return detval;
00237 }

Vector<BG> matvec::Matrix< BG >::diag const size_type    k const [inherited]
 

Matrix matvec::Matrix< BG >::diag void    const [inherited]
 

Referenced by gs_solve(), and norm().

bool matvec::Matrix< BG >::empty void    const [inline, inherited]
 

Definition at line 138 of file matrix.h.

00138 { return (nrow == 0 || ncol == 0); }

BGMatrix matvec::BGMatrix::ginv0 void    const
 

BGMatrix & matvec::BGMatrix::ginv1 unsigned *    irank = 0
 

Definition at line 91 of file bgmatrix.cpp.

References matvec::Matrix< BG >::begin(), matvec::Session::epsilon, matvec::ginverse1(), matvec::Matrix< BG >::num_rows(), matvec::SESSION, and symmetric().

00092 {         // it only works for symmetric-positive-semidefinite matrix
00093           //  Matrix itself becomes its inverse;
00094    if (!this->symmetric()) {
00095      throw exception("BGMatrix::ginv1(): matrix must be symmetric");
00096    }
00097    BG lgdet;
00098    unsigned myrank = ginverse1(begin(),num_rows(),lgdet,1,SESSION.epsilon);
00099    if (irank) *irank = myrank;
00100    return *this;
00101 }

void matvec::BGMatrix::gs_solve const Vector< BG > &    v,
Vector< BG > &    solvec,
const double    relax = 1.0,
const double    stopval = 0.001,
const int    mxiter = 1000
 

Definition at line 205 of file bgmatrix.cpp.

References gs_solve(), matvec::Vector< T >::resize(), and matvec::Vector< T >::size().

00207 {
00208    int n = rhs.size();
00209    BGMatrix bmat(n,1),solmat(n,1);
00210    if (sol.size() != n) {
00211       sol.resize(n);
00212    }
00213    int i;
00214    for (i=0; i<n; i++) {
00215       bmat[i][0] = rhs[i];
00216       solmat[i][0] = sol[i];
00217    }
00218    gs_solve(bmat,solmat,relax,stopval,mxiter);
00219    for (i=0; i<n; i++) sol[i] = solmat[i][0];
00220 }

void matvec::BGMatrix::gs_solve const BGMatrix &    v,
BGMatrix &    solmat,
const double    relax = 1.0,
const double    stopval = 0.001,
const int    mxiter = 1000
 

Definition at line 139 of file bgmatrix.cpp.

References matvec::Matrix< BG >::diag(), matvec::Session::epsilon, matvec::BG::f, matvec::Matrix< BG >::me, matvec::Matrix< BG >::ncol, matvec::Matrix< BG >::nrow, matvec::Matrix< BG >::num_cols(), matvec::Matrix< BG >::num_rows(), matvec::Matrix< BG >::resize(), matvec::SESSION, and matvec::warning().

Referenced by gs_solve().

00141 {
00142   //   relax    relaxation coefficient, relax=1.2 seems good for some case
00143   //   stopval  the accuracy at which iteration stops.
00144   //   mxiter   maximum number of iterations allowed
00145 
00146    int nrow =  Matrix<BG>::nrow;
00147    int ncol =  Matrix<BG>::ncol;
00148    BG** me =  Matrix<BG>::me;
00149 
00150    int m = rhs.num_rows();
00151    int n = rhs.num_cols();
00152    if (nrow != ncol) throw exception("BGMatrix::gs_solve(): matrix must be square ");
00153    if (ncol != m ) throw exception("BGMatrix::gs_solve(): matrix and rhs are not conformable");
00154    if (solmat.num_rows() != m || solmat.num_cols() != n) {
00155       solmat.resize(m,n);
00156    }
00157    int i,j,k;
00158    BG diag;
00159    int niter = 0;
00160    BG a,cmax;
00161    BG tol = SESSION.epsilon;
00162 
00163    Vector<BG> oldsol(n);
00164    Vector<BG> newsol(n);
00165    Vector<BG> cval(n);
00166    Vector<BG> local(n);
00167    do {                             // now iteration begins
00168       cmax = 0.0;
00169       for (i=0; i<m; i++) {
00170          for (k=0; k<n; k++) {
00171             oldsol[k] = solmat[i][k];
00172             local[k] = 0.0;
00173          }
00174          for (j=0; j<m; j++) {
00175             a = me[i][j];
00176             if (j != i) for (k=0; k<n; k++) local[k] += a * solmat[j][k];
00177          }
00178          diag = me[i][i];
00179          if (diag > tol) {
00180             for (k=0; k<n; k++) {
00181                newsol[k] = (rhs[i][k] - local[k])/diag;
00182                cval[k] = (newsol[k] - oldsol[k])*relax;
00183                if (fabs(cval[k]) > cmax) cmax = fabs(cval[k]);
00184                newsol[k] = solmat[i][k] = oldsol[k] + cval[k];
00185             }
00186          }
00187          else if (diag > -tol) {
00188             throw exception("BGMatrix::gs_solve(): zero-diagonal found in Matrix::gs_solve()");
00189          }
00190          else {
00191             throw exception("BGMatrix::gs_solve(): matrix is not psd");
00192          }
00193       }
00194       niter += 1;
00195       if ( (niter % 10) ==0) {
00196          std::cout << " GS: # of iter = " << niter << ", max_change = "
00197               << cmax << std::endl;
00198       }
00199    } while (niter <= mxiter && cmax > stopval);
00200    if (cmax > stopval) {
00201       warning("BGMatrix::gs_solve(): not converge: %20.10f",cmax.f);
00202    }
00203 }

BGMatrix& matvec::BGMatrix::identity void    [inline]
 

Definition at line 75 of file bgmatrix.h.

References matvec::Matrix< BG >::num_cols(), and matvec::Matrix< BG >::num_rows().

Referenced by identity().

00075 {return identity(num_rows(),num_cols());}

BGMatrix& matvec::BGMatrix::identity const int    m [inline]
 

Definition at line 74 of file bgmatrix.h.

References identity().

00074 {return identity(m,m);}

BGMatrix & matvec::BGMatrix::identity const int    m,
const int    n
 

Definition at line 345 of file bgmatrix.cpp.

References matvec::Matrix< BG >::begin(), matvec::Matrix< BG >::me, and matvec::Matrix< BG >::resize().

00346 {
00347    resize(m,n);
00348    BG **me = begin();
00349    for (int i=0; i<m; ++i) if (i < n) me[i][i] = 1.0;
00350    return *this;
00351 }

void matvec::Matrix< BG >::initialize const size_type    m,
const size_type    n,
const BG **    a
[inherited]
 

void matvec::Matrix< BG >::input const std::string &    fname,
const size_type    m,
const size_type    n
[inherited]
 

BGMatrix & matvec::BGMatrix::inv  
 

Definition at line 60 of file bgmatrix.cpp.

References matvec::Vector< T >::assign(), matvec::Vector< T >::begin(), matvec::Session::epsilon, matvec::lubksb(), matvec::ludcmp(), matvec::Matrix< BG >::me, matvec::Matrix< BG >::ncol, matvec::Matrix< BG >::nrow, matvec::Matrix< T >::reserve(), matvec::Vector< T >::reserve(), and matvec::SESSION.

00061 {
00062    //////////////////////////////////////////////////////////
00063    // A itself turns into its inverse
00064    // returns non_singular indicator
00065    // REQUIREMENTS:  A must be nonsingular
00066    /////////////////////////////////////////////////////////
00067    int nrow =  Matrix<BG>::nrow;
00068    int ncol =  Matrix<BG>::ncol;
00069    BG** me =  Matrix<BG>::me;
00070 
00071    int i,j,d;
00072    if ( nrow != ncol ) throw exception("BGMatrix::inv(): matrix must be square");
00073    Vector<int>    indx;  indx.reserve(nrow);
00074    Vector<BG> tempcol; tempcol.reserve(nrow);
00075    Matrix<BG> temp; temp.reserve(nrow,nrow);
00076 
00077    ludcmp(me,nrow,indx.begin(),d, SESSION.epsilon);
00078    for (j=0; j<nrow; j++) {
00079       tempcol.assign(0.0);
00080       tempcol[j] = 1.0;
00081       lubksb(me,nrow,indx.begin(),tempcol.begin());
00082       for (i=0; i<nrow;i++) temp[i][j] = tempcol[i];
00083    }
00084    //for (i=0;i<nrow; i++) memcpy(me[i],temp[i],sizeof(BG)*nrow);
00085    for (j=0; j<nrow; j++) { 
00086      for (i=0; i<nrow;i++) me[i][j] = temp[i][j];
00087    }
00088    return *this;
00089 }

Matrix matvec::Matrix< BG >::kron const Matrix< BG > &    b const [inherited]
 

BG matvec::BGMatrix::logdet void   
 

Definition at line 253 of file bgmatrix.cpp.

References matvec::Matrix< T >::begin(), matvec::Session::epsilon, matvec::ginverse1(), matvec::Matrix< BG >::me, matvec::Matrix< BG >::ncol, matvec::Matrix< BG >::nrow, matvec::SESSION, and symmetric().

00254 {
00255    int nrow =  Matrix<BG>::nrow;
00256    int ncol =  Matrix<BG>::ncol;
00257    BG** me =  Matrix<BG>::me;
00258 
00259    BG retval = 0.0;
00260    if (!this->symmetric()) throw exception("BGMatrix::logdet(): matrix must be symmetric");
00261    Matrix<BG> temp(*this);
00262 
00263    ginverse1(temp.begin(),nrow,retval,3,SESSION.epsilon);
00264    return retval;
00265 }

Vector< BG > matvec::BGMatrix::lu_solve const Vector< BG > &    rhs
 

Definition at line 129 of file bgmatrix.cpp.

References lu_solve(), matvec::Vector< T >::size(), and matvec::Matrix< BG >::vec().

00130 {
00131    int n = rhs.size();
00132    BGMatrix bmat(n,1);
00133    for (int i=0; i<n; i++) bmat[i][0] = rhs[i];
00134    bmat = lu_solve(bmat);
00135    return bmat.vec();
00136 }

BGMatrix matvec::BGMatrix::lu_solve const BGMatrix &    rhs
 

Definition at line 104 of file bgmatrix.cpp.

References matvec::Vector< T >::begin(), matvec::Session::epsilon, matvec::lubksb(), matvec::ludcmp(), matvec::Matrix< BG >::me, matvec::Matrix< BG >::ncol, matvec::Matrix< BG >::nrow, matvec::Matrix< BG >::num_cols(), matvec::Matrix< BG >::num_rows(), matvec::Vector< T >::reserve(), matvec::SESSION, and matvec::warning().

Referenced by lu_solve().

00105 {
00106    int nrow =  Matrix<BG>::nrow;
00107    int ncol =  Matrix<BG>::ncol;
00108    BG** me =  Matrix<BG>::me;
00109 
00110    if (nrow  != ncol) throw exception("BGMatrix::lu_solve(): matrix is not square ");
00111    int m = rhs.num_rows();
00112    int n = rhs.num_cols();
00113 
00114    if (ncol != m ) throw exception("BGMatrix::lu_solve(): bad arg");
00115    BGMatrix solmat(m,n);
00116    int i,j,d;
00117    Vector<BG> solvec; solvec.reserve(m);
00118    Vector<int> indx;  indx.reserve(m);
00119    ludcmp(me,nrow,indx.begin(),d,SESSION.epsilon);
00120    warning("A.solve(b), A destroyed");
00121    for (j=0; j<n; j++) {
00122       for (i=0; i<m; i++) solvec[i] = rhs[i][j];
00123       lubksb(me,m,indx.begin(),solvec.begin());
00124       for (i=0; i<m; i++) solmat[i][j] = solvec[i];
00125    }
00126    return solmat;
00127 }

BGMatrix matvec::BGMatrix::mat_exp double    tol = 0.0 const
 

void matvec::BGMatrix::mat_exp_der Vector< BGMatrix > &    der,
double    tol = 0.0
const
 

BGMatrix matvec::BGMatrix::mat_log double    tol = 0.0 const
 

Vector<BG> matvec::Matrix< BG >::max orientation    orient = COLUMN const [inherited]
 

Vector<BG> matvec::Matrix< BG >::min orientation    orient = COLUMN const [inherited]
 

BG matvec::BGMatrix::norm const std::string &    s const
 

Definition at line 240 of file bgmatrix.cpp.

References matvec::Matrix< BG >::diag(), matvec::sqrt(), matvec::Matrix< BG >::sum(), and matvec::Matrix< BG >::transpose().

00241 {
00242    BG retval = 0.0;
00243    BGMatrix A = this->transpose();
00244    if (s == "fro") {
00245       retval = sqrt((A*(*this)).diag(0).sum());
00246    }
00247    else {
00248       throw exception("BGMatrix::norm((): bad arg, it must be either \"inf\" or \"fro\" ");
00249    }
00250    return retval;
00251 }

BG matvec::BGMatrix::norm const int    p const
 

int matvec::Matrix< BG >::num_cols void    const [inline, inherited]
 

Definition at line 163 of file matrix.h.

Referenced by covariance(), gs_solve(), identity(), and lu_solve().

00163 { return ncol; }

int matvec::Matrix< BG >::num_rows void    const [inline, inherited]
 

Definition at line 162 of file matrix.h.

Referenced by covariance(), ginv1(), gs_solve(), identity(), lu_solve(), and sqrtm().

00162 { return nrow; }

Matrix matvec::Matrix< BG >::operator * const BG   x const [inherited]
 

Vector<BG> matvec::Matrix< BG >::operator * const Vector< BG > &    a const [inherited]
 

Matrix matvec::Matrix< BG >::operator * const Matrix< BG > &    a const [inherited]
 

Matrix& matvec::Matrix< BG >::operator *= const BG   x [inherited]
 

Matrix& matvec::Matrix< BG >::operator *= const Matrix< BG > &    a [inherited]
 

Matrix<bool> matvec::Matrix< BG >::operator! void    const [inherited]
 

Matrix<bool> matvec::Matrix< BG >::operator!= const BG   x const [inherited]
 

Matrix<bool> matvec::Matrix< BG >::operator!= const Matrix< BG > &    a const [inherited]
 

BG& matvec::Matrix< BG >::operator() const size_type    i,
const size_type    j
[inherited]
 

Matrix& matvec::Matrix< BG >::operator+ void    [inline, inherited]
 

Definition at line 117 of file matrix.h.

00117 { return *this; }      //unary plus

Matrix matvec::Matrix< BG >::operator+ const BG   x const [inherited]
 

Matrix matvec::Matrix< BG >::operator+ const Matrix< BG > &    a const [inherited]
 

Matrix& matvec::Matrix< BG >::operator+= const BG   x [inherited]
 

Matrix& matvec::Matrix< BG >::operator+= const Matrix< BG > &    a [inherited]
 

Matrix matvec::Matrix< BG >::operator- void    const [inherited]
 

Matrix matvec::Matrix< BG >::operator- const BG   x const [inherited]
 

Matrix matvec::Matrix< BG >::operator- const Matrix< BG > &    a const [inherited]
 

Matrix& matvec::Matrix< BG >::operator-= const BG   x [inherited]
 

Matrix& matvec::Matrix< BG >::operator-= const Matrix< BG > &    a [inherited]
 

Matrix matvec::Matrix< BG >::operator/ const BG   x const [inherited]
 

Matrix matvec::Matrix< BG >::operator/ const Matrix< BG > &    a const [inherited]
 

Matrix& matvec::Matrix< BG >::operator/= const BG   x [inherited]
 

Matrix& matvec::Matrix< BG >::operator/= const Matrix< BG > &    a [inherited]
 

Matrix<bool> matvec::Matrix< BG >::operator< const BG   x const [inherited]
 

Matrix<bool> matvec::Matrix< BG >::operator< const Matrix< BG > &    a const [inherited]
 

Matrix<bool> matvec::Matrix< BG >::operator<= const BG   x const [inherited]
 

Matrix<bool> matvec::Matrix< BG >::operator<= const Matrix< BG > &    a const [inherited]
 

BGMatrix & matvec::BGMatrix::operator= const Matrix< bool > &    a
 

Definition at line 44 of file bgmatrix.cpp.

References matvec::Matrix< T >::num_cols(), matvec::Matrix< T >::num_rows(), and matvec::Matrix< BG >::resize().

00045 {
00046    resize(a.num_rows(),a.num_cols());
00047    for (int j,i=0; i<a.num_rows(); ++i) for (j=0; j<a.num_cols(); ++j) Matrix<BG>::me[i][j] = (BG)a[i][j];
00048    return *this;
00049 }

BGMatrix& matvec::BGMatrix::operator= const Matrix< BG > &    a [inline]
 

Definition at line 43 of file bgmatrix.h.

References matvec::Matrix< BG >::copy().

00043 { copy(a); return *this; }

Matrix<bool> matvec::Matrix< BG >::operator== const BG   x const [inherited]
 

Matrix<bool> matvec::Matrix< BG >::operator== const Matrix< BG > &    a const [inherited]
 

Matrix<bool> matvec::Matrix< BG >::operator> const BG   x const [inherited]
 

Matrix<bool> matvec::Matrix< BG >::operator> const Matrix< BG > &    a const [inherited]
 

Matrix<bool> matvec::Matrix< BG >::operator>= const BG   x const [inherited]
 

Matrix<bool> matvec::Matrix< BG >::operator>= const Matrix< BG > &    a const [inherited]
 

const BG* matvec::Matrix< BG >::operator[] const size_type    i const [inline, inherited]
 

Definition at line 114 of file matrix.h.

00114 { return me[i]; }

BG* matvec::Matrix< BG >::operator[] const size_type    i [inline, inherited]
 

Definition at line 113 of file matrix.h.

00113 { return me[i]; }

virtual std::ostream& matvec::Matrix< BG >::print std::ostream &    os = std::cout const [virtual, inherited]
 

bool matvec::BGMatrix::psd void    const
 

Definition at line 52 of file bgmatrix.cpp.

References matvec::Matrix< BG >::begin(), matvec::Session::epsilon, matvec::Matrix< BG >::ncol, matvec::Matrix< BG >::nrow, matvec::psdefinite(), matvec::SESSION, and symmetric().

00053 {
00054    if (!this->symmetric()) return false;
00055    return psdefinite(begin(),Matrix<BG>::nrow,Matrix<BG>::ncol,SESSION.epsilon);
00056 }

BG matvec::BGMatrix::quadratic const Vector< BG > &    a,
const Vector< BG > &    b
const
 

Definition at line 267 of file bgmatrix.cpp.

References matvec::Matrix< BG >::me, matvec::Matrix< BG >::ncol, matvec::Matrix< BG >::nrow, and matvec::Vector< T >::size().

00268 {
00269    int nrow =  Matrix<BG>::nrow;
00270    int ncol =  Matrix<BG>::ncol;
00271    BG** me =  Matrix<BG>::me;
00272    int m = x.size();
00273    int n = y.size();
00274 
00275    BG s = 0.0;
00276    if (m != nrow  || n != ncol)  throw exception("BGMatrix::quadratic(): size not conformable");
00277    for (int j,i=0;i<m; i++) for (j=0; j<n; j++) s += x[i]*me[i][j]*y[j];
00278    return s;
00279 }

Matrix& matvec::Matrix< BG >::reserve const size_type    n,
const size_type    m
[inherited]
 

Matrix matvec::Matrix< BG >::reshape const size_type    m,
const size_type    n,
orientation    orient = COLUMN
const [inherited]
 

Matrix& matvec::Matrix< BG >::resize const Matrix< BG > &    a [inline, inherited]
 

Definition at line 86 of file matrix.h.

00086 {resize(a.ne); return *this;}

Matrix& matvec::Matrix< BG >::resize const size_type    n,
const size_type    m,
const BG   a
[inherited]
 

Matrix& matvec::Matrix< BG >::resize const size_type    n,
const size_type    m,
const BG   val = T()
[inherited]
 

Referenced by BGMatrix(), gs_solve(), identity(), and operator=().

bool matvec::Matrix< BG >::save const std::string &    fname,
const int    io_mode = std::ios::out
const [inherited]
 

int matvec::Matrix< BG >::size void    const [inline, inherited]
 

Definition at line 161 of file matrix.h.

00161 { return nrow*ncol; }

Matrix& matvec::Matrix< BG >::sortby orientation    orient,
const size_type    k
[inherited]
 

BGMatrix matvec::BGMatrix::splines const BGMatrix    knots,
const unsigned    type = 0
const
 

BGMatrix & matvec::BGMatrix::sqrtm void   
 

Definition at line 337 of file bgmatrix.cpp.

References matvec::Matrix< BG >::begin(), matvec::Session::epsilon, matvec::ginverse1(), matvec::Matrix< BG >::num_rows(), matvec::SESSION, and symmetric().

00338 {
00339    if (!this->symmetric()) throw exception("BGMatrix::sqrtm(): matrix must be symmetric");
00340    BG lgdet;
00341    ginverse1(begin(),num_rows(),lgdet,2,SESSION.epsilon);
00342    return *this;
00343 }

Matrix matvec::Matrix< BG >::submat const Matrix< bool > &    a const [inherited]
 

Matrix matvec::Matrix< BG >::submat const size_type    idx1,
const size_type    idx2,
const int    len1 = 0,
const int    len2 = 0
const [inherited]
 

Vector<BG> matvec::Matrix< BG >::sum orientation    orient = COLUMN const [inherited]
 

Referenced by norm().

Vector<BG> matvec::Matrix< BG >::sumsq orientation    orient = COLUMN const [inherited]
 

bool matvec::BGMatrix::symmetric void    const [inline]
 

Reimplemented from matvec::Matrix< BG >.

Definition at line 78 of file bgmatrix.h.

References matvec::Session::epsilon, matvec::Matrix< BG >::me, matvec::Matrix< BG >::nrow, and matvec::SESSION.

Referenced by ginv1(), logdet(), psd(), and sqrtm().

00078                                      {
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   } ;

BG matvec::Matrix< BG >::trace BG    init = T() const [inherited]
 

Matrix matvec::Matrix< BG >::transpose void    const [inherited]
 

Referenced by norm().

Vector< BG > matvec::BGMatrix::variance orientation    orien = COLUMN const
 

Definition at line 280 of file bgmatrix.cpp.

References matvec::Matrix< BG >::COLUMN, matvec::Matrix< BG >::me, matvec::Matrix< BG >::ncol, matvec::Matrix< BG >::nrow, matvec::Vector< T >::resize(), matvec::Matrix< BG >::ROW, and matvec::warning().

00281 {
00282    int nrow =  Matrix<BG>::nrow;
00283    int ncol =  Matrix<BG>::ncol;
00284    BG** me =  Matrix<BG>::me;
00285    int i,j;
00286    BG ss,s;
00287    Vector<BG> temp;
00288    if (orien == COLUMN) {
00289       assert(nrow > 1);
00290       temp.resize(ncol);
00291       for (j=0; j<ncol; j++) {
00292          for (ss=0.0,s=0.0,i=0; i<ncol; ++i) {
00293              ss += me[i][j]*me[i][j];
00294              s  += me[i][j];
00295          }
00296          temp[j] = (ss-s*s/nrow)/(nrow - 1);
00297       }
00298    } else if (orien == ROW) {
00299       assert(ncol > 1);
00300       temp.resize(nrow);
00301       for (i=0; i<nrow; i++) {
00302          for (ss=0.0,s=0.0,j=0; j<ncol; ++j) {
00303              ss += me[i][j]*me[i][j];
00304              s  += me[i][j];
00305          }
00306          temp[i] = (ss-s*s/ncol)/(ncol - 1);
00307       }
00308    } else {
00309       warning("unknown orientation");
00310    }
00311    return temp;
00312 }

Vector<BG> matvec::Matrix< BG >::vec orientation    orient = COLUMN const [inherited]
 

Referenced by lu_solve().


Friends And Related Function Documentation

friend class Model [friend]
 

Definition at line 34 of file bgmatrix.h.


Member Data Documentation

BG** matvec::Matrix< BG >::me [inherited]
 

Definition at line 170 of file matrix.h.

Referenced by covariance(), gs_solve(), identity(), inv(), logdet(), lu_solve(), quadratic(), symmetric(), and variance().

int matvec::Matrix< BG >::ncol [inherited]
 

Definition at line 171 of file matrix.h.

Referenced by covariance(), det(), gs_solve(), inv(), logdet(), lu_solve(), psd(), quadratic(), and variance().

int matvec::Matrix< BG >::nrow [inherited]
 

Definition at line 171 of file matrix.h.

Referenced by covariance(), det(), gs_solve(), inv(), logdet(), lu_solve(), psd(), quadratic(), symmetric(), and variance().


The documentation for this class was generated from the following files:
Generated on Thu Jun 16 17:14:18 2005 for Matvec by doxygen1.2.16