Changeset 507
- Timestamp:
- 08/12/09 15:37:43 (15 years ago)
- Location:
- library
- Files:
-
- 11 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.cpp
r504 r507 306 306 } 307 307 308 RV compositepdf::getrv ( bool checkoverlap ) { 308 RV get_composite_rv ( const Array<shared_ptr<mpdf> > &mpdfs, 309 bool checkoverlap ) { 309 310 RV rv; //empty rv 310 311 bool rvaddok; … … 312 313 rvaddok = rv.add ( mpdfs ( i )->_rv() ); //add rv to common rvs. 313 314 // If rvaddok==false, mpdfs overlap => assert error. 314 it_assert_debug ( rvaddok || ( !checkoverlap ), "mprod::mprod() input mpdfs overlap in rv!" ); 315 }; 315 it_assert_debug ( rvaddok || !checkoverlap, "mprod::mprod() input mpdfs overlap in rv!" ); 316 } 317 316 318 return rv; 317 }318 319 void compositepdf::setrvc ( const RV &rv, RV &rvc ) {320 for ( int i = 0; i < mpdfs.length(); i++ ) {321 RV rvx = mpdfs ( i )->_rvc().subt ( rv );322 rvc.add ( rvx ); //add rv to common rvc323 };324 319 } 325 320 -
library/bdm/base/bdmbase.h
r504 r507 449 449 //! @{ 450 450 451 RV _rv() {451 RV _rv() const { 452 452 return ep->_rv(); 453 453 } … … 742 742 UIREGISTER (mepdf); 743 743 744 //!\brief Chain rule of pdfs - abstract part common for mprod and merger. 745 //!this abstract class is common to epdf and mpdf 746 //!\todo Think of better design - global functions rv=get_rv(Array<mpdf*> mpdfs); ?? 747 class compositepdf 748 { 749 protected: 750 //! Elements of composition 751 Array<mpdf*> mpdfs; 752 bool owning_mpdfs; 753 public: 754 compositepdf() : mpdfs (0) {}; 755 compositepdf (Array<mpdf*> A0, bool own = false) { 756 set_elements (A0, own); 757 }; 758 void set_elements (Array<mpdf*> A0, bool own = false) { 759 mpdfs = A0; 760 owning_mpdfs = own; 761 }; 762 //! find common rv, flag \param checkoverlap modifies whether overlaps are acceptable 763 RV getrv (bool checkoverlap = false); 764 //! common rvc of all mpdfs is written to rvc 765 void setrvc (const RV &rv, RV &rvc); 766 ~compositepdf() { 767 if (owning_mpdfs) for (int i = 0; i < mpdfs.length(); i++) { 768 delete mpdfs (i); 769 } 770 }; 771 }; 744 //! \brief Combines RVs from a list of mpdfs to a single one. 745 RV get_composite_rv ( const Array<shared_ptr<mpdf> > &mpdfs, bool checkoverlap = false ); 772 746 773 747 /*! \brief Abstract class for discrete-time sources of data. -
library/bdm/stat/emix.cpp
r504 r507 202 202 return aprgiw; 203 203 }; 204 205 void mprod::set_elements (const Array<shared_ptr<mpdf> > &mFacs ) { 206 mpdfs = mFacs; 207 dls.set_size ( mFacs.length() ); 208 209 set_ep ( iepdf); 210 RV rv = get_composite_rv ( mpdfs, true ); 211 set_rv ( rv ); 212 iepdf.set_parameters ( rv._dsize() ); 213 214 for ( int i = 0; i < mpdfs.length(); i++ ) { 215 RV rvx = mpdfs ( i )->_rvc().subt ( rv ); 216 rvc.add ( rvx ); // add rv to common rvc 217 } 218 219 // rv and rvc established = > we can link them with mpdfs 220 for ( int i = 0; i < mpdfs.length(); i++ ) { 221 dls ( i ) = new datalink_m2m; 222 dls ( i )->set_connection ( mpdfs ( i )->_rv(), mpdfs ( i )->_rvc(), _rv(), _rvc() ); 223 } 224 } 204 225 205 226 vec mmix::samplecond(const vec &cond) { -
library/bdm/stat/emix.h
r504 r507 270 270 Note that 271 271 */ 272 class mprod: public compositepdf, public mpdf { 272 class mprod: public mpdf { 273 private: 274 Array<shared_ptr<mpdf> > mpdfs; 275 273 276 protected: 274 277 //! Data link for each mpdfs … … 279 282 280 283 public: 281 /*!\brief Constructor from list of mFacs, 284 //! \brief Default constructor 285 mprod() { } 286 287 /*!\brief Constructor from list of mFacs 282 288 */ 283 mprod() : iepdf( ) { } 284 mprod ( Array<mpdf*> mFacs ) : 285 iepdf ( ) { 289 mprod ( const Array<shared_ptr<mpdf> > &mFacs ) { 286 290 set_elements ( mFacs ); 287 291 } 288 292 289 void set_elements ( Array<mpdf*> mFacs , bool own = false ) { 290 291 compositepdf::set_elements ( mFacs, own ); 292 dls.set_size ( mFacs.length() ); 293 294 set_ep ( iepdf); 295 RV rv = getrv ( true ); 296 set_rv ( rv ); 297 iepdf.set_parameters ( rv._dsize() ); 298 setrvc (_rv(), rvc ); 299 // rv and rvc established = > we can link them with mpdfs 300 for ( int i = 0; i < mpdfs.length(); i++ ) { 301 dls ( i ) = new datalink_m2m; 302 dls ( i )->set_connection ( mpdfs ( i )->_rv(), mpdfs ( i )->_rvc(), _rv(), _rvc() ); 303 } 304 305 }; 293 void set_elements (const Array<shared_ptr<mpdf> > &mFacs ); 306 294 307 295 double evallogcond ( const vec &val, const vec &cond ) { … … 359 347 } 360 348 361 ~mprod() {};362 349 //! Load from structure with elements: 363 350 //! \code … … 368 355 //!@} 369 356 void from_setting ( const Setting &set ) { 370 Array<mpdf*> Atmp; //temporary Array 371 UI::get ( Atmp, set, "mpdfs", UI::compulsory ); 372 set_elements ( Atmp, true ); 357 Array<mpdf*> atmp; //temporary Array 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 ); 373 366 } 374 367 -
library/bdm/stat/merger.cpp
r504 r507 5 5 namespace bdm { 6 6 7 merger_base::merger_base ( const Array<mpdf*> &S, bool own ) { 8 DBG = false; 9 dbg_file = NULL; 10 set_sources ( S, own ); 7 merger_base::merger_base ( const Array<shared_ptr<mpdf> > &S ): 8 Npoints(0), DBG(false), dbg_file(0) { 9 set_sources ( S ); 11 10 } 12 11 -
library/bdm/stat/merger.h
r488 r507 42 42 */ 43 43 44 class merger_base : public compositepdf, publicepdf {44 class merger_base : public epdf { 45 45 protected: 46 //! Elements of composition 47 Array<shared_ptr<mpdf> > mpdfs; 48 46 49 //! Data link for each mpdf in mpdfs 47 50 Array<datalink_m2e*> dls; 51 48 52 //! Array of rvs that are not modelled by mpdfs at all, \f$ z_i \f$ 49 53 Array<RV> rvzs; 54 50 55 //! Data Links for extension \f$ f(z_i|x_i,y_i) \f$ 51 56 Array<datalink_m2e*> zdls; 57 52 58 //! number of support points 53 59 int Npoints; 60 54 61 //! number of sources 55 62 int Nsources; … … 77 84 //! @{ 78 85 79 //!Empty constructor 80 merger_base () : compositepdf() { 81 DBG = false; 82 dbg_file = NULL; 86 //! Default constructor 87 merger_base () : Npoints(0), Nsources(0), DBG(false), dbg_file(0) { 83 88 } 84 89 85 90 //!Constructor from sources 86 merger_base ( const Array< mpdf*> &S, bool own = false);91 merger_base ( const Array<shared_ptr<mpdf> > &S ); 87 92 88 93 //! Function setting the main internal structures 89 void set_sources ( const Array< mpdf*> &Sources, bool own) {90 compositepdf::set_elements ( Sources, own );94 void set_sources ( const Array<shared_ptr<mpdf> > &Sources ) { 95 mpdfs = Sources; 91 96 Nsources = mpdfs.length(); 92 97 //set sizes … … 95 100 zdls.set_size ( Sources.length() ); 96 101 97 rv = getrv ( /* checkoverlap = */ false ); 102 rv = get_composite_rv ( mpdfs, /* checkoverlap = */ false ); 103 98 104 RV rvc; 99 setrvc ( rv, rvc ); // Extend rv by rvc! 105 // Extend rv by rvc! 106 for ( int i = 0; i < mpdfs.length(); i++ ) { 107 RV rvx = mpdfs ( i )->_rvc().subt ( rv ); 108 rvc.add ( rvx ); // add rv to common rvc 109 } 110 100 111 // join rv and rvc - see descriprion 101 112 rv.add ( rvc ); … … 325 336 //!\name Constructors 326 337 //!@{ 327 merger_mix () {}; 328 merger_mix ( const Array<mpdf*> &S, bool own = false ) { 329 set_sources ( S, own ); 330 }; 338 merger_mix ():Ncoms(0), effss_coef(0), stop_niter(0) { } 339 340 merger_mix ( const Array<shared_ptr<mpdf> > &S ): 341 Ncoms(0), effss_coef(0), stop_niter(0) { 342 set_sources ( S ); 343 } 344 331 345 //! Set sources and prepare all internal structures 332 void set_sources ( const Array< mpdf*> &S, bool own) {333 merger_base::set_sources ( S , own);346 void set_sources ( const Array<shared_ptr<mpdf> > &S ) { 347 merger_base::set_sources ( S ); 334 348 Nsources = S.length(); 335 349 } 350 336 351 //! Set internal parameters used in approximation 337 352 void set_parameters ( int Ncoms0 = DFLT_Ncoms, double effss_coef0 = DFLT_effss_coef ) { -
library/tests/epdf_harness.cpp
r502 r507 68 68 shared_ptr<epdf> m = hepdf->marginal ( *mrv ); 69 69 shared_ptr<mpdf> c = hepdf->condition ( crv ); 70 mepdf mm ( m ); 71 72 Array<mpdf *> aa ( 2 ); 73 aa ( 0 ) = c.get(); 74 aa ( 1 ) = &mm; 70 71 Array<shared_ptr<mpdf> > aa ( 2 ); 72 aa ( 0 ) = c; 73 aa ( 1 ) = new mepdf ( m ); 75 74 mprod mEp ( aa ); 76 75 -
library/tests/merger_2d_test.cpp
r504 r507 21 21 xy.add ( y ); 22 22 23 enorm<fsqmat> f1;24 f1 .set_rv ( xy );25 enorm<fsqmat> f2;26 f 1.set_rv ( xy );23 shared_ptr<enorm<fsqmat> > f1 = new enorm<fsqmat>(); 24 f1->set_rv ( xy ); 25 shared_ptr<enorm<fsqmat> > f2 = new enorm<fsqmat>(); 26 f2->set_rv ( xy ); 27 27 28 28 mat R1 ( "0.5 0.48; 0.48 0.5" ); 29 29 mat R2 ( "0.5 0; 0 0.1" ); 30 f1 .set_parameters ( "1 1", R1 );31 f2 .set_parameters ( "1 1", mat ( "0.5 0; 0 0.1" ) );30 f1->set_parameters ( "1 1", R1 ); 31 f2->set_parameters ( "1 1", mat ( "0.5 0; 0 0.1" ) ); 32 32 33 Array< mpdf*> A ( 2 );34 mepdf A1 ( &f1 );35 mepdf A2 ( &f2 );36 A ( 0 ) = &A1;37 A ( 1 ) = &A2;33 Array<shared_ptr<mpdf> > A ( 2 ); 34 shared_ptr<mepdf> A1 = new mepdf ( f1 ); 35 shared_ptr<mepdf> A2 = new mepdf ( f2 ); 36 A ( 0 ) = A1; 37 A ( 1 ) = A2; 38 38 39 39 int Npoints = 100; … … 68 68 it << Name ( "Res1" ) << Res1; 69 69 it << Name ( "Res2" ) << Res2; 70 it << Name ( "S1" ) << f1 .evallog_m ( Grid );71 it << Name ( "S2" ) << f2 .evallog_m ( Grid );70 it << Name ( "S1" ) << f1->evallog_m ( Grid ); 71 it << Name ( "S2" ) << f2->evallog_m ( Grid ); 72 72 cout << ( ( enorm<ldmat>* ) ( MP->_Coms ( 0 ).get() ) )->_R().to_mat() << endl; 73 73 } -
library/tests/merger_iter_test.cpp
r477 r507 21 21 xy.add ( y ); 22 22 23 enorm<fsqmat> f1;24 f1 .set_rv ( xy );25 enorm<fsqmat> f2;26 f2 .set_rv ( xy );27 enorm<fsqmat> f3;28 f3 .set_rv ( y );23 shared_ptr<enorm<fsqmat> > f1 = new enorm<fsqmat>(); 24 f1->set_rv ( xy ); 25 shared_ptr<enorm<fsqmat> > f2 = new enorm<fsqmat>(); 26 f2->set_rv ( xy ); 27 shared_ptr<enorm<fsqmat> > f3 = new enorm<fsqmat>(); 28 f3->set_rv ( y ); 29 29 30 f1 .set_parameters ( "4 3", mat ( "0.4 0.3; 0.3 0.4" ) );31 f2 .set_parameters ( "1 3", mat ( "0.3 -0.2; -0.2 0.3" ) );32 f3 .set_parameters ( "2", mat ( "0.4" ) );30 f1->set_parameters ( "4 3", mat ( "0.4 0.3; 0.3 0.4" ) ); 31 f2->set_parameters ( "1 3", mat ( "0.3 -0.2; -0.2 0.3" ) ); 32 f3->set_parameters ( "2", mat ( "0.4" ) ); 33 33 34 Array<mpdf* > A ( 3 ); 35 mepdf A1 ( &f1 ); 36 mepdf A2 ( &f2 ); 37 mepdf A3 ( &f3 ); 38 A ( 0 ) = &A1; 39 A ( 1 ) = &A2; 40 A ( 2 ) = &A3; 34 Array<shared_ptr<mpdf> > A ( 3 ); 35 A ( 0 ) = new mepdf ( f1 ); 36 A ( 1 ) = new mepdf ( f2 ); 37 A ( 2 ) = new mepdf ( f3 ); 41 38 42 39 int Npoints = 100; -
library/tests/merger_test.cpp
r506 r507 7 7 8 8 using namespace bdm; 9 10 //These lines are needed for use of cout and endl11 using std::cout;12 using std::endl;13 9 14 10 TEST ( test_merger_basic ) { … … 25 21 f2->set_parameters ( "5", mat ( "10" ) ); 26 22 27 Array<mpdf* > A ( 2 ); 28 mepdf A1 ( f1 ); 29 mepdf A2 ( f2 ); 30 A ( 0 ) = &A1; 31 A ( 1 ) = &A2; 23 Array<shared_ptr<mpdf> > A ( 2 ); 24 A ( 0 ) = new mepdf ( f1 ); 25 A ( 1 ) = new mepdf ( f2 ); 32 26 33 27 int Npoints = 100; -
library/tests/testSmp.cpp
r504 r507 106 106 eG->set_rv ( y ); 107 107 //create array 108 Array<mpdf*> A ( 2 ); 109 mepdf meN ( eN.get() ); 110 mepdf meG ( eG.get() ); 111 A ( 0 ) = &meN; 112 A ( 1 ) = &meG; 108 Array<shared_ptr<mpdf> > A ( 2 ); 109 A ( 0 ) = new mepdf ( eN ); 110 A ( 1 ) = new mepdf ( eG ); 113 111 114 112 mprod eP ( A );