root/library/bdm/math/chmat.cpp @ 737

Revision 737, 1.8 kB (checked in by mido, 15 years ago)

ASTYLER RUN OVER THE WHOLE LIBRARY, JUPEE

  • Property svn:eol-style set to native
Line 
1
2#include "chmat.h"
3
4//using std::endl;
5
6namespace bdm {
7
8void chmat::opupdt ( const vec &v, double w ) {
9//TODO see cholupdt in lhotse
10        mat Z;
11        mat R;
12        mat V ( 1, v.length() );
13        V.set_row ( 0, v*sqrt ( w ) );
14        Z = concat_vertical ( Ch, V );
15        qr ( Z, R );
16        Ch = R ( 0, Ch.rows() - 1, 0, Ch.cols() - 1 );
17}
18
19mat chmat::to_mat() const {
20        mat F = Ch.T() * Ch;
21        return F;
22}
23
24void chmat::mult_sym ( const mat &C ) {
25        bdm_assert_debug ( C.rows() == dim, "Wrong dimension of U" );
26        if ( !qr ( Ch*C.T(), Ch ) ) {
27                bdm_warning ( "QR unstable in chmat mult_sym" );
28        }
29}
30
31void chmat::mult_sym ( const mat &C , chmat &U ) const {
32        bdm_assert_debug ( C.rows() == U.dim, "Wrong dimension of U" );
33        if ( !qr ( Ch*C.T(), U.Ch ) ) {
34                bdm_warning ( "QR unstable in chmat mult_sym" );
35        }
36}
37
38void chmat::mult_sym_t ( const mat &C ) {
39        bdm_assert_debug ( C.cols() == dim, "Wrong dimension of U" );
40        if ( !qr ( Ch*C, Ch ) ) {
41                bdm_warning ( "QR unstable in chmat mult_sym" );
42        }
43}
44
45void chmat::mult_sym_t ( const mat &C, chmat &U ) const {
46        bdm_assert_debug ( C.cols() == U.dim, "Wrong dimension of U" );
47        if ( !qr ( Ch*C, U.Ch ) ) {
48                bdm_warning ( "QR unstable in chmat mult_sym" );
49        }
50}
51
52double chmat::logdet() const {
53        double ldet = 0.0;
54        int i;
55        //sum of logs of (possibly negative!) diagonal entries
56        for ( i = 0; i < Ch.rows(); i++ ) {
57                ldet += log ( std::fabs ( Ch ( i, i ) ) );
58        }
59        return 2*ldet; //compensate for Ch being sqrt()
60}
61
62//TODO can be done more efficiently using BLAS, see triangular matrices
63vec chmat::sqrt_mult ( const vec &v ) const {
64        vec pom;
65        pom = Ch * v;
66        return pom;
67}
68
69double chmat::qform ( const vec &v ) const {
70        vec pom;
71        pom = Ch * v;
72        return pom*pom;
73}
74
75double chmat::invqform ( const vec &v ) const {
76        vec pom ( v.length() );
77        forward_substitution ( Ch.T(), v, pom );
78        return pom*pom;
79}
80
81void chmat::clear() {
82        Ch.clear();
83}
84
85}
Note: See TracBrowser for help on using the browser.