- Timestamp:
- 08/14/09 09:03:02 (15 years ago)
- Location:
- library
- Files:
-
- 20 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.h
r527 r529 226 226 }; 227 227 UIREGISTER (RV); 228 SHAREDPTR (RV); 228 229 229 230 //! Concat two random variables … … 386 387 387 388 }; 388 389 SHAREDPTR(epdf); 389 390 390 391 //! Conditional probability density, e.g. modeling some dependencies. … … 487 488 //!@} 488 489 }; 490 SHAREDPTR(mpdf); 489 491 490 492 template <class EPDF> … … 740 742 }; 741 743 UIREGISTER (mepdf); 744 SHAREDPTR (mepdf); 742 745 743 746 //! \brief Combines RVs from a list of mpdfs to a single one. … … 990 993 }; 991 994 995 typedef Array<shared_ptr<epdf> > epdf_array; 996 997 typedef Array<shared_ptr<mpdf> > mpdf_array; 998 992 999 template<class EPDF> 993 1000 vec mpdf_internal<EPDF>::samplecond (const vec &cond) -
library/bdm/base/datasources.h
r527 r529 107 107 108 108 UIREGISTER ( ITppFileDS ); 109 SHAREDPTR ( ITppFileDS ); 109 110 110 111 /*! … … 263 264 264 265 UIREGISTER ( ArxDS ); 266 SHAREDPTR ( ArxDS ); 265 267 266 268 class stateDS : public DS { … … 346 348 347 349 UIREGISTER ( stateDS ); 350 SHAREDPTR ( stateDS ); 348 351 349 352 }; //namespace -
library/bdm/base/loggers.h
r477 r529 92 92 93 93 UIREGISTER ( memlog ); 94 SHAREDPTR ( memlog ); 94 95 95 96 /*! … … 139 140 140 141 UIREGISTER ( dirfilelog ); 142 SHAREDPTR ( dirfilelog ); 141 143 142 144 }; -
library/bdm/base/user_info.h
r527 r529 550 550 ParticularUI<T> ( const string &class_name ) : UI ( class_name, &typeid ( T ) ) {}; 551 551 552 //! A method returning a brand new instance of class T, this method is the reason why there have to be a parameterless construc otor in class T552 //! A method returning a brand new instance of class T, this method is the reason why there have to be a parameterless constructor in class T 553 553 root* new_instance() const { 554 554 return new T(); … … 565 565 \brief Macro for registration of class into map of user-infos, registered class is scriptable using UI static methods 566 566 567 Argument \a class_name has to be a descendant of root class and also , it has to have parameterless constructor prepared.567 Argument \a class_name has to be a descendant of root class and also to have a default constructor. 568 568 This macro should be used in header file, immediately after a class declaration. 569 569 -
library/bdm/estim/arx.h
r477 r529 164 164 165 165 UIREGISTER ( ARX ); 166 SHAREDPTR ( ARX ); 166 167 167 168 } -
library/bdm/estim/kalman.h
r527 r529 280 280 281 281 UIREGISTER ( EKFCh ); 282 SHAREDPTR ( EKFCh ); 282 283 283 284 … … 466 467 467 468 UIREGISTER ( MultiModel ); 469 SHAREDPTR ( MultiModel ); 468 470 469 471 -
library/bdm/mex/mex_datasource.h
r477 r529 40 40 it_assert_debug ( time < Data.cols(), "MemDS delays are too high." ); 41 41 42 RV*r = UI::build<RV> ( set, "rv", UI::compulsory );42 shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::compulsory ); 43 43 RV ru = RV(); 44 44 set_rvs ( *r, ru ); … … 50 50 51 51 UIREGISTER ( MexDS ); 52 SHAREDPTR ( MexDS ); 52 53 53 54 } -
library/bdm/mex/mex_logger.h
r477 r529 71 71 }; 72 72 UIREGISTER ( mexlog ); 73 SHAREDPTR ( mexlog ); 73 74 } -
library/bdm/shared_ptr.h
r477 r529 1 1 /*! 2 2 \file 3 \brief BDM's own smart pointer .3 \brief BDM's own smart pointers. 4 4 \author Vaclav Barta. 5 5 … … 22 22 namespace bdm { 23 23 24 //! A naive implementation of roughly a subset of the std::tr1:shared_ptr spec (really just roughly - it ignores memory exceptions, for example; also note I didn't read the spec). 25 // The standard template would naturally be preferable, _if_ it was 26 // included in the standard libraries of all supported compilers - but 27 // that's exactly what remains to be seen... 24 /*! \brief A naive implementation of roughly a subset of the std::tr1:shared_ptr spec 25 26 Really just roughly - it ignores memory 27 exceptions, for example; also note I didn't read the spec. 28 29 The standard template would naturally be preferable, _if_ it was 30 included in the standard libraries of all supported compilers - but 31 as of 2009, that's still a problem... 32 */ 28 33 template <typename T> 29 34 class shared_ptr { … … 41 46 } 42 47 43 //! Constructs a shared_ptr that owns the pointer p (unless p is 44 //! null, in which case this constructor creates an empty 45 //! shared_ptr). 48 /*! 49 Constructs a shared_ptr that owns the pointer p (unless p 50 is NULL, in which case this constructor creates an empty 51 shared_ptr). When p isn't null, it must have been alllocated 52 by new! 53 */ 46 54 shared_ptr ( T *p ) : 47 55 payload ( p ), … … 70 78 } 71 79 72 shared_ptr &operator= ( const shared_ptr&other ) {80 shared_ptr<T> &operator= ( const shared_ptr<T> &other ) { 73 81 other.add_ref(); 74 82 del_ref(); … … 178 186 } 179 187 188 /*! \brief A wrapper of shared_ptr which is never empty. 189 190 T must have a default constructor. 191 192 Note that shared_ptr's destructor isn't virtual - don't call delete 193 on pointers to instances of this class. 194 */ 195 template <typename T> 196 class object_ptr : public shared_ptr<T> 197 { 198 public: 199 /*! 200 \brief Default constructor 201 202 Calls T's default constructor. 203 */ 204 object_ptr() : shared_ptr<T> ( new T() ) { } 205 206 /*! 207 \brief Upcast from shared_ptr<T> to object_ptr<T> 208 209 \param b The shared pointer, which must not be empty. 210 */ 211 object_ptr ( const shared_ptr<T> &b ) : shared_ptr<T> ( b ) { 212 it_assert_debug ( this->get(), "object_ptr cannot be empty" ); 213 } 214 215 /*! 216 Constructs an object_ptr that owns the pointer p. p must 217 have been alllocated by new! 218 */ 219 object_ptr ( T *p ) : shared_ptr<T> ( p ) { 220 it_assert_debug ( p, "object_ptr cannot be empty" ); 221 } 222 223 object_ptr<T> &operator= ( const object_ptr<T> &other ) { 224 shared_ptr<T>::operator= ( other ); 225 return *this; 226 } 227 }; 228 229 #define SHAREDPTR(class_name) typedef bdm::object_ptr< class_name > class_name##_ptr 230 231 #define SHAREDPTR2(template_class_name, template_parameter_name) typedef bdm::object_ptr< template_class_name < template_parameter_name > > template_class_name##_##template_parameter_name##_ptr 232 180 233 } 181 234 -
library/bdm/stat/emix.h
r527 r529 186 186 } 187 187 }; 188 188 SHAREDPTR( emix ); 189 189 190 190 /*! … … 362 362 }; 363 363 UIREGISTER ( mprod ); 364 SHAREDPTR ( mprod ); 364 365 365 366 //! Product of independent epdfs. For dependent pdfs, use mprod. -
library/bdm/stat/exp_family.h
r527 r529 165 165 }; 166 166 UIREGISTER (enorm<chmat>); 167 SHAREDPTR2 ( enorm, chmat ); 167 168 UIREGISTER (enorm<ldmat>); 169 SHAREDPTR2 ( enorm, ldmat ); 168 170 UIREGISTER (enorm<fsqmat>); 171 SHAREDPTR2 ( enorm, fsqmat ); 169 172 170 173 … … 241 244 //!@} 242 245 }; 243 UIREGISTER (egiw); 246 UIREGISTER ( egiw ); 247 SHAREDPTR ( egiw ); 244 248 245 249 /*! \brief Dirichlet posterior density … … 399 403 }; 400 404 UIREGISTER (egamma); 405 SHAREDPTR ( egamma ); 406 401 407 /*! 402 408 \brief Inverse-Gamma posterior density … … 566 572 }; 567 573 UIREGISTER (mlnorm<ldmat>); 574 SHAREDPTR2 ( mlnorm, ldmat ); 568 575 UIREGISTER (mlnorm<fsqmat>); 576 SHAREDPTR2 ( mlnorm, fsqmat ); 569 577 UIREGISTER (mlnorm<chmat>); 578 SHAREDPTR2 ( mlnorm, chmat ); 570 579 571 580 //! Mpdf with general function for mean value … … 627 636 628 637 UIREGISTER (mgnorm<chmat>); 638 SHAREDPTR2 ( mgnorm, chmat ); 629 639 630 640 … … 716 726 }; 717 727 UIREGISTER (mgamma); 728 SHAREDPTR (mgamma); 718 729 719 730 /*! … … 860 871 861 872 UIREGISTER (migamma_ref); 873 SHAREDPTR (migamma_ref); 862 874 863 875 /*! Log-Normal probability density … … 941 953 942 954 UIREGISTER (mlognorm); 955 SHAREDPTR (mlognorm); 943 956 944 957 /*! inverse Wishart density defined on Choleski decomposition -
library/bdm/stat/merger.h
r507 r529 316 316 }; 317 317 UIREGISTER ( merger_base ); 318 SHAREDPTR ( merger_base ); 318 319 319 320 class merger_mix : public merger_base { … … 398 399 }; 399 400 UIREGISTER ( merger_mix ); 401 SHAREDPTR ( merger_mix ); 400 402 401 403 } -
library/tests/emix_test.cpp
r522 r529 1 #include "shared_ptr.h"2 1 #include "stat/exp_family.h" 3 2 #include "stat/emix.h" … … 20 19 vec mu0 ( "1.00054 1.0455" ); 21 20 22 shared_ptr<enorm<ldmat> > E1 = new enorm<ldmat>();21 enorm_ldmat_ptr E1; 23 22 E1->set_rv ( xy ); 24 23 E1->set_parameters ( mu0 , mat ( "0.740142 -0.259015; -0.259015 1.0302" ) ); 25 24 26 shared_ptr<enorm<ldmat> > E2 = new enorm<ldmat>();25 enorm_ldmat_ptr E2; 27 26 E2->set_rv ( xy ); 28 27 E2->set_parameters ( "-1.2 -0.1" , mat ( "1 0.4; 0.4 0.5" ) ); 29 28 30 Array<shared_ptr<epdf> >A1 ( 1 );29 epdf_array A1 ( 1 ); 31 30 A1 ( 0 ) = E1; 32 31 … … 36 35 37 36 // test if ARX and emix with one ARX are the same 38 shared_ptr<epdf>Mm = M1.marginal ( y );39 shared_ptr<epdf>Am = E1->marginal ( y );40 shared_ptr<mpdf>Mc = M1.condition ( y );41 shared_ptr<mpdf>Ac = E1->condition ( y );37 epdf_ptr Mm = M1.marginal ( y ); 38 epdf_ptr Am = E1->marginal ( y ); 39 mpdf_ptr Mc = M1.condition ( y ); 40 mpdf_ptr Ac = E1->condition ( y ); 42 41 43 42 mlnorm<ldmat> *wacnd = dynamic_cast<mlnorm<ldmat> *>( Ac.get() ); … … 56 55 57 56 // mixture with two components 58 Array<shared_ptr<epdf> >A2 ( 2 );57 epdf_array A2 ( 2 ); 59 58 A2 ( 0 ) = E1; 60 59 A2 ( 1 ) = E2; … … 80 79 check_covariance ( M2, N, observedR, 2.0); 81 80 82 shared_ptr<epdf>Mg = M2.marginal ( y );81 epdf_ptr Mg = M2.marginal ( y ); 83 82 CHECK ( Mg.get() ); 84 shared_ptr<mpdf>Cn = M2.condition ( x );83 mpdf_ptr Cn = M2.condition ( x ); 85 84 CHECK ( Cn.get() ); 86 85 … … 90 89 91 90 TEST ( test_emix_2 ) { 92 int N = 10000; // number of samples91 int N = 10000; // number of samples 93 92 vec mu0 ( "1.5 1.7" ); 94 93 mat V0 ( "1.2 0.3; 0.3 5" ); 95 94 ldmat R = ldmat ( V0 ); 96 95 97 shared_ptr<enorm<ldmat> > eN = new enorm<ldmat>();96 enorm_ldmat_ptr eN; 98 97 eN->set_parameters ( mu0, R ); 99 98 100 99 vec a = "100000,10000"; 101 100 vec b = a / 10.0; 102 shared_ptr<egamma> eG = new egamma();101 egamma_ptr eG; 103 102 eG->set_parameters ( a, b ); 104 103 105 104 emix eMix; 106 Array<shared_ptr<epdf> >Coms ( 2 );105 epdf_array Coms ( 2 ); 107 106 Coms ( 0 ) = eG; 108 107 Coms ( 1 ) = eN; -
library/tests/epdf_harness.cpp
r527 r529 64 64 } 65 65 66 if ( mrv .get()) {66 if ( mrv ) { 67 67 RV crv = hepdf->_rv().subt ( *mrv ); 68 shared_ptr<epdf>m = hepdf->marginal ( *mrv );69 shared_ptr<mpdf>c = hepdf->condition ( crv );70 71 Array<shared_ptr<mpdf> >aa ( 2 );68 epdf_ptr m = hepdf->marginal ( *mrv ); 69 mpdf_ptr c = hepdf->condition ( crv ); 70 71 mpdf_array aa ( 2 ); 72 72 aa ( 0 ) = c; 73 73 aa ( 1 ) = new mepdf ( m ); -
library/tests/merger_2d_test.cpp
r507 r529 21 21 xy.add ( y ); 22 22 23 shared_ptr<enorm<fsqmat> > f1 = new enorm<fsqmat>();23 enorm_fsqmat_ptr f1; 24 24 f1->set_rv ( xy ); 25 shared_ptr<enorm<fsqmat> > f2 = new enorm<fsqmat>();25 enorm_fsqmat_ptr f2; 26 26 f2->set_rv ( xy ); 27 27 … … 31 31 f2->set_parameters ( "1 1", mat ( "0.5 0; 0 0.1" ) ); 32 32 33 Array<shared_ptr<mpdf> >A ( 2 );34 shared_ptr<mepdf>A1 = new mepdf ( f1 );35 shared_ptr<mepdf>A2 = new mepdf ( f2 );33 mpdf_array A ( 2 ); 34 mepdf_ptr A1 = new mepdf ( f1 ); 35 mepdf_ptr A2 = new mepdf ( f2 ); 36 36 A ( 0 ) = A1; 37 37 A ( 1 ) = A2; -
library/tests/merger_iter_test.cpp
r507 r529 21 21 xy.add ( y ); 22 22 23 shared_ptr<enorm<fsqmat> > f1 = new enorm<fsqmat>();23 enorm_fsqmat_ptr f1; 24 24 f1->set_rv ( xy ); 25 shared_ptr<enorm<fsqmat> > f2 = new enorm<fsqmat>();25 enorm_fsqmat_ptr f2; 26 26 f2->set_rv ( xy ); 27 shared_ptr<enorm<fsqmat> > f3 = new enorm<fsqmat>();27 enorm_fsqmat_ptr f3; 28 28 f3->set_rv ( y ); 29 29 … … 32 32 f3->set_parameters ( "2", mat ( "0.4" ) ); 33 33 34 Array<shared_ptr<mpdf> >A ( 3 );34 mpdf_array A ( 3 ); 35 35 A ( 0 ) = new mepdf ( f1 ); 36 36 A ( 1 ) = new mepdf ( f2 ); -
library/tests/merger_test.cpp
r518 r529 13 13 RV z ( x ); 14 14 15 shared_ptr<enorm<fsqmat> > f1 = new enorm<fsqmat>();15 enorm_fsqmat_ptr f1; 16 16 f1->set_rv ( x ); 17 shared_ptr<enorm<fsqmat> > f2 = new enorm<fsqmat>();17 enorm_fsqmat_ptr f2; 18 18 f2->set_rv ( x ); 19 19 … … 21 21 f2->set_parameters ( "5", mat ( "10" ) ); 22 22 23 Array<shared_ptr<mpdf> >A ( 2 );23 mpdf_array A ( 2 ); 24 24 A ( 0 ) = new mepdf ( f1 ); 25 25 A ( 1 ) = new mepdf ( f2 ); -
library/tests/mixtures_test.cpp
r504 r529 53 53 fsqmat V2 ( mat ( "2 -0.1; -0.1 2" ) ); 54 54 55 shared_ptr<enorm<fsqmat> > C1 = new enorm<fsqmat>();55 enorm_fsqmat_ptr C1; 56 56 C1->set_rv ( x ); 57 57 C1->set_parameters ( m1, V1 ); 58 shared_ptr<enorm<fsqmat> > C2 = new enorm<fsqmat>();58 enorm_fsqmat_ptr C2; 59 59 C2->set_rv ( x ); 60 60 C2->set_parameters ( m2, V2 ); 61 61 62 Array<shared_ptr<epdf> >Sim ( 2 );62 epdf_array Sim ( 2 ); 63 63 Sim ( 0 ) = C1; 64 64 Sim ( 1 ) = C2; -
library/tests/mpdf_test.cpp
r524 r529 38 38 ldmat R = ldmat ( V0 ); 39 39 40 shared_ptr<enorm<ldmat> > eN = new enorm<ldmat>();40 enorm_ldmat_ptr eN; 41 41 eN->set_parameters ( mu0, R ); 42 42 43 shared_ptr<mgamma> mG = new mgamma();43 mgamma_ptr mG; 44 44 double k = 10.0; 45 45 mG->set_parameters ( k, mu0 ); 46 46 47 47 mmix mMix; 48 Array<shared_ptr<mpdf> >mComs ( 2 );48 mpdf_array mComs ( 2 ); 49 49 50 50 // mmix::set_parameters requires the first mpdf to be named … … 54 54 55 55 eN->set_mu ( vec_2 ( 0.0, 0.0 ) ); 56 shared_ptr<mepdf>mEnorm = new mepdf ( eN );56 mepdf_ptr mEnorm = new mepdf ( eN ); 57 57 mComs ( 1 ) = mEnorm; 58 58 59 59 mMix.set_parameters ( vec_2 ( 0.5, 0.5 ), mComs ); 60 60 61 double tolerance = 0.1;62 63 61 vec tmu = 0.5 * eN->mean() + 0.5 * mu0; 64 check_mean ( mMix, mu0, N, tmu, tolerance);62 check_mean ( mMix, mu0, N, tmu, 0.1 ); 65 63 66 64 mat observedR ( "1.27572 0.778247; 0.778247 3.33129" ); 67 check_covariance( mMix, mu0, N, observedR, tolerance);65 check_covariance( mMix, mu0, N, observedR, 0.2 ); 68 66 } 69 67 … … 75 73 ldmat R = ldmat ( V0 ); 76 74 77 shared_ptr<enorm<ldmat> > eN = new enorm<ldmat>();75 enorm_ldmat_ptr eN; 78 76 eN->set_parameters ( mu0, R ); 79 77 80 78 vec a = "100000,10000"; 81 79 vec b = a / 10.0; 82 shared_ptr<egamma> eG = new egamma();80 egamma_ptr eG; 83 81 eG->set_parameters ( a, b ); 84 82 85 shared_ptr<emix> eMix = new emix();86 Array<shared_ptr<epdf> >Coms ( 2 );83 emix_ptr eMix; 84 epdf_array Coms ( 2 ); 87 85 Coms ( 0 ) = eG; 88 86 Coms ( 1 ) = eN; -
library/tests/mprod.cfg
r519 r529 38 38 R = ( "matrix", 2, 2, [ 2.0, 0.5, 0.5, 0.5 ] ); 39 39 variance = [ 1.2, 5.0 ]; 40 tolerance = 0. 2;40 tolerance = 0.3; 41 41 }, 42 42 {