Changeset 527
- Timestamp:
- 08/13/09 15:58:32 (15 years ago)
- Location:
- library
- Files:
-
- 16 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.cpp
r507 r527 169 169 170 170 void mpdf::from_setting ( const Setting &set ) { 171 RV *r = UI::build<RV> ( set, "rv");171 shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::optional ); 172 172 if ( r ) { 173 173 set_rv ( *r ); 174 delete r; 175 } 176 177 r = UI::build<RV> ( set, "rvc" ); 174 } 175 176 r = UI::build<RV> ( set, "rvc", UI::optional ); 178 177 if ( r ) { 179 178 set_rvc ( *r ); 180 delete r;181 179 } 182 180 } -
library/bdm/base/bdmbase.h
r513 r527 379 379 //!@} 380 380 void from_setting (const Setting &set) { 381 RV* r = UI::build<RV> (set, "rv");381 shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::optional ); 382 382 if (r) { 383 383 set_rv (*r); 384 delete r;385 384 } 386 385 } … … 455 454 return rvc; 456 455 } 457 int dimension() { 456 457 int dimension() const { 458 458 return ep->dimension(); 459 459 } -
library/bdm/base/datasources.cpp
r477 r527 57 57 58 58 void ArxDS::from_setting ( const Setting &set ) { 59 RV *yrv = UI::build<RV> ( set, "y" , UI::compulsory );60 RV *urv = UI::build<RV> ( set, "u" , UI::compulsory );61 RV *rrv = UI::build<RV> ( set, "rgr" , UI::compulsory );59 shared_ptr<RV> yrv = UI::build<RV> ( set, "y" , UI::compulsory ); 60 shared_ptr<RV> urv = UI::build<RV> ( set, "u" , UI::compulsory ); 61 shared_ptr<RV> rrv = UI::build<RV> ( set, "rgr" , UI::compulsory ); 62 62 63 63 mat Th; … … 112 112 113 113 void ITppFileDS::from_setting ( const Setting &set ) { 114 RV*rvtmp = UI::build<RV> ( set, "rv" , UI::compulsory );114 shared_ptr<RV> rvtmp = UI::build<RV> ( set, "rv" , UI::compulsory ); 115 115 116 116 it_file it ( set["filename"] ); … … 131 131 ut.set_length ( 0 ); 132 132 133 #if 0 133 134 RV* rvtmp = UI::build<RV> ( set["IM"], "rvu", UI::compulsory ); 134 135 //set_drv(rvtmp); 136 #endif 135 137 } -
library/bdm/base/datasources.h
r477 r527 173 173 }; 174 174 //! Set 175 void set_drv ( RV &yrv, RV &urv,RV &rrv ) {175 void set_drv ( const RV &yrv, const RV &urv, const RV &rrv ) { 176 176 Rrv = rrv; 177 177 Urv = urv; … … 265 265 266 266 class stateDS : public DS { 267 private: 268 //!conditional pdf of the state evolution \f$ f(x_t|x_{t-1}) \f$ 269 shared_ptr<mpdf> IM; 270 271 //!conditional pdf of the observations \f$ f(d_t|x_t) \f$ 272 shared_ptr<mpdf> OM; 273 267 274 protected: 268 //!conditional pdf of the state evolution \f$ f(x_t|x_{t-1}) \f$269 mpdf* IM;270 //!conditional pdf of the observations \f$ f(d_t|x_t) \f$271 mpdf* OM;272 275 //! result storage 273 276 vec dt; … … 278 281 //! Logger 279 282 int L_xt; 283 280 284 public: 281 285 void getdata ( vec &dt0 ) { … … 286 290 } 287 291 288 stateDS ( mpdf* IM0, mpdf* OM0, int usize ) : DS ( ), IM ( IM0 ), OM ( OM0 ), 289 dt ( OM0->dimension() ), xt ( IM0->dimension() ), ut ( usize ) {} 290 291 stateDS() {} 292 293 ~stateDS() { 294 delete IM; 295 delete OM; 296 } 292 stateDS ( const shared_ptr<mpdf> &IM0, const shared_ptr<mpdf> &OM0, int usize ) : IM ( IM0 ), OM ( OM0 ), 293 dt ( OM0->dimension() ), xt ( IM0->dimension() ), 294 ut ( usize ), L_xt(0) { } 295 296 stateDS() : L_xt(0) { } 297 297 298 virtual void step() { 298 299 xt = IM->samplecond ( concat ( xt, ut ) ); 299 300 dt = OM->samplecond ( concat ( xt, ut ) ); 300 } ;301 } 301 302 302 303 virtual void log_add ( logger &L ) { -
library/bdm/base/user_info.h
r494 r527 24 24 #include "libconfig/libconfig.h++" 25 25 #include "../bdmroot.h" 26 #include "../shared_ptr.h" 26 27 #include "itpp/itbase.h" 27 28 … … 253 254 static void assert_type ( const Setting &element, Setting::Type type ); 254 255 255 //! Method assembling a typeless instance, it is implemented in descendant class ParticularUI<T> 256 /*! 257 \brief Method constructing a configured instance 258 259 The returned pointer must be allocated using operator new 260 (it's deleted at the end of its life cycle). The method is 261 implemented in descendant class ParticularUI<T>, which knows 262 the correct type T. 263 */ 256 264 virtual root* new_instance() const = 0; 257 265 … … 274 282 //! This method converts a Setting into a real scalar 275 283 static void from_setting ( double &real, const Setting &element ); 284 276 285 //! This method converts a Setting into a class T descendant 277 286 template<class T> static void from_setting ( T* &instance, const Setting &element ) { … … 287 296 const UI& related_UI = MappedUI::retrieve_ui ( class_name ); 288 297 289 root* typeless_instance = related_UI.new_instance(); 298 root *typeless_instance = related_UI.new_instance(); 299 it_assert_debug ( typeless_instance, "UI::new_instance failed" ); 290 300 291 301 instance = dynamic_cast<T*> ( typeless_instance ); 292 if ( !instance ) 302 if ( !instance ) { 303 delete typeless_instance; 293 304 throw UIException ( "class " + class_name + " is not a descendant of the desired output class. Try to call the UI::build<T> function with a different type parameter.", link.result ); 305 } 294 306 295 307 try { … … 301 313 } 302 314 315 //! This method converts a Setting into a descendant of class 316 //! T, wrapped in an instance of shared_ptr<T> . 317 template<class T> 318 static void from_setting ( shared_ptr<T> &instance, const Setting &element ) { 319 T *tmp_inst = 0; 320 from_setting ( tmp_inst, element ); 321 it_assert_debug ( tmp_inst, "UI::from_setting failed" ); 322 instance = tmp_inst; 323 } 324 303 325 //! This methods converts a Setting into a new templated array of type Array<T> 304 326 template<class T> static void from_setting ( Array<T> &array_to_load, const Setting &element ) { … … 320 342 //! The exception can help to find the place where the template is misused and also to correct it. 321 343 template<class T> static void from_setting ( T &variable_to_load, const Setting &element ) { 322 throw UIException ( "from_setting is not implemented for this type", element ); 344 std::string msg = "from_setting is not implemented for type "; 345 msg += typeid(T).name(); 346 throw UIException ( msg, element ); 323 347 } 324 348 … … 341 365 //! The new instance of type T* is constructed and initialized with values stored in the Setting element[name] 342 366 //! 343 //! If there is not any sub-element named #name, the null pointer is returned. 344 template<class T> static T* build ( const Setting &element, const string &name, SettingPresence settingPresence = optional ) { 367 //! If there is not any sub-element named #name and settingPresence is #optional, an empty shared_ptr<T> is returned. When settingPresence is #compulsory, the returned shared_ptr<T> is never empty (an exception is thrown when the object isn't found). 368 template<class T> 369 static shared_ptr<T> build ( const Setting &element, const string &name, SettingPresence settingPresence = optional ) { 345 370 if ( !element.exists ( name ) ) { 346 371 if ( settingPresence == optional ) 347 return NULL;372 return shared_ptr<T>(); 348 373 else 349 374 throw UIException ( "the compulsory Setting named \"" + name + "\" is missing", element ); 350 375 } 351 376 352 T*instance;377 shared_ptr<T> instance; 353 378 from_setting<T> ( instance, to_child_setting ( element, name ) ); 354 379 return instance; … … 483 508 } 484 509 510 template< class T> static void save ( const shared_ptr<T> &instance, Setting &element, const string &name = "" ) { 511 save<T> ( instance.get(), element, name ); 512 } 513 485 514 //! An Array<T> instance is stored in the new child Setting appended to the passed element 486 515 template<class T> static void save ( const Array<T> &array_to_save, Setting &element, const string &name = "" ) { -
library/bdm/estim/arx.cpp
r477 r527 194 194 195 195 void ARX::from_setting ( const Setting &set ) { 196 RV *yrv = UI::build<RV> ( set, "y", UI::compulsory );197 RV *rrv = UI::build<RV> ( set, "rgr", UI::compulsory );196 shared_ptr<RV> yrv = UI::build<RV> ( set, "y", UI::compulsory ); 197 shared_ptr<RV> rrv = UI::build<RV> ( set, "rgr", UI::compulsory ); 198 198 int ylen = yrv->_dsize(); 199 199 int rgrlen = rrv->_dsize(); … … 220 220 //name results (for logging) 221 221 set_rv ( RV ( "{theta r }", vec_2 ( ylen*rgrlen, ylen*ylen ) ) ); 222 223 delete yrv; 224 delete rrv; 225 } 226 227 } 222 } 223 224 } -
library/bdm/estim/kalman.cpp
r477 r527 64 64 EKFfull::EKFfull ( ) : BM (), E() {}; 65 65 66 void EKFfull::set_parameters ( diffbifn* pfxu0, diffbifn*phxu0, const mat Q0, const mat R0 ) {66 void EKFfull::set_parameters ( const shared_ptr<diffbifn> &pfxu0, const shared_ptr<diffbifn> &phxu0, const mat Q0, const mat R0 ) { 67 67 pfxu = pfxu0; 68 68 phxu = phxu0; … … 168 168 169 169 170 void EKFCh::set_parameters ( diffbifn* pfxu0, diffbifn*phxu0, const chmat Q0, const chmat R0 ) {170 void EKFCh::set_parameters ( const shared_ptr<diffbifn> &pfxu0, const shared_ptr<diffbifn> &phxu0, const chmat Q0, const chmat R0 ) { 171 171 pfxu = pfxu0; 172 172 phxu = phxu0; … … 255 255 256 256 void EKFCh::from_setting ( const Setting &set ) { 257 diffbifn*IM = UI::build<diffbifn> ( set, "IM", UI::compulsory );258 diffbifn*OM = UI::build<diffbifn> ( set, "OM", UI::compulsory );257 shared_ptr<diffbifn> IM = UI::build<diffbifn> ( set, "IM", UI::compulsory ); 258 shared_ptr<diffbifn> OM = UI::build<diffbifn> ( set, "OM", UI::compulsory ); 259 259 260 260 //statistics … … 280 280 281 281 //connect 282 RV*drv = UI::build<RV> ( set, "drv", UI::compulsory );282 shared_ptr<RV> drv = UI::build<RV> ( set, "drv", UI::compulsory ); 283 283 set_drv ( *drv ); 284 RV*rv = UI::build<RV> ( set, "rv", UI::compulsory );284 shared_ptr<RV> rv = UI::build<RV> ( set, "rv", UI::compulsory ); 285 285 set_rv ( *rv ); 286 286 -
library/bdm/estim/kalman.h
r477 r527 190 190 protected: 191 191 //! Internal Model f(x,u) 192 diffbifn* pfxu; 192 shared_ptr<diffbifn> pfxu; 193 193 194 //! Observation Model h(x,u) 194 diffbifn*phxu;195 shared_ptr<diffbifn> phxu; 195 196 196 197 enorm<fsqmat> E; … … 198 199 //! Default constructor 199 200 EKFfull ( ); 201 200 202 //! Set nonlinear functions for mean values and covariance matrices. 201 void set_parameters ( diffbifn* pfxu, diffbifn* phxu, const mat Q0, const mat R0 ); 203 void set_parameters ( const shared_ptr<diffbifn> &pfxu, const shared_ptr<diffbifn> &phxu, const mat Q0, const mat R0 ); 204 202 205 //! Here dt = [yt;ut] of appropriate dimensions 203 206 void bayes ( const vec &dt ); … … 252 255 protected: 253 256 //! Internal Model f(x,u) 254 diffbifn* pfxu; 257 shared_ptr<diffbifn> pfxu; 258 255 259 //! Observation Model h(x,u) 256 diffbifn*phxu;260 shared_ptr<diffbifn> phxu; 257 261 public: 258 262 //! copy constructor duplicated - calls different set_parameters … … 264 268 } 265 269 //! Set nonlinear functions for mean values and covariance matrices. 266 void set_parameters ( diffbifn* pfxu, diffbifn* phxu, const chmat Q0, const chmat R0 ); 270 void set_parameters ( const shared_ptr<diffbifn> &pfxu, const shared_ptr<diffbifn> &phxu, const chmat Q0, const chmat R0 ); 271 267 272 //! Here dt = [yt;ut] of appropriate dimensions 268 273 void bayes ( const vec &dt ); -
library/bdm/stat/emix.h
r515 r527 355 355 //!@} 356 356 void from_setting ( const Setting &set ) { 357 Array< mpdf*> atmp; //temporary Array357 Array<shared_ptr<mpdf> > atmp; //temporary Array 358 358 UI::get ( atmp, set, "mpdfs", UI::compulsory ); 359 360 Array<shared_ptr<mpdf> > btmp ( atmp.length() ); 361 for (int i = 0; i < atmp.length(); ++i) { 362 btmp ( i ) = shared_ptr<mpdf> ( atmp ( i ) ); 363 } 364 365 set_elements ( btmp ); 359 set_elements ( atmp ); 366 360 } 367 361 -
library/bdm/stat/exp_family.h
r510 r527 236 236 UI::get (V, set, "V", UI::compulsory); 237 237 set_parameters (dimx, V, nu); 238 RV*rv = UI::build<RV> (set, "rv", UI::compulsory);238 shared_ptr<RV> rv = UI::build<RV> (set, "rv", UI::compulsory); 239 239 set_rv (*rv); 240 delete rv;241 240 } 242 241 //!@} … … 574 573 class mgnorm : public mpdf_internal< enorm< sq_T > > 575 574 { 576 pr otected:575 private: 577 576 // vec μ WHY NOT? 578 fnc* g; 577 shared_ptr<fnc> g; 578 579 579 public: 580 580 //!default constructor 581 581 mgnorm() : mpdf_internal<enorm<sq_T> >() { } 582 582 //!set mean function 583 inline void set_parameters ( fnc*g0, const sq_T &R0);583 inline void set_parameters (const shared_ptr<fnc> &g0, const sq_T &R0); 584 584 inline void condition (const vec &cond); 585 585 … … 613 613 614 614 void from_setting (const Setting &set) { 615 fnc*g = UI::build<fnc> (set, "g", UI::compulsory);615 shared_ptr<fnc> g = UI::build<fnc> (set, "g", UI::compulsory); 616 616 617 617 mat R; … … 1305 1305 /////// 1306 1306 template<class sq_T> 1307 void mgnorm<sq_T >::set_parameters (fnc* g0, const sq_T &R0) {g = g0; this->iepdf.set_parameters (zeros (g->dimension()), R0);} 1307 void mgnorm<sq_T >::set_parameters (const shared_ptr<fnc> &g0, const sq_T &R0) { 1308 g = g0; 1309 this->iepdf.set_parameters (zeros (g->dimension()), R0); 1310 } 1311 1308 1312 template<class sq_T> 1309 1313 void mgnorm<sq_T >::condition (const vec &cond) {this->iepdf._mu() = g->eval (cond);}; -
library/tests/epdf_harness.cpp
r507 r527 14 14 15 15 UIFile in ( config_file_name ); 16 Array< epdf_harness *> input;16 Array<shared_ptr<epdf_harness> > input; 17 17 UI::get ( input, in, "data", UI::compulsory ); 18 18 int sz = input.size(); -
library/tests/mpdf_harness.cpp
r493 r527 13 13 14 14 UIFile in ( config_file_name ); 15 Array< mpdf_harness *> input;15 Array<shared_ptr<mpdf_harness> > input; 16 16 UI::get ( input, in, "data", UI::compulsory ); 17 17 int sz = input.size(); -
library/tests/square_mat_prep.cpp
r480 r527 7 7 #include <iostream> 8 8 #include <iomanip> 9 #include <memory>10 9 #include <stdlib.h> 11 10 … … 62 61 cerr << "usage: " << argv[0] << " [ -g generator.cfg ] [ -a agenda_output.cfg ] [ -l agenda_length ]" << endl; 63 62 } else { 64 Array<s quare_mat_point *> mag ( agenda_length );63 Array<shared_ptr<square_mat_point> > mag ( agenda_length ); 65 64 66 65 UIFile gspec ( generator_file_name ); 67 auto_ptr<generator> gen ( UI::build<generator> ( gspec, "generator", UI::compulsory ) );66 shared_ptr<generator> gen ( UI::build<generator> ( gspec, "generator", UI::compulsory ) ); 68 67 for ( int i = 0; i < agenda_length; ++i ) { 69 68 mat m = gen->next(); … … 76 75 UI::save ( mag, fag, "agenda" ); 77 76 fag.save ( agenda_file_name ); 78 79 for ( int i = 0; i < agenda_length; ++i ) {80 square_mat_point *p = mag ( i );81 mag ( i ) = 0;82 delete p;83 }84 77 } 85 78 } -
library/tests/square_mat_stress.cpp
r495 r527 17 17 using bdm::chmat; 18 18 using bdm::ldmat; 19 using bdm::shared_ptr; 19 20 using bdm::UIFile; 20 21 using bdm::UI; … … 174 175 void test_agenda ( FTestMatrix test ) { 175 176 UIFile fag ( agenda_file_name ); 176 Array<s quare_mat_point *> mag;177 Array<shared_ptr<square_mat_point> > mag; 177 178 UI::get ( mag, fag, "agenda", UI::compulsory ); 178 179 int sz = mag.size(); 179 180 CHECK ( sz > 0 ); 180 181 for ( int i = 0; i < sz; ++i ) { 181 test ( i, mag ( i ) ); 182 } 183 184 for ( int i = 0; i < sz; ++i ) { 185 square_mat_point *p = mag ( i ); 186 mag ( i ) = 0; 187 delete p; 182 test ( i, mag ( i ).get() ); 188 183 } 189 184 } -
library/tests/test_kalman.cpp
r477 r527 82 82 83 83 // EKF 84 bilinfn fxu( A, B );85 bilinfn hxu( C, D );84 shared_ptr<bilinfn> fxu = new bilinfn ( A, B ); 85 shared_ptr<bilinfn> hxu = new bilinfn ( C, D ); 86 86 EKFCh KFE; 87 KFE.set_parameters ( &fxu, &hxu, Q, R );87 KFE.set_parameters ( fxu, hxu, Q, R ); 88 88 KFE.set_est ( mu0, chmat ( P0 ) ); 89 89 const epdf& KFEep = KFE.posterior(); -
library/tests/user_info_test.cpp
r499 r527 1 #include <memory>2 1 #include <string> 3 2 #include <string.h> … … 103 102 public: 104 103 int kilometers; 105 Array< Passenger*> passengers;104 Array<shared_ptr<Passenger> > passengers; 106 105 107 106 Car() : Transport() { … … 192 191 TEST ( test_load ) { 193 192 UIFile in ( "test_user_info_input.cfg" ); 194 auto_ptr<Transport> pepikovo ( UI::build<Transport> ( in, "pepikovo", UI::compulsory ) );193 shared_ptr<Transport> pepikovo ( UI::build<Transport> ( in, "pepikovo", UI::compulsory ) ); 195 194 CHECK_EQUAL ( string ( "A car made in 1998 by audi, having 25000 kilometers on the clock.The names of passengers are as follows: Karlos Novak -1_CygWin_Matlab_Aimsun Karlosik Novacek " ), pepikovo->to_string() ); 196 195 197 auto_ptr<Transport> jardovo ( UI::build<Transport> ( in, "jardovo", UI::compulsory ) );196 shared_ptr<Transport> jardovo ( UI::build<Transport> ( in, "jardovo", UI::compulsory ) ); 198 197 CHECK_EQUAL ( string ( "A car made in 1992 by liaz, having 1555000 kilometers on the clock." ), jardovo->to_string() ); 199 198 200 auto_ptr<Transport> ondrejovo ( UI::build<Transport> ( in, "ondrejovo", UI::compulsory ) );199 shared_ptr<Transport> ondrejovo ( UI::build<Transport> ( in, "ondrejovo", UI::compulsory ) ); 201 200 CHECK_EQUAL ( string ( "a bike made in 1996 by author with electric lights included" ), ondrejovo->to_string() ); 202 201 203 auto_ptr<Transport> elisky ( UI::build<Transport> ( in, "elisky", UI::compulsory ) );202 shared_ptr<Transport> elisky ( UI::build<Transport> ( in, "elisky", UI::compulsory ) ); 204 203 CHECK_EQUAL ( string ( "A car made in 1992 by liaz, having 1555000 kilometers on the clock." ), elisky->to_string() ); 205 204 206 auto_ptr<Transport> kati ( UI::build<Transport> ( in, "kati", UI::compulsory ) );205 shared_ptr<Transport> kati ( UI::build<Transport> ( in, "kati", UI::compulsory ) ); 207 206 CHECK_EQUAL ( string ( "A car made in 1980 by vecernicek, having 250000 kilometers on the clock." ), kati->to_string() ); 208 207 } … … 210 209 TEST ( test_save ) { 211 210 UIFile in ( "test_user_info_input.cfg" ); 212 auto_ptr<Transport> pepikovo ( UI::build<Transport> ( in, "pepikovo", UI::compulsory ) );211 shared_ptr<Transport> pepikovo ( UI::build<Transport> ( in, "pepikovo", UI::compulsory ) ); 213 212 214 213 Car audi ( 1968, "zyl", 200 ); … … 220 219 UI::save ( &liaz, out, "bohousovo" ); 221 220 UI::save ( &author, out, "karlovo" ); 222 UI::save ( pepikovo .get(), out, "pepikovo" );221 UI::save ( pepikovo, out, "pepikovo" ); 223 222 out.save ( "testUI_out.cfg" ); 224 223