Changeset 565 for library/bdm/stat
- Timestamp:
- 08/19/09 16:54:24 (15 years ago)
- Location:
- library/bdm/stat
- Files:
-
- 7 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/stat/discrete.h
r564 r565 55 55 void initialize() { 56 56 dim = ranges.length(); 57 it_assert_debug(gridsizes.length()==dim,"Incompatible dimensions of input");57 bdm_assert_debug(gridsizes.length() == dim, "Incompatible dimensions of input"); 58 58 Npoints = prod(gridsizes); 59 it_assert_debug(Npoints>0,"Wrong input parameters");59 bdm_assert_debug(Npoints > 0, "Wrong input parameters"); 60 60 61 61 //precompute steps … … 71 71 vec v ( dim ); 72 72 for ( int j = 0; j < dim; j++ ) { 73 it_assert_debug(inds(j)<gridsizes(j), "Index out of bounds");73 bdm_assert_debug(inds(j) < gridsizes(j), "Index out of bounds"); 74 74 v ( j ) = ranges(j)(0) + (0.5+inds(j))*steps(j); 75 75 } … … 80 80 long linear_index (const ivec inds){ 81 81 long ind=0; 82 it_assert_debug(inds.length()==dim,"Improper indeces inds");82 bdm_assert_debug(inds.length() == dim, "Improper indices inds"); 83 83 int dim_skips=1; // skips in active dimension, in the first dimension, the skips are 1 index per value 84 84 -
library/bdm/stat/emix.cpp
r507 r565 12 12 13 13 for ( i = 0; i < w.length(); i++ ) { 14 it_assert_debug ( dim == ( Coms0 ( i )->dimension() ), "Component sizes do not match!" );15 it_assert_debug ( !isnamed || tmp_rv.equal ( Coms0 ( i )->_rv() ), "Component RVs do not match!" );14 bdm_assert_debug ( dim == ( Coms0 ( i )->dimension() ), "Component sizes do not match!" ); 15 bdm_assert_debug ( !isnamed || tmp_rv.equal ( Coms0 ( i )->_rv() ), "Component RVs do not match!" ); 16 16 } 17 17 … … 44 44 45 45 void emix::marginal ( const RV &rv, emix &target ) const { 46 it_assert_debug ( isnamed(), "rvs are not assigned" );46 bdm_assert_debug ( isnamed(), "rvs are not assigned" ); 47 47 48 48 Array<shared_ptr<epdf> > Cn ( Coms.length() ); … … 55 55 56 56 shared_ptr<mpdf> emix::condition ( const RV &rv ) const { 57 it_assert_debug ( isnamed(), "rvs are not assigned" );57 bdm_assert_debug ( isnamed(), "rvs are not assigned" ); 58 58 mratio *tmp = new mratio ( this, rv ); 59 59 return shared_ptr<mpdf>(tmp); … … 65 65 int i; 66 66 for ( i = 0; i < w.length(); i++ ) { 67 it_assert_debug ( dim == ( Coms0 ( i )->dimension() ), "Component sizes do not match!" );67 bdm_assert_debug ( dim == ( Coms0 ( i )->dimension() ), "Component sizes do not match!" ); 68 68 } 69 69 if ( copy ) { 70 70 Coms.set_length ( Coms0.length() ); 71 71 for ( i = 0; i < w.length(); i++ ) { 72 it_error ( "Not imp..." );73 *Coms ( i ) = *Coms0 ( i );72 bdm_error ( "Not implemented" ); 73 // *Coms ( i ) = *Coms0 ( i ); 74 74 } 75 75 destroyComs = true; … … 124 124 125 125 void egiwmix::marginal ( const RV &rv, emix &target ) const { 126 it_assert_debug ( isnamed(), "rvs are not assigned" );126 bdm_assert_debug ( isnamed(), "rvs are not assigned" ); 127 127 128 128 Array<shared_ptr<epdf> > Cn ( Coms.length() ); … … 247 247 // rvaddok=rv.add ( mpdfs ( i )->_rv() ); //add rv to common rvs. 248 248 // // If rvaddok==false, mpdfs overlap => assert error. 249 // it_assert_debug(rvaddok||overlap,"mprod::mprod() input mpdfs overlap in rv!");250 249 // epdfs ( i ) = & ( mpdfs ( i )->posterior() ); // add pointer to epdf 251 250 // }; -
library/bdm/stat/emix.h
r559 r565 62 62 //prepare data structures 63 63 if ( copy ) { 64 it_error ( "todo" );65 destroynom = true;64 bdm_error ( "todo" ); 65 // destroynom = true; 66 66 } else { 67 67 nom = nom0; 68 68 destroynom = false; 69 69 } 70 it_assert_debug ( rvc.length() > 0, "Makes no sense to use this object!" );70 bdm_assert_debug ( rvc.length() > 0, "Makes no sense to use this object!" ); 71 71 72 72 // build denominator … … 156 156 } 157 157 double tmp = log ( sum ); 158 it_assert_debug ( std::isfinite ( tmp ), "Infinite" );158 bdm_assert_debug ( std::isfinite ( tmp ), "Infinite" ); 159 159 return tmp; 160 160 }; … … 387 387 for ( int i = 0; i < epdfs.length(); i++ ) { 388 388 independent = rv.add ( epdfs ( i )->_rv() ); 389 it_assert_debug ( independent == true, "eprod:: given components are not independent." );389 bdm_assert_debug ( independent, "eprod:: given components are not independent." ); 390 390 } 391 391 dim = rv._dsize(); … … 441 441 tmp += epdfs ( i )->evallog ( dls ( i )->pushdown ( val ) ); 442 442 } 443 it_assert_debug ( std::isfinite ( tmp ), "Infinite" );443 bdm_assert_debug ( std::isfinite ( tmp ), "Infinite" ); 444 444 return tmp; 445 445 } 446 446 //!access function 447 447 const epdf* operator () ( int i ) const { 448 it_assert_debug ( i < epdfs.length(), "wrong index" );448 bdm_assert_debug ( i < epdfs.length(), "wrong index" ); 449 449 return epdfs ( i ); 450 450 } -
library/bdm/stat/exp_family.cpp
r488 r565 19 19 20 20 vec egiw::sample() const { 21 it_warning ( "Function not implemented" );21 bdm_warning ( "Function not implemented" ); 22 22 return vec_1 ( 0.0 ); 23 23 } … … 67 67 - 0.5 * dimx * ( m * log2 + 0.5 * ( dimx - 1 ) * log2pi ) - lg; 68 68 69 it_assert_debug ( ( ( -nkG - nkW ) > -Inf ) && ( ( -nkG - nkW ) < Inf ), "ARX improper" );69 bdm_assert_debug ( ( ( -nkG - nkW ) > -Inf ) && ( ( -nkG - nkW ) < Inf ), "ARX improper" ); 70 70 return -nkG - nkW; 71 71 } … … 82 82 return iLsub * L0 ( 1, end ); 83 83 } else { 84 it_error ( "ERROR: est_theta() not implemented for dimx>1" );85 return 0;84 bdm_error ( "ERROR: est_theta() not implemented for dimx>1" ); 85 return vec(); 86 86 } 87 87 } … … 99 99 100 100 } else { 101 it_error ( "ERROR: est_theta_cov() not implemented for dimx>1" );102 return 0;101 bdm_error ( "ERROR: est_theta_cov() not implemented for dimx>1" ); 102 return ldmat(); 103 103 } 104 104 … … 138 138 return var; 139 139 } else { 140 it_error ( "not implemented" );141 return vec ( 0);140 bdm_error ( "not implemented" ); 141 return vec(); 142 142 } 143 143 } … … 199 199 } 200 200 double tmp = res - lognc();; 201 it_assert_debug ( std::isfinite ( tmp ), "Infinite value" );201 bdm_assert_debug ( std::isfinite ( tmp ), "Infinite value" ); 202 202 return tmp; 203 203 } … … 256 256 257 257 default: 258 it_error ( "PF::resample(): Unknown resampling method" );258 bdm_error ( "PF::resample(): Unknown resampling method" ); 259 259 } 260 260 … … 306 306 307 307 void eEmp::set_statistics ( const vec &w0, const epdf &epdf0 ) { 308 //it_assert_debug(rv==epdf0->rv(),"Wrong epdf0");309 308 dim = epdf0.dimension(); 310 309 w = w0; … … 319 318 320 319 void eEmp::set_samples ( const epdf* epdf0 ) { 321 //it_assert_debug(rv==epdf0->rv(),"Wrong epdf0");322 320 w = 1; 323 321 w /= sum ( w );//renormalize -
library/bdm/stat/exp_family.h
r536 r565 44 44 //! logarithm of the normalizing constant, \f$\mathcal{I}\f$ 45 45 virtual double lognc() const = 0; 46 46 47 //!Evaluate normalized log-probability 47 virtual double evallog_nn (const vec &val) const{it_error ("Not implemented");return 0.0;}; 48 virtual double evallog_nn (const vec &val) const { 49 bdm_error ("Not implemented"); 50 return 0.0; 51 } 52 48 53 //!Evaluate normalized log-probability 49 54 virtual double evallog (const vec &val) const { 50 55 double tmp; 51 56 tmp = evallog_nn (val) - lognc(); 52 // it_assert_debug ( std::isfinite ( tmp ),"Infinite value" );53 57 return tmp; 54 58 } … … 65 69 return x -lognc(); 66 70 } 71 67 72 //!Power of the density, used e.g. to flatten the density 68 virtual void pow (double p) {it_error ("Not implemented");}; 73 virtual void pow (double p) { 74 bdm_error ("Not implemented"); 75 } 69 76 }; 70 77 … … 84 91 BMEF (const BMEF &B) : BM (B), frg (B.frg), last_lognc (B.last_lognc) {} 85 92 //!get statistics from another model 86 virtual void set_statistics (const BMEF* BM0) {it_error ("Not implemented");}; 93 virtual void set_statistics (const BMEF* BM0) { 94 bdm_error ("Not implemented"); 95 } 96 87 97 //! Weighted update of sufficient statistics (Bayes rule) 88 98 virtual void bayes (const vec &data, const double w) {}; 89 99 //original Bayes 90 100 void bayes (const vec &dt); 101 91 102 //!Flatten the posterior according to the given BMEF (of the same type!) 92 virtual void flatten (const BMEF * B) {it_error ("Not implemented");} 93 //!Flatten the posterior as if to keep nu0 data 94 // virtual void flatten ( double nu0 ) {it_error ( "Not implemented" );} 95 96 BMEF* _copy_ () const {it_error ("function _copy_ not implemented for this BM"); return NULL;}; 103 virtual void flatten (const BMEF * B) { 104 bdm_error ("Not implemented"); 105 } 106 107 BMEF* _copy_ () const { 108 bdm_error ("function _copy_ not implemented for this BM"); 109 return NULL; 110 } 97 111 }; 98 112 … … 122 136 void from_setting (const Setting &root); 123 137 void validate() { 124 it_assert(mu.length() == R.rows(), "parameters mismatch");138 bdm_assert_debug (mu.length() == R.rows(), "parameters mismatch"); 125 139 dim = mu.length(); 126 140 } … … 272 286 //!@} 273 287 274 vec sample() const {it_error ("Not implemented");return vec_1 (0.0);}; 288 vec sample() const { 289 bdm_error ("Not implemented"); 290 return vec(); 291 } 292 275 293 vec mean() const {return beta / sum (beta);}; 276 294 vec variance() const {double gamma = sum (beta); return elem_mult (beta, (beta + 1)) / (gamma* (gamma + 1));} … … 278 296 double evallog_nn (const vec &val) const { 279 297 double tmp; tmp = (beta - 1) * log (val); 280 // it_assert_debug ( std::isfinite ( tmp ),"Infinite value" );281 298 return tmp; 282 }; 299 } 300 283 301 double lognc () const { 284 302 double tmp; … … 287 305 for (int i = 0;i < beta.length();i++) {lgb += lgamma (beta (i));} 288 306 tmp = lgb - lgamma (gam); 289 // it_assert_debug ( std::isfinite ( tmp ),"Infinite value" );290 307 return tmp; 291 }; 308 } 309 292 310 //!access function 293 311 vec& _beta() {return beta;} … … 397 415 } 398 416 void validate() { 399 it_assert(alpha.length() == beta.length(), "parameters do not match");417 bdm_assert_debug (alpha.length() == beta.length(), "parameters do not match"); 400 418 dim = alpha.length(); 401 419 } … … 446 464 void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;} 447 465 vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;}; 448 vec sample() {it_error ( "Not implemented" );return 0;}449 466 }; 450 467 */ … … 472 489 void set_parameters (const vec &low0, const vec &high0) { 473 490 distance = high0 - low0; 474 it_assert_debug (min (distance) > 0.0, "bad support");491 bdm_assert_debug (min (distance) > 0.0, "bad support"); 475 492 low = low0; 476 493 high = high0; … … 535 552 //! Set \c A and \c R 536 553 void set_parameters (const mat &A0, const vec &mu0, const sq_T &R0) { 537 it_assert_debug (A0.rows() == mu0.length(), "");538 it_assert_debug (A0.rows() == R0.rows(), "");554 bdm_assert_debug (A0.rows() == mu0.length(), "mlnorm: A vs. mu mismatch"); 555 bdm_assert_debug (A0.rows() == R0.rows(), "mlnorm: A vs. R mismatch"); 539 556 540 557 this->iepdf.set_parameters (zeros (A0.rows()), R0); … … 660 677 //! constructor function 661 678 void set_parameters (const mat &A0, const vec &mu0, const ldmat &R0, const ldmat& Lambda0) { 662 it_assert_debug (A0.rows() == mu0.length(), "");663 it_assert_debug (R0.rows() == A0.rows(), "");679 bdm_assert_debug (A0.rows() == mu0.length(), "mlstudent: A vs. mu mismatch"); 680 bdm_assert_debug (R0.rows() == A0.rows(), "mlstudent: A vs. R mismatch"); 664 681 665 682 iepdf.set_parameters (mu0, Lambda); // … … 1138 1155 //! Function performs resampling, i.e. removal of low-weight samples and duplication of high-weight samples such that the new samples represent the same density. 1139 1156 ivec resample (RESAMPLING_METHOD method = SYSTEMATIC); 1140 //! inherited operation : NOT implemneted 1141 vec sample() const {it_error ("Not implemented");return 0;} 1142 //! inherited operation : NOT implemneted 1143 double evallog (const vec &val) const {it_error ("Not implemented");return 0.0;} 1157 1158 //! inherited operation : NOT implemented 1159 vec sample() const { 1160 bdm_error ("Not implemented"); 1161 return vec(); 1162 } 1163 1164 //! inherited operation : NOT implemented 1165 double evallog (const vec &val) const { 1166 bdm_error ("Not implemented"); 1167 return 0.0; 1168 } 1169 1144 1170 vec mean() const { 1145 1171 vec pom = zeros (dim); … … 1279 1305 void enorm<sq_T>::marginal ( const RV &rvn, enorm<sq_T> &target ) const 1280 1306 { 1281 it_assert_debug (isnamed(), "rv description is not assigned");1307 bdm_assert_debug (isnamed(), "rv description is not assigned"); 1282 1308 ivec irvn = rvn.dataind (rv); 1283 1309 … … 1302 1328 typedef mlnorm<sq_T> TMlnorm; 1303 1329 1304 it_assert_debug (isnamed(), "rvs are not assigned");1330 bdm_assert_debug (isnamed(), "rvs are not assigned"); 1305 1331 TMlnorm &uptarget = dynamic_cast<TMlnorm &>(target); 1306 1332 1307 1333 RV rvc = rv.subt (rvn); 1308 it_assert_debug ( (rvc._dsize() + rvn._dsize() == rv._dsize()), "wrong rvn");1334 bdm_assert_debug ( (rvc._dsize() + rvn._dsize() == rv._dsize()), "wrong rvn"); 1309 1335 //Permutation vector of the new R 1310 1336 ivec irvn = rvn.dataind (rv); -
library/bdm/stat/merger.cpp
r561 r565 192 192 193 193 } 194 // it_assert_debug(std::isfinite(sum(lw_src)),"bad"); 194 195 195 lW.set_row ( i, lw_src ); // do not divide by mix 196 196 } -
library/bdm/stat/merger.h
r556 r565 200 200 eSmp._w() = wtmp / sum ( wtmp ); 201 201 } else { 202 it_error ( "Sources are not compatible - use merger_mix" );202 bdm_error ( "Sources are not compatible - use merger_mix" ); 203 203 } 204 204 }; … … 277 277 278 278 void validate() { 279 it_assert ( eSmp._w().length() > 0, "Empty support, use set_support()." );280 it_assert ( dim == eSmp._samples() ( 0 ).length(), "Support points and rv are not compatible!" );281 it_assert ( isnamed(), "mergers must be named" );279 bdm_assert ( eSmp._w().length() > 0, "Empty support, use set_support()." ); 280 bdm_assert ( dim == eSmp._samples() ( 0 ).length(), "Support points and rv are not compatible!" ); 281 bdm_assert ( isnamed(), "mergers must be named" ); 282 282 } 283 283 //!@}