[262] | 1 | |
---|
[39] | 2 | #include "chmat.h" |
---|
| 3 | |
---|
| 4 | //using std::endl; |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | void chmat::opupdt ( const vec &v, double w ) { |
---|
| 8 | //TODO see cholupdt in lhotse |
---|
| 9 | mat Z; |
---|
| 10 | mat R; |
---|
[76] | 11 | mat V(1,v.length()); |
---|
[434] | 12 | V.set_row(0,v*sqrt(w)); |
---|
[76] | 13 | Z = concat_vertical ( Ch,V ); |
---|
| 14 | qr ( Z,R ); |
---|
[39] | 15 | Ch = R ( 0, Ch.rows()-1, 0, Ch.cols()-1 ); |
---|
| 16 | }; |
---|
[168] | 17 | mat chmat::to_mat() const {mat F=Ch.T() *Ch;return F;}; |
---|
[39] | 18 | void chmat::mult_sym ( const mat &C ) { |
---|
[76] | 19 | it_error ( "not implemented" ); |
---|
[39] | 20 | }; |
---|
[76] | 21 | void chmat::mult_sym ( const mat &C , chmat &U ) const { |
---|
[279] | 22 | mat Z=C*Ch; |
---|
| 23 | U.Ch= chol(Z*Z.T()); |
---|
[39] | 24 | }; |
---|
| 25 | void chmat::mult_sym_t ( const mat &C ) { |
---|
[76] | 26 | it_error ( "not implemented" ); |
---|
[39] | 27 | }; |
---|
| 28 | void chmat::mult_sym_t ( const mat &C, chmat &U ) const { |
---|
[76] | 29 | it_error ( "not implemented" ); |
---|
[39] | 30 | }; |
---|
| 31 | double chmat::logdet() const { |
---|
| 32 | double ldet=0.0; int i; |
---|
| 33 | //sum of logs of (possibly negative!) diagonal entries |
---|
[76] | 34 | for ( i=0;i<Ch.rows();i++ ) {ldet+=log ( std::fabs ( Ch ( i,i ) ) );} |
---|
[39] | 35 | return 2*ldet; //compensate for Ch being sqrt() |
---|
| 36 | }; |
---|
| 37 | //TODO can be done more efficiently using BLAS, see triangular matrices |
---|
[108] | 38 | vec chmat::sqrt_mult ( const vec &v ) const {vec pom; pom = Ch*v; return pom;}; |
---|
| 39 | double chmat::qform ( const vec &v ) const {vec pom; pom = Ch*v; return pom*pom;}; |
---|
| 40 | double chmat::invqform ( const vec &v ) const { |
---|
[76] | 41 | vec pom(v.length()); |
---|
| 42 | forward_substitution(Ch.T(),v,pom); |
---|
| 43 | return pom*pom; |
---|
| 44 | }; |
---|
[108] | 45 | void chmat::clear() {Ch.clear();}; |
---|