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

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

panove, vite, jak jsem peclivej na upravu kodu.. snad se vam bude libit:) konfigurace je v souboru /system/astylerc

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