Changeset 766
- Timestamp:
- 01/11/10 22:55:57 (15 years ago)
- Location:
- library
- Files:
-
- 30 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.cpp
r746 r766 27 27 }; 28 28 29 int RV:: init( const string &name, int size ) {29 int RV::assign_id( const string &name, int size ) { 30 30 //Refer 31 31 int id; … … 86 86 int id; 87 87 for ( int i = 0; i < len; i++ ) { 88 id = init( in_names ( i ), in_sizes ( i ) );88 id = assign_id ( in_names ( i ), in_sizes ( i ) ); 89 89 ids ( i ) = id; 90 90 } … … 100 100 101 101 bool RV::add ( const RV &rv2 ) { 102 // TODO103 102 if ( rv2.len > 0 ) { //rv2 is nonempty 104 103 ivec ind = rv2.findself ( *this ); //should be -1 all the time … … 146 145 } 147 146 148 shared_ptr<pdf> epdf::condition ( const RV &rv ) const { 149 bdm_warning ( "Not implemented" ); 150 return shared_ptr<pdf>(); 151 } 152 153 shared_ptr<epdf> epdf::marginal ( const RV &rv ) const { 154 bdm_warning ( "Not implemented" ); 155 return shared_ptr<epdf>(); 156 } 147 shared_ptr<pdf> epdf::condition ( const RV &rv ) const NOT_IMPLEMENTED( shared_ptr<pdf>() ); 148 149 150 shared_ptr<epdf> epdf::marginal ( const RV &rv ) const NOT_IMPLEMENTED( shared_ptr<epdf>() ); 157 151 158 152 mat epdf::sample_mat ( int N ) const { -
library/bdm/base/bdmbase.h
r760 r766 108 108 109 109 //! auxiliary function used in constructor 110 void init ( const Array<std::string> &in_names, const ivec &in_sizes, const ivec &in_times ); 111 int init ( const string &name, int size ); 110 void init( const Array<std::string> &in_names, const ivec &in_sizes, const ivec &in_times ); 111 112 //! auxiliary function assigning unique integer index related to the passed name and size of the random variable 113 int assign_id( const string &name, int size ); 114 112 115 //! Private constructor from IDs, potentially dangerous since all ids must be valid! 113 116 //! dummy is there to prevent confusion with RV(" string"); … … 319 322 320 323 //! log this vector 321 virtual void log_vector ( int id, const vec &v ) { 322 bdm_error ( "Not implemented" ); 323 }; 324 virtual void log_vector ( int id, const vec &v ) = 0; 324 325 325 326 virtual Setting & log_to_setting ( int id ) { 326 327 return settings ( id )->add ( Setting::TypeGroup ); 327 328 } 328 329 329 //! log this double 330 virtual void logit ( int id, const double &d ) { 331 bdm_error ( "Not implemented" ); 332 }; 330 virtual void logit ( int id, const double &d ) = 0; 333 331 334 332 //! Shifts storage position for another time step. 335 virtual void step() { 336 bdm_error ( "Not implemneted" ); 337 }; 333 virtual void step() = 0; 338 334 339 335 //! Finalize storing information … … 385 381 //!dimension of the condition 386 382 int dimc; 383 387 384 //! random variable in condition 388 385 RV rvc; … … 402 399 pdf ( const pdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), dim ( m.dim ), rv ( m.rv ) { } 403 400 404 //! copy of the current object - make sure to implement405 virtual pdf* _copy_() const {406 return new pdf ( *this );407 }408 401 //!@} 409 402 … … 412 405 413 406 //! Returns a sample from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv 414 virtual vec samplecond ( const vec &cond ) { 415 bdm_error ( "Not implemented" ); 416 return vec(); 417 } 407 virtual vec samplecond ( const vec &cond ) = 0; 418 408 419 409 //! Returns \param N samples from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv … … 421 411 422 412 //! Shortcut for conditioning and evaluation of the internal epdf. In some cases, this operation can be implemented efficiently. 423 virtual double evallogcond ( const vec &yt, const vec &cond ) { 424 bdm_error ( "Not implemented" ); 425 return 0.0; 426 } 413 virtual double evallogcond ( const vec &yt, const vec &cond ) = 0; 427 414 428 415 //! Matrix version of evallogcond … … 521 508 } 522 509 523 epdf* _copy_() const {524 return new epdf ( *this );525 }526 510 //!@} 527 511 … … 530 514 531 515 //! Returns a sample, \f$ x \f$ from density \f$ f_x()\f$ 532 virtual vec sample() const { 533 bdm_error ( "not implemented" ); 534 return vec(); 535 } 516 virtual vec sample() const = 0; 536 517 537 518 //! Returns N samples, \f$ [x_1 , x_2 , \ldots \ \f$ from density \f$ f_x(rv)\f$ … … 540 521 //! Compute log-probability of argument \c val 541 522 //! In case the argument is out of suport return -Infinity 542 virtual double evallog ( const vec &val ) const { 543 bdm_error ( "not implemented" ); 544 return 0.0; 545 } 546 523 virtual double evallog ( const vec &val ) const = 0; 524 547 525 //! Compute log-probability of multiple values argument \c val 548 526 virtual vec evallog_mat ( const mat &Val ) const; … … 557 535 virtual shared_ptr<epdf> marginal ( const RV &rv ) const; 558 536 559 //! return expected value 560 virtual vec mean() const { 561 bdm_error ( "not implemneted" ); 562 return vec(); 563 } 537 virtual vec mean() const = 0; 564 538 565 539 //! return expected variance (not covariance!) 566 virtual vec variance() const { 567 bdm_error ( "not implemneted" ); 568 return vec(); 569 } 540 virtual vec variance() const = 0; 570 541 571 542 //! Lower and upper bounds of \c percentage % quantile, returns mean-2*sigma as default … … 639 610 //! Update \c iepdf so that it represents this pdf conditioned on \c rvc = cond 640 611 //! This function provides convenient reimplementation in offsprings 641 virtual void condition ( const vec &cond ) { 642 bdm_error ( "Not implemented" ); 643 } 612 virtual void condition ( const vec &cond ) = 0; 644 613 645 614 //!access function to iepdf … … 942 911 } 943 912 //! Returns full vector of observed data=[output, input] 944 virtual void getdata ( vec &dt ) const { 945 bdm_error ( "abstract class" ); 946 } 913 virtual void getdata ( vec &dt ) const = 0; 914 947 915 //! Returns data records at indeces. 948 virtual void getdata ( vec &dt, const ivec &indeces ) { 949 bdm_error ( "abstract class" ); 950 } 951 952 //! Accepts action variable and schedule it for application. 953 virtual void write ( const vec &ut ) { 954 bdm_error ( "abstract class" ); 955 } 916 virtual void getdata ( vec &dt, const ivec &indeces ) = 0; 917 918 //! Accepts action variable and schedule it for application. 919 virtual void write ( const vec &ut ) = 0; 956 920 957 921 //! Accepts action variables at specific indeces 958 virtual void write ( const vec &ut, const ivec &indeces ) { 959 bdm_error ( "abstract class" ); 960 } 922 virtual void write ( const vec &ut, const ivec &indeces ) = 0; 961 923 962 924 //! Moves from \f$ t \f$ to \f$ t+1 \f$, i.e. perfroms the actions and reads response of the system. 963 virtual void step() { 964 bdm_error ( "abstract class" ); 965 } 925 virtual void step() = 0; 966 926 967 927 //! Register DS for logging into logger L … … 1033 993 // BM ( const BM &B ) : yrv ( B.yrv ), dimy(B.dimy), rvc ( B.rvc ),dimc(B.dimc), ll ( B.ll ), evalll ( B.evalll ) {} 1034 994 //! \brief Copy function required in vectors, Arrays of BM etc. Have to be DELETED manually! 1035 //! Prototype: \code BM* _copy_() const {return new BM(*this);} \endcode 1036 virtual BM* _copy_() const { 1037 return NULL; 1038 }; 995 //! Prototype: \code BM* _copy() const {return new BM(*this);} \endcode 996 virtual BM* _copy() const { return NULL; }; // TODO NEBUDE TU TAKY LEPSI BDM_ERROR??! 1039 997 //!@} 1040 998 … … 1054 1012 //! This function evaluates only \f$ y_t \f$, condition is assumed to be the last used in bayes(). 1055 1013 //! See bdm::BM::predictor for conditional version. 1056 virtual double logpred ( const vec &yt ) const { 1057 bdm_error ( "Not implemented" ); 1058 return 0.0; 1059 } 1014 virtual double logpred ( const vec &yt ) const = 0; 1060 1015 1061 1016 //! Matrix version of logpred … … 1069 1024 1070 1025 //!Constructs a predictive density \f$ f(d_{t+1} |d_{t}, \ldots d_{0}) \f$ 1071 virtual epdf* epredictor() const { 1072 bdm_error ( "Not implemented" ); 1073 return NULL; 1074 }; 1026 virtual epdf* epredictor() const = 0; 1027 1075 1028 //!Constructs conditional density of 1-step ahead predictor \f$ f(d_{t+1} |d_{t+h-1}, \ldots d_{t}) \f$ 1076 virtual pdf* predictor() const { 1077 bdm_error ( "Not implemented" ); 1078 return NULL; 1079 }; 1029 virtual pdf* predictor() const = 0; 1030 1080 1031 //!@} 1081 1032 -
library/bdm/base/datasources.h
r738 r766 129 129 } 130 130 131 //! Accepts action variable and schedule it for application. 132 virtual void write ( const vec &ut ) NOT_IMPLEMENTED_VOID; 133 134 //! Accepts action variables at specific indeces 135 virtual void write ( const vec &ut, const ivec &indeces ) NOT_IMPLEMENTED_VOID; 136 131 137 /*! 132 138 \code … … 182 188 } 183 189 190 191 //! Returns data records at indeces. 192 virtual void getdata ( vec &dt, const ivec &indeces ) NOT_IMPLEMENTED_VOID; 193 194 184 195 /*! 185 196 \code … … 353 364 } 354 365 366 virtual void write ( const vec &ut, const ivec &indeces ) NOT_IMPLEMENTED_VOID; 367 355 368 /*! UI for stateDS 356 369 -
library/bdm/base/loggers.cpp
r737 r766 48 48 49 49 void memlog::from_setting ( const Setting &set ) { 50 // TODO tady se natvrdo ocekava existence stringu, nejsou zadne defaulty.. je to tak OK?51 50 UI::get ( maxlen, set, "maxlen", UI::compulsory ); 52 51 UI::get ( filename, set, "filename" ); … … 174 173 175 174 void dirfilelog::from_setting ( const Setting &set ) { 176 // TODO tady se natvrdo ocekava existence stringu, nejsou zadne defaulty.. je to tak OK?177 175 dirname = ( const char* ) set["dirname"]; 178 176 maxlen = set["maxlen"]; -
library/bdm/base/loggers.h
r737 r766 78 78 /*! \brief UI for memlog 79 79 80 TODO dat tam kam patri, a to celej blok81 82 80 \code 83 81 logger = { … … 130 128 /*! \brief UI for stdlog 131 129 132 TODO dat tam kam patri, a to celej blok133 134 130 \code 135 131 logger = { … … 140 136 void from_setting ( const Setting &set ) { 141 137 } 142 143 138 }; 144 139 UIREGISTER ( stdlog ); -
library/bdm/bdmerror.h
r737 r766 64 64 } else ((void) 0) 65 65 66 #define NOT_IMPLEMENTED(RESULT) { bdm_error( "Not implemented" ); return RESULT; } 67 68 #define NOT_IMPLEMENTED_VOID { bdm_error( "Not implemented" ); } 69 66 70 #endif 67 -
library/bdm/bdmroot.h
r756 r766 19 19 #include "itpp_ext.h" 20 20 #include "base/libconfig/lib/libconfig.h++" 21 #include "bdmerror.h" 21 22 22 23 using namespace libconfig; … … 94 95 virtual void validate() { 95 96 } 97 98 //! Virtual method providing deep copy of instances 99 virtual root* _copy() const NOT_IMPLEMENTED(NULL); 100 101 96 102 //! access function 97 103 int _log_level() const { -
library/bdm/estim/arx.cpp
r741 r766 78 78 } 79 79 80 ARX* ARX::_copy _( ) const {80 ARX* ARX::_copy ( ) const { 81 81 ARX* Tmp = new ARX ( *this ); 82 82 return Tmp; -
library/bdm/estim/arx.h
r746 r766 56 56 ARX ( const double frg0 = 1.0 ) : BMEF ( frg0 ), have_constant ( true ), dyad(), est(), alter_est() {}; 57 57 ARX ( const ARX &A0 ) : BMEF ( A0 ), have_constant ( A0.have_constant ), dyad ( A0.dyad ), est ( A0.est ), alter_est ( A0.alter_est ) { }; 58 ARX* _copy_() const; 58 59 ARX* _copy() const; 60 59 61 void set_parameters ( double frg0 ) { 60 62 frg = frg0; … … 174 176 //! copy constructor 175 177 ARXfrg ( const ARXfrg &A0 ) : ARX ( A0 ) {}; 176 ARXfrg* _copy_() const {178 virtual ARXfrg* _copy() const { 177 179 ARXfrg *A = new ARXfrg ( *this ); 178 180 return A; -
library/bdm/estim/ekf_template.h
r744 r766 30 30 class EKFCh_dQ : public EKFCh { 31 31 public: 32 BM* _copy_() const {return new EKFCh_dQ(*this);} 32 root* _copy_() const { 33 return new EKFCh_dQ(*this); 34 } 35 33 36 //! new bayes, expects cond = [ut, Qt] 34 37 void bayes( const vec &yt , const vec &cond) { -
library/bdm/estim/kalman.h
r744 r766 154 154 bdm_assert ( est.dimension(), "Statistics and model parameters mismatch" ); 155 155 } 156 157 virtual double logpred ( const vec &yt ) const NOT_IMPLEMENTED(0); 158 159 virtual epdf* epredictor() const NOT_IMPLEMENTED(NULL); 160 161 virtual pdf* predictor() const NOT_IMPLEMENTED(NULL); 156 162 }; 157 163 /*! … … 165 171 //! Here dt = [yt;ut] of appropriate dimensions 166 172 void bayes ( const vec &yt, const vec &cond = empty_vec ); 167 BM* _copy_() const { 173 174 virtual KalmanFull* _copy() const { 168 175 KalmanFull* K = new KalmanFull; 169 176 K->set_parameters ( A, B, C, D, Q, R ); … … 192 199 public: 193 200 //! copy constructor 194 BM* _copy_() const {201 virtual KalmanCh* _copy() const { 195 202 KalmanCh* K = new KalmanCh; 196 203 K->set_parameters ( A, B, C, D, Q, R ); … … 335 342 public: 336 343 //! copy constructor duplicated - calls different set_parameters 337 BM* _copy_() const {344 EKFCh* _copy() const { 338 345 return new EKFCh(*this); 339 346 } … … 422 429 // TODO dodelat void to_setting( Setting &set ) const; 423 430 431 virtual double logpred ( const vec &yt ) const NOT_IMPLEMENTED(0); 432 433 virtual epdf* epredictor() const NOT_IMPLEMENTED(NULL); 434 435 virtual pdf* predictor() const NOT_IMPLEMENTED(NULL); 424 436 }; 425 437 -
library/bdm/estim/mixtures.cpp
r750 r766 15 15 int ndat = Data.cols(); 16 16 //Estimate Com0 from all data 17 Coms ( 0 ) = Com0->_copy_();17 Coms ( 0 ) = (BMEF*) Com0->_copy(); 18 18 // Coms(0)->set_evalll(false); 19 19 Coms ( 0 )->bayes_batch ( Data ); … … 24 24 for ( i = 1; i < n; i++ ) { 25 25 //copy Com0 and create new rvs for them 26 Coms ( i ) = Coms ( 0 )->_copy_( );26 Coms ( i ) = (BMEF*) Coms ( 0 )->_copy ( ); 27 27 } 28 28 //Pick some data for each component and update it 29 29 for ( i = 0; i < n; i++ ) { 30 30 //pick one datum 31 int ind = floor ( ndat * UniRNG.sample() );31 int ind = (int) floor ( ndat * UniRNG.sample() ); 32 32 Coms ( i )->bayes ( Data.get_col ( ind ), empty_vec ); 33 33 //flatten back to oringinal … … 49 49 Array<BMEF*> Coms0 ( n ); 50 50 for ( i = 0; i < n; i++ ) { 51 Coms0 ( i ) = ( BMEF* ) Coms ( i )->_copy _();51 Coms0 ( i ) = ( BMEF* ) Coms ( i )->_copy(); 52 52 } 53 53 … … 147 147 emix* tmp; 148 148 tmp = new emix( ); 149 tmp->set_parameters ( weights.posterior().mean(), pC ); 149 tmp->_w() = weights.posterior().mean(); 150 tmp->_Coms() = pC; 150 151 tmp->validate(); 151 152 return tmp; -
library/bdm/estim/mixtures.h
r746 r766 75 75 weights (), method ( QB ) { 76 76 for ( int i = 0; i < n; i++ ) { 77 Coms ( i ) = ( BMEF* ) Coms0 ( i )->_copy _();77 Coms ( i ) = ( BMEF* ) Coms0 ( i )->_copy(); 78 78 } 79 79 weights.set_parameters(alpha0); … … 92 92 weights ( M2.weights ), method ( M2.method ) { 93 93 for ( int i = 0; i < n; i++ ) { 94 Coms ( i ) = M2.Coms ( i )->_copy_();94 Coms ( i ) = (BMEF*) M2.Coms ( i )->_copy(); 95 95 } 96 96 build_est(); … … 144 144 } 145 145 #endif // MIXTURES_H 146 147 -
library/bdm/estim/particles.cpp
r739 r766 168 168 if ( ind ( i ) != i ) {//replace the current Bm by a new one 169 169 delete BMs ( i ); 170 BMs ( i ) = BMs ( ind ( i ) )->_copy_(); //copy constructor170 BMs ( i ) = (BM*) BMs ( ind ( i ) )->_copy(); //copy constructor 171 171 } 172 172 }; -
library/bdm/estim/particles.h
r744 r766 203 203 return _samples; 204 204 } 205 206 virtual double logpred ( const vec &yt ) const NOT_IMPLEMENTED(0); 207 208 virtual epdf* epredictor() const NOT_IMPLEMENTED(NULL); 209 210 virtual pdf* predictor() const NOT_IMPLEMENTED(NULL); 205 211 }; 206 212 UIREGISTER ( PF ); … … 242 248 void qbounds ( vec &lb, vec &ub, double perc = 0.95 ) const; 243 249 244 vec sample() const { 245 bdm_error ( "Not implemented" ); 246 return vec(); 247 } 248 249 double evallog ( const vec &val ) const { 250 bdm_error ( "not implemented" ); 251 return 0.0; 252 } 250 vec sample() const NOT_IMPLEMENTED(0); 251 252 double evallog ( const vec &val ) const NOT_IMPLEMENTED(0); 253 253 }; 254 254 … … 282 282 //BMcond0 .condition ( pf->posterior()._sample ( 0 ) ); 283 283 for ( int i = 0; i < n; i++ ) { 284 BMs ( i ) = BMcond0._copy_();284 BMs ( i ) = (BM*) BMcond0._copy(); 285 285 } 286 286 }; 287 287 288 288 void bayes ( const vec &yt, const vec &cond ); 289 289 290 const epdf& posterior() const { 290 291 return jest; … … 301 302 } 302 303 PF& _pf() {return *pf;} 304 305 306 virtual double logpred ( const vec &yt ) const NOT_IMPLEMENTED(0); 307 308 virtual epdf* epredictor() const NOT_IMPLEMENTED(NULL); 309 310 virtual pdf* predictor() const NOT_IMPLEMENTED(NULL); 311 303 312 304 313 /*! configuration structure for basic PF … … 315 324 void from_setting ( const Setting &set ) { 316 325 shared_ptr<pdf> par = UI::build<pdf> ( set, "parameter_pdf", UI::compulsory ); 317 shared_ptr<pdf> obs = new pdf(); // not used!!318 326 319 327 pf = new PF; … … 321 329 pf->prior_from_set ( set ); 322 330 pf->resmethod_from_set ( set ); 323 pf->set_model ( par, obs );331 pf->set_model ( par, par ); // too hackish! 324 332 325 333 shared_ptr<BM> BM0 = UI::build<BM> ( set, "BM", UI::compulsory ); … … 340 348 validate(); 341 349 } 350 342 351 void validate() { 343 352 try { 344 353 pf->validate(); 345 } catch ( std::exception &e) {354 } catch ( std::exception ) { 346 355 throw UIException ( "Error in PF part of MPF:" ); 347 356 } … … 351 360 pf2bm.set_connection ( BMs ( 0 )->_rvc(), pf->posterior()._rv() ); 352 361 } 353 354 362 }; 355 363 UIREGISTER ( MPF ); -
library/bdm/itpp_ext.cpp
r737 r766 359 359 } 360 360 if ( xa == ( int ) xa ) { 361 n = xa;361 n = (int) xa; 362 362 for ( k = 1; k < n; k++ ) { 363 363 s += 1.0 / k; … … 365 365 ps = s - el; 366 366 } else if ( ( xa + 0.5 ) == ( ( int ) ( xa + 0.5 ) ) ) { 367 n = xa - 0.5;367 n = (int) (xa - 0.5); 368 368 for ( k = 1; k <= n; k++ ) { 369 369 s += 1.0 / ( 2.0 * k - 1.0 ); … … 410 410 //! generate randun() sample 411 411 double get() { 412 long long tmp = A * seed;412 long tmp = (long) (A * seed); 413 413 tmp = tmp % M; 414 414 seed = tmp; -
library/bdm/math/chmat.h
r738 r766 77 77 it shouldn't actually be called. 78 78 */ 79 chmat ( const chmat &M, const ivec &perm ) { 80 bdm_error ( "not implemented" ); 81 } 79 chmat ( const chmat &M, const ivec &perm ) NOT_IMPLEMENTED_VOID; 82 80 83 81 //! Access function -
library/bdm/math/square_mat.h
r737 r766 42 42 BLAS-2b operation. 43 43 */ 44 virtual void opupdt ( const vec &v, double w ) { 45 bdm_error ( "not implemented" ); 46 }; 44 virtual void opupdt ( const vec &v, double w ) = 0; 47 45 48 46 /*! \brief Conversion to full matrix. 49 47 */ 50 51 virtual mat to_mat() const { 52 bdm_error ( "not implemented" ); 53 return mat ( 0, 0 ); 54 } 48 virtual mat to_mat() const = 0; 55 49 56 50 /*! \brief Inplace symmetric multiplication by a SQUARE matrix \f$C\f$, i.e. \f$V = C*V*C'\f$ 57 51 @param C multiplying matrix, 58 52 */ 59 virtual void mult_sym ( const mat &C ) { 60 bdm_error ( "not implemented" ); 61 }; 53 virtual void mult_sym ( const mat &C ) = 0; 62 54 63 55 /*! \brief Inplace symmetric multiplication by a SQUARE transpose of matrix \f$C\f$, i.e. \f$V = C'*V*C\f$ 64 56 @param C multiplying matrix, 65 57 */ 66 virtual void mult_sym_t ( const mat &C ) { 67 bdm_error ( "not implemented" ); 68 } 69 58 virtual void mult_sym_t ( const mat &C ) = 0; 70 59 71 60 /*! … … 73 62 74 63 */ 75 virtual double logdet() const { 76 bdm_error ( "not implemented" ); 77 return 0; 78 }; 64 virtual double logdet() const = 0; 79 65 80 66 /*! … … 83 69 Used e.g. in generating normal samples. 84 70 */ 85 virtual vec sqrt_mult ( const vec &v ) const { 86 bdm_error ( "not implemented" ); 87 return vec ( 0 ); 88 }; 71 virtual vec sqrt_mult ( const vec &v ) const = 0; 89 72 90 73 /*! … … 92 75 93 76 */ 94 virtual double qform ( const vec &v ) const { 95 bdm_error ( "not implemented" ); 96 return 0; 97 }; 77 virtual double qform ( const vec &v ) const = 0; 98 78 99 79 /*! … … 101 81 102 82 */ 103 virtual double invqform ( const vec &v ) const { 104 bdm_error ( "not implemented" ); 105 return 0; 106 }; 83 virtual double invqform ( const vec &v ) const = 0; 107 84 108 85 // //! easy version of the … … 110 87 111 88 //! Clearing matrix so that it corresponds to zeros. 112 virtual void clear() { 113 bdm_error ( "not implemented" ); 114 }; 89 virtual void clear() = 0; 115 90 116 91 //! Reimplementing common functions of mat: cols(). -
library/bdm/mex/mex_BM.h
r756 r766 38 38 return mxArray2vec ( tmp ); 39 39 } 40 41 virtual vec sample() const NOT_IMPLEMENTED(0); 42 43 virtual double evallog ( const vec &val ) const NOT_IMPLEMENTED(0); 44 45 virtual vec variance() const NOT_IMPLEMENTED(0); 40 46 }; 41 47 UIREGISTER ( mexEpdf ); … … 92 98 return est; 93 99 } //tohle by melo zustat!! 100 101 virtual double logpred ( const vec &yt ) const NOT_IMPLEMENTED(0); 102 103 virtual epdf* epredictor() const NOT_IMPLEMENTED(NULL); 104 105 virtual pdf* predictor() const NOT_IMPLEMENTED(NULL); 94 106 }; 95 107 UIREGISTER ( mexBM ); -
library/bdm/mex/mex_datasource.h
r737 r766 117 117 } 118 118 119 virtual void getdata ( vec &dt, const ivec &indeces ) NOT_IMPLEMENTED_VOID; 120 121 virtual void write ( const vec &ut, const ivec &indeces ) NOT_IMPLEMENTED_VOID; 122 123 119 124 void step() { 120 125 mxArray* tmp; -
library/bdm/stat/discrete.cpp
r760 r766 81 81 inds ( j ) = gridsizes ( j ) - 1; 82 82 else { 83 inds ( j ) = ::round ( val ( j ) - ranges ( j ) ( 0 ) / steps ( j ) );83 inds ( j ) = (int) ::round ( val ( j ) - ranges ( j ) ( 0 ) / steps ( j ) ); 84 84 } 85 85 } -
library/bdm/stat/emix.cpp
r760 r766 3 3 namespace bdm { 4 4 5 void emix::set_parameters ( const vec &w0, const Array<shared_ptr<epdf> > &Coms0 ) {6 w = w0 / sum ( w0 );7 8 bool isnamed = Coms0 ( 0 )->isnamed();9 RV tmp_rv;10 if ( isnamed ) tmp_rv = Coms0 ( 0 )->_rv();11 Coms = Coms0;12 13 if ( isnamed ) epdf::set_rv ( tmp_rv ); //coms aer already OK, no need for set_rv14 }15 16 5 void emix::validate (){ 17 dim = Coms ( 0 )->dimension(); 18 bool isnamed = Coms ( 0 )->isnamed(); 19 int i; 20 RV tmp_rv; 21 if ( isnamed ) tmp_rv = Coms ( 0 )->_rv(); 22 for ( i = 0; i < w.length(); i++ ) { 6 bdm_assert ( Coms.length() > 0, "There has to be at least one component." ); 7 8 bdm_assert ( Coms.length() == w.length(), "It is obligatory to define weights of all the components." ); 9 10 double sum_w = sum ( w ); 11 bdm_assert ( sum_w != 0, "There has to be a component with non-zero weight." ); 12 w = w / sum_w; 13 14 int dim = Coms ( 0 )->dimension(); 15 for ( int i = 1; i < Coms.length(); i++ ) { 23 16 bdm_assert ( dim == ( Coms ( i )->dimension() ), "Component sizes do not match!" ); 24 bdm_assert ( !isnamed || tmp_rv.equal ( Coms ( i )->_rv() ), "Component RVs do not match!" ); 25 } 26 27 } 28 29 17 bdm_assert ( Coms(i)->isnamed() , "An unnamed component is forbidden here!" ); 18 } 19 20 set_rv ( Coms ( 0 )->_rv() ); 21 } 22 23 void emix::from_setting ( const Setting &set ) { 24 UI::get ( Coms, set, "pdfs", UI::compulsory ); 25 26 if ( !UI::get ( w, set, "weights", UI::optional ) ) { 27 int len = Coms.length(); 28 w.set_length ( len ); 29 w = 1.0 / len; 30 } 31 32 validate(); 33 } 30 34 31 35 … … 109 113 } 110 114 111 target.set_parameters ( w, Cn ); 115 target._w() = w; 116 target._Coms() = Cn; 112 117 target.validate(); 113 118 } … … 190 195 } 191 196 192 target.set_parameters ( w, Cn ); 197 target._w() = w; 198 target._Coms() = Cn; 193 199 target.validate(); 194 200 } … … 313 319 dls ( i ) = new datalink_m2m; 314 320 dls ( i )->set_connection ( pdfs ( i )->_rv(), pdfs ( i )->_rvc(), _rv(), _rvc() ); 321 } 322 } 323 324 void mmix::validate() 325 { 326 bdm_assert ( Coms.length() > 0, "There has to be at least one component." ); 327 328 bdm_assert ( Coms.length() == w.length(), "It is obligatory to define weights of all the components." ); 329 330 double sum_w = sum ( w ); 331 bdm_assert ( sum_w != 0, "There has to be a component with non-zero weight." ); 332 w = w / sum_w; 333 334 int dim = Coms ( 0 )->dimension(); 335 int dimc = Coms ( 0 )->dimensionc(); 336 for ( int i = 1; i < Coms.length(); i++ ) { 337 bdm_assert ( dim == ( Coms ( i )->dimension() ), "Component sizes do not match!" ); 338 bdm_assert ( dimc == ( Coms ( i )->dimensionc() ), "Component sizes do not match!" ); 339 bdm_assert ( Coms(i)->isnamed() , "An unnamed component is forbidden here!" ); 340 } 341 342 set_rv ( Coms ( 0 )->_rv() ); 343 set_rvc ( Coms ( 0 )->_rvc() ); 344 } 345 346 void mmix::from_setting ( const Setting &set ) { 347 UI::get ( Coms, set, "pdfs", UI::compulsory ); 348 349 if ( !UI::get ( w, set, "weights", UI::optional ) ) { 350 int len = Coms.length(); 351 w.set_length ( len ); 352 w = 1.0 / len; 315 353 } 316 354 } -
library/bdm/stat/emix.h
r750 r766 53 53 // adjust rv and rvc 54 54 55 set_rv ( rv ); // TODO co kdyby tohle samo uz nastavovalo dimension?!?!55 set_rv ( rv ); 56 56 dim = rv._dsize(); 57 57 … … 81 81 return tmp; 82 82 } 83 84 //! Returns a sample from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv 85 virtual vec samplecond ( const vec &cond ) NOT_IMPLEMENTED(0); 86 83 87 //! Object takes ownership of nom and will destroy it 84 88 void ownnom() { … … 91 95 } 92 96 } 97 98 99 93 100 94 101 private: … … 120 127 emix ( ) : epdf ( ) { } 121 128 122 /*!123 \brief Set weights \c w and components \c Coms124 125 Shared pointers in Coms are kept inside this instance and126 shouldn't be modified after being passed to this method.127 */128 void set_parameters ( const vec &w, const Array<shared_ptr<epdf> > &Coms );129 130 129 virtual void validate (); 131 130 … … 148 147 shared_ptr<pdf> condition ( const RV &rv ) const; 149 148 150 //Access methods 151 //! returns a pointer to the internal mean value. Use with Care!149 //Access methods 150 //! returns a reference to the internal weights. Use with Care! 152 151 vec& _w() { 153 152 return w; 154 153 } 155 154 156 //!access function 155 /*! 156 \brief returns a reference to the internal array of components. Use with Care! Set components \c Coms 157 158 Shared pointers in Coms are kept inside this instance and 159 shouldn't be modified after being passed to this method. 160 */ 161 Array<shared_ptr<epdf>>& _Coms ( ) { 162 return Coms; 163 } 164 165 //! returns a reference to the internal components specified by index i. Use with Care! 157 166 shared_ptr<epdf> _Coms ( int i ) { 158 167 return Coms ( i ); … … 174 183 //! \endcode 175 184 //!@} 176 void from_setting ( const Setting &set ) { 177 178 vec w0; 179 Array<shared_ptr<epdf> > Coms0; 180 181 UI::get ( Coms0, set, "pdfs", UI::compulsory ); 182 183 if ( !UI::get ( w0, set, "weights", UI::optional ) ) { 184 int len = Coms.length(); 185 w0.set_length ( len ); 186 w0 = 1.0 / len; 187 } 188 189 // TODO asi lze nacitat primocare do w a coms, jen co bude hotovy validate() 190 set_parameters ( w0, Coms0 ); 191 validate(); 192 } 185 void from_setting ( const Setting &set ); 193 186 }; 194 187 SHAREDPTR ( emix ); … … 284 277 //! Data link for each pdfs 285 278 Array<shared_ptr<datalink_m2m> > dls; 286 287 protected:288 //! dummy epdf used only as storage for RV and dim289 epdf iepdf;290 279 291 280 public: … … 330 319 //!@} 331 320 void from_setting ( const Setting &set ) { 332 Array<shared_ptr<pdf> > atmp; //temporary Array333 UI::get ( atmp, set, "pdfs", UI::compulsory );334 set_elements ( atmp);321 Array<shared_ptr<pdf> > temp_array; 322 UI::get ( temp_array, set, "pdfs", UI::compulsory ); 323 set_elements ( temp_array ); 335 324 } 336 325 }; … … 418 407 mmix() : Coms ( 0 ) { } 419 408 420 //! Set weights \c w and components \c R421 void set_parameters ( const vec &w0, const Array<shared_ptr<pdf> > &Coms0 ) {422 //!\todo check if all components are OK423 Coms = Coms0;424 w = w0;425 426 if ( Coms0.length() > 0 ) {427 set_rv ( Coms ( 0 )->_rv() );428 dim = rv._dsize();429 set_rvc ( Coms ( 0 )->_rvc() );430 dimc = rvc._dsize();431 }432 }433 409 double evallogcond ( const vec &dt, const vec &cond ) { 434 410 double ll = 0.0; … … 449 425 //! \endcode 450 426 //!@} 451 void from_setting ( const Setting &set ) { 452 UI::get ( Coms, set, "pdfs", UI::compulsory ); 453 454 // TODO ma byt zde, ci ve validate()? 455 if ( Coms.length() > 0 ) { 456 set_rv ( Coms ( 0 )->_rv() ); 457 dim = rv._dsize(); 458 set_rvc ( Coms ( 0 )->_rvc() ); 459 dimc = rvc._dsize(); 460 } 461 462 if ( !UI::get ( w, set, "weights", UI::optional ) ) { 463 int len = Coms.length(); 464 w.set_length ( len ); 465 w = 1.0 / len; 466 } 467 } 427 void from_setting ( const Setting &set ); 428 429 virtual void validate(); 468 430 }; 469 431 SHAREDPTR ( mmix ); -
library/bdm/stat/exp_family.h
r763 r766 44 44 45 45 //!Evaluate normalized log-probability 46 virtual double evallog_nn ( const vec &val ) const { 47 bdm_error ( "Not implemented" ); 48 return 0.0; 49 } 46 virtual double evallog_nn ( const vec &val ) const NOT_IMPLEMENTED(0); 50 47 51 48 //!Evaluate normalized log-probability … … 73 70 74 71 //!Power of the density, used e.g. to flatten the density 75 virtual void pow ( double p ) { 76 bdm_error ( "Not implemented" ); 77 } 72 virtual void pow ( double p ) NOT_IMPLEMENTED_VOID; 78 73 }; 79 74 … … 92 87 BMEF ( const BMEF &B ) : BM ( B ), frg ( B.frg ), last_lognc ( B.last_lognc ) {} 93 88 //!get statistics from another model 94 virtual void set_statistics ( const BMEF* BM0 ) { 95 bdm_error ( "Not implemented" ); 96 } 89 virtual void set_statistics ( const BMEF* BM0 ) NOT_IMPLEMENTED_VOID; 97 90 98 91 //! Weighted update of sufficient statistics (Bayes rule) … … 102 95 103 96 //!Flatten the posterior according to the given BMEF (of the same type!) 104 virtual void flatten ( const BMEF * B ) { 105 bdm_error ( "Not implemented" ); 106 } 107 108 BMEF* _copy_ () const { 109 bdm_error ( "function _copy_ not implemented for this BM" ); 110 return NULL; 111 } 97 virtual void flatten ( const BMEF * B ) NOT_IMPLEMENTED_VOID; 98 99 double logpred ( const vec &yt ) const NOT_IMPLEMENTED(0); 100 101 virtual epdf* epredictor() const NOT_IMPLEMENTED(NULL); 102 103 virtual pdf* predictor() const NOT_IMPLEMENTED(NULL); 112 104 113 105 void to_setting ( Setting &set ) const 114 106 { 115 107 BM::to_setting( set ); 116 // TODO DOPLNIT? CHYBI FROM_SETTING PRO INSPIRACI108 // TODO DOPLNIT? ALE MOMENTALNE CHYBI FROM_SETTING PRO INSPIRACI 117 109 } 118 110 }; … … 1112 1104 //! Constructor 1113 1105 migamma_ref () : migamma (), refl () {}; 1106 1114 1107 //! Set value of \c k 1115 1108 void set_parameters ( double k0 , vec ref0, double l0 ) { … … 1266 1259 return X*Y._Ch();// return upper triangular part of the decomposition 1267 1260 } 1261 1268 1262 vec sample () const { 1269 1263 return vec ( sample_mat()._data(), p*p ); 1270 1264 } 1265 1266 virtual vec mean() const NOT_IMPLEMENTED(0); 1267 1268 //! return expected variance (not covariance!) 1269 virtual vec variance() const NOT_IMPLEMENTED(0); 1270 1271 virtual double evallog ( const vec &val ) const NOT_IMPLEMENTED(0); 1272 1271 1273 //! fast access function y0 will be copied into Y.Ch. 1272 1274 void setY ( const mat &Ch0 ) { 1273 1275 copy_vector ( dim, Ch0._data(), Y._Ch()._data() ); 1274 1276 } 1277 1275 1278 //! fast access function y0 will be copied into Y.Ch. 1276 1279 void _setY ( const vec &ch0 ) { 1277 1280 copy_vector ( dim, ch0._data(), Y._Ch()._data() ); 1278 1281 } 1282 1279 1283 //! access function 1280 1284 const chmat& getY() const { … … 1321 1325 W.setY ( iCh ); 1322 1326 } 1327 1323 1328 virtual double evallog ( const vec &val ) const { 1324 1329 chmat X ( p ); … … 1345 1350 }; 1346 1351 1352 virtual vec mean() const NOT_IMPLEMENTED(0); 1353 1354 //! return expected variance (not covariance!) 1355 virtual vec variance() const NOT_IMPLEMENTED(0); 1347 1356 }; 1348 1357 … … 1464 1473 1465 1474 //! inherited operation : NOT implemented 1466 vec sample() const { 1467 bdm_error ( "Not implemented" ); 1468 return vec(); 1469 } 1475 vec sample() const NOT_IMPLEMENTED(0); 1470 1476 1471 1477 //! inherited operation : NOT implemented 1472 double evallog ( const vec &val ) const { 1473 bdm_error ( "Not implemented" ); 1474 return 0.0; 1475 } 1478 double evallog ( const vec &val ) const NOT_IMPLEMENTED(0); 1476 1479 1477 1480 vec mean() const { -
library/bdm/stat/merger.h
r763 r766 148 148 149 149 vec variance() const; 150 151 //! Compute log-probability of argument \c val 152 virtual double evallog ( const vec &val ) const NOT_IMPLEMENTED(0); 153 154 //! Returns a sample, \f$ x \f$ from density \f$ f_x()\f$ 155 virtual vec sample() const NOT_IMPLEMENTED(0); 150 156 151 157 //!@} -
library/tests/stresssuite/arx_stress.cpp
r722 r766 24 24 //Test constructor 25 25 mat V0 = 0.00001 * eye ( ord + 1 ); 26 V0 ( 0 .0) = 1; //26 V0 ( 0 ) = 1; // 27 27 double nu0 = ord + 5.0; 28 28 -
library/tests/stresssuite/mixtures_stress.cpp
r750 r766 67 67 emix Simul; 68 68 Simul.set_rv ( x ); 69 Simul.set_parameters ( "0.5 0.6", Sim ); 69 Simul._w() = "0.5 0.6"; 70 Simul._Coms() = Sim; 70 71 Simul.validate(); 71 72 -
library/tests/stresssuite/square_mat_stress.cpp
r717 r766 60 60 61 61 tt.tic(); 62 TMatrix sq mat ( A );62 TMatrix sq_mat ( A ); 63 63 double elapsed = tt.toc(); 64 64 cout << "ctor(" << sz << " x " << sz << "): " << elapsed << " s" << endl; 65 65 66 66 tt.tic(); 67 mat res = sq mat.to_mat();67 mat res = sq_mat.to_mat(); 68 68 elapsed = tt.toc(); 69 69 … … 76 76 vec v = point->get_vector(); 77 77 double w = point->get_scalar(); 78 TMatrix sq mat2 = sqmat;79 80 tt.tic(); 81 sq mat2.opupdt ( v, w );78 TMatrix sq_mat2 = sq_mat; 79 80 tt.tic(); 81 sq_mat2.opupdt ( v, w ); 82 82 elapsed = tt.toc(); 83 83 84 84 if ( !fast ) { 85 85 mat expA = A + w * outer_product ( v, v ); 86 CHECK_CLOSE ( expA, sq mat2.to_mat(), epsilon );86 CHECK_CLOSE ( expA, sq_mat2.to_mat(), epsilon ); 87 87 } 88 88 … … 92 92 93 93 tt.tic(); 94 sq mat.inv ( invmat );94 sq_mat.inv ( invmat ); 95 95 elapsed = tt.toc(); 96 96 … … 104 104 105 105 tt.tic(); 106 double ld = sq mat.logdet();106 double ld = sq_mat.logdet(); 107 107 elapsed = tt.toc(); 108 108 … … 115 115 116 116 tt.tic(); 117 double q = sq mat.qform ( ones ( sz ) );117 double q = sq_mat.qform ( ones ( sz ) ); 118 118 elapsed = tt.toc(); 119 119 … … 125 125 126 126 tt.tic(); 127 q = sq mat.qform ( v );127 q = sq_mat.qform ( v ); 128 128 elapsed = tt.toc(); 129 129 … … 136 136 137 137 tt.tic(); 138 q = sq mat.invqform ( v );138 q = sq_mat.invqform ( v ); 139 139 elapsed = tt.toc(); 140 140 … … 146 146 cout << "invqform: " << elapsed << " s" << endl; 147 147 148 TMatrix twice = sq mat;149 150 tt.tic(); 151 twice += sq mat;148 TMatrix twice = sq_mat; 149 150 tt.tic(); 151 twice += sq_mat; 152 152 elapsed = tt.toc(); 153 153 … … 159 159 cout << "+=: " << elapsed << " s" << endl; 160 160 161 sq mat2 = sqmat;162 163 tt.tic(); 164 sq mat2.mult_sym ( A );161 sq_mat2 = sq_mat; 162 163 tt.tic(); 164 sq_mat2.mult_sym ( A ); 165 165 elapsed = tt.toc(); 166 166 167 167 if ( !fast ) { 168 168 res = ( A * A ) * A.T(); 169 CHECK_CLOSE ( res, sq mat2.to_mat(), epsilon );169 CHECK_CLOSE ( res, sq_mat2.to_mat(), epsilon ); 170 170 } 171 171 -
library/tests/testsuite/emix_test.cpp
r750 r766 38 38 emix M1; 39 39 M1.set_rv ( xy ); 40 M1.set_parameters ( vec ( "1" ), A1 ); 40 M1._Coms() = A1; 41 M1._w() = 1; 41 42 M1.validate(); 42 43 … … 68 69 emix M2; 69 70 M2.set_rv ( xy ); 70 M2.set_parameters ( vec ( "1" ), A2 ); 71 M2._Coms() = A2; 72 M2._w() = 1; 71 73 M2.validate(); 72 74 -
library/tests/testsuite/square_mat_test.cpp
r717 r766 20 20 mat A = A0 * A0.T(); 21 21 22 TMatrix sq mat ( A );23 CHECK_EQUAL ( sz, sq mat.rows() );24 CHECK_EQUAL ( sz, sq mat.cols() );22 TMatrix sq_mat ( A ); 23 CHECK_EQUAL ( sz, sq_mat.rows() ); 24 CHECK_EQUAL ( sz, sq_mat.cols() ); 25 25 26 mat res = sq mat.to_mat();26 mat res = sq_mat.to_mat(); 27 27 CHECK_CLOSE ( A, res, epsilon ); 28 28 29 29 vec v = randu ( sz ); 30 30 double w = randu(); 31 TMatrix sq mat2 = sqmat;32 sq mat2.opupdt ( v, w );31 TMatrix sq_mat2 = sq_mat; 32 sq_mat2.opupdt ( v, w ); 33 33 34 34 res = A + w * outer_product ( v, v ); 35 CHECK_CLOSE ( res, sq mat2.to_mat(), epsilon );35 CHECK_CLOSE ( res, sq_mat2.to_mat(), epsilon ); 36 36 37 37 TMatrix invmat ( sz ); 38 sq mat.inv ( invmat );38 sq_mat.inv ( invmat ); 39 39 mat invA = inv ( A ); 40 40 CHECK_CLOSE ( invA, invmat.to_mat(), epsilon ); 41 41 42 42 double d = det ( A ); 43 CHECK_CLOSE ( log ( d ), sq mat.logdet(), epsilon );43 CHECK_CLOSE ( log ( d ), sq_mat.logdet(), epsilon ); 44 44 45 double q = sq mat.qform ( ones ( sz ) );45 double q = sq_mat.qform ( ones ( sz ) ); 46 46 CHECK_CLOSE ( sumsum ( A ), q, epsilon ); 47 47 48 q = sq mat.qform ( v );48 q = sq_mat.qform ( v ); 49 49 double r = ( A * v ) * v; 50 50 CHECK_CLOSE ( r, q, epsilon ); 51 51 52 q = sq mat.invqform ( v );52 q = sq_mat.invqform ( v ); 53 53 r = ( invA * v ) * v; 54 54 CHECK_CLOSE ( r, q, epsilon ); 55 55 56 sq mat2 = sqmat;57 sq mat2.clear();58 CHECK_EQUAL ( 0, sq mat2.qform ( ones ( sz ) ) );56 sq_mat2 = sq_mat; 57 sq_mat2.clear(); 58 CHECK_EQUAL ( 0, sq_mat2.qform ( ones ( sz ) ) ); 59 59 60 TMatrix twice = sq mat;61 twice += sq mat;60 TMatrix twice = sq_mat; 61 twice += sq_mat; 62 62 res = 2 * A; 63 63 CHECK_CLOSE ( res, twice.to_mat(), epsilon ); 64 64 65 twice = sq mat;65 twice = sq_mat; 66 66 twice *= 2; 67 67 CHECK_CLOSE ( res, twice.to_mat(), epsilon ); 68 68 69 sq mat2 = sqmat;69 sq_mat2 = sq_mat; 70 70 mat B = randu ( sz, sz ); 71 sq mat2.mult_sym ( B );71 sq_mat2.mult_sym ( B ); 72 72 res = ( B * A ) * B.T(); 73 CHECK_CLOSE ( res, sq mat2.to_mat(), epsilon );73 CHECK_CLOSE ( res, sq_mat2.to_mat(), epsilon ); 74 74 75 75 mat C = randu ( sz, sz - 1 ); 76 76 TMatrix CAC ( sz - 1 ); 77 sq mat.mult_sym_t ( C, CAC );77 sq_mat.mult_sym_t ( C, CAC ); 78 78 res = ( C.T() * A ) * C; 79 79 CHECK_CLOSE ( res, CAC.to_mat(), epsilon ); 80 80 81 sq mat2 = sqmat;82 sq mat2.mult_sym_t ( B );81 sq_mat2 = sq_mat; 82 sq_mat2.mult_sym_t ( B ); 83 83 res = ( B.T() * A ) * B; 84 CHECK_CLOSE ( res, sq mat2.to_mat(), epsilon );84 CHECK_CLOSE ( res, sq_mat2.to_mat(), epsilon ); 85 85 } 86 86