Changeset 957
- Timestamp:
- 05/19/10 05:31:37 (15 years ago)
- Location:
- library/bdm/stat
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/stat/exp_family.cpp
r956 r957 613 613 migamma::from_setting(set); 614 614 vec ref; 615 double k,l; 616 615 617 UI::get ( ref, set, "ref" , UI::compulsory ); 616 set_parameters ( set["k"], ref, set["l"] ); 617 validate(); 618 } 618 UI::get( k, set, "k", UI::compulsory ); 619 UI::get( l, set, "l", UI::compulsory ); 620 set_parameters ( k, ref, l ); 621 } 622 619 623 void migamma_ref::to_setting (Setting &set) const { 620 624 migamma::to_setting(set); … … 623 627 UI::save(k,set,"k"); 624 628 } 629 625 630 void mlognorm::from_setting ( const Setting &set ) { 626 631 pdf_internal<elognorm>::from_setting(set); 627 632 vec mu0; 633 double k; 628 634 UI::get ( mu0, set, "mu0", UI::compulsory ); 629 set_parameters ( mu0.length(), set["k"] ); 635 UI::get( k, set, "k", UI::compulsory ); 636 set_parameters ( mu0.length(), k ); 630 637 condition ( mu0 ); 631 638 } 632 633 639 634 640 void mlognorm::to_setting (Setting &set) const { 635 641 pdf_internal<elognorm>::to_setting(set); 636 642 UI::save ( exp(mu + sig2), set, "mu0"); 643 644 // inversion of sig2 = 0.5 * log ( k * k + 1 ); 645 double k = sqrt( exp( 2 * sig2 ) - 1 ); 646 UI::save(k,set,"k"); 637 647 } 638 648 -
library/bdm/stat/exp_family.h
r956 r957 1253 1253 */ 1254 1254 void from_setting ( const Setting &set ); 1255 1255 1256 void to_setting (Setting &set) const; 1256 // TODO dodelat void to_setting( Setting &set ) const;1257 1257 }; 1258 1258 … … 1330 1330 */ 1331 1331 void from_setting ( const Setting &set ); 1332 1332 1333 void to_setting (Setting &set) const; 1333 1334 // TODO dodelat void to_setting( Setting &set ) const;1335 1336 1334 }; 1337 1335 -
library/bdm/stat/merger.cpp
r956 r957 350 350 351 351 void merger_mix::from_setting ( const Setting& set ) { 352 merger_base::from_setting ( set ); 353 Ncoms=DFLT_Ncoms; 354 UI::get( Ncoms, set, "ncoms", UI::optional ); 355 effss_coef=DFLT_effss_coef; 356 UI::get (effss_coef , set, "effss_coef", UI::optional); 357 stop_niter=10; 358 UI::get ( stop_niter, set,"stop_niter", UI::optional ); 352 merger_base::from_setting ( set ); 353 Ncoms=DFLT_Ncoms; 354 UI::get( Ncoms, set, "ncoms", UI::optional ); 355 effss_coef=DFLT_effss_coef; 356 UI::get (effss_coef , set, "effss_coef", UI::optional); 357 stop_niter=10; 358 UI::get ( stop_niter, set,"stop_niter", UI::optional ); 359 } 360 361 void merger_mix::to_setting (Setting &set) const { 362 merger_base::to_setting(set); 363 UI::save( Ncoms, set, "ncoms"); 364 UI::save (effss_coef , set, "effss_coef"); 365 UI::save ( stop_niter, set,"stop_niter"); 366 } 367 368 void merger_mix::validate() { 369 merger_base::validate(); 370 bdm_assert(Ncoms>0,"Ncoms too small"); 371 } 372 373 void merger_base::from_setting ( const Setting& set ) { 374 // get support 375 // find which method to use 376 epdf::from_setting (set); 377 string meth_str; 378 UI::get( meth_str, set, "method", UI::compulsory ); 379 if ( meth_str == "arithmetic" ) 380 set_method ( ARITHMETIC ); 381 else if ( meth_str == "geometric" ) 382 set_method ( GEOMETRIC ); 383 else if ( meth_str == "lognormal" ) { 384 set_method ( LOGNORMAL ); 385 UI::get(beta, set, "beta", UI::compulsory ); 386 } 359 387 360 } 361 362 void merger_mix::to_setting (Setting &set) const { 363 merger_base::to_setting(set); 364 UI::save( Ncoms, set, "ncoms"); 365 UI::save (effss_coef , set, "effss_coef"); 366 UI::save ( stop_niter, set,"stop_niter"); 367 368 } 369 370 void merger_mix::validate() { 371 merger_base::validate(); 372 bdm_assert(Ncoms>0,"Ncoms too small"); 373 } 374 375 void merger_base::from_setting ( const Setting& set ) { 376 // get support 377 // find which method to use 378 epdf::from_setting (set); 379 string meth_str; 380 UI::get<string> ( meth_str, set, "method", UI::compulsory ); 381 if ( !strcmp ( meth_str.c_str(), "arithmetic" ) ) 382 set_method ( ARITHMETIC ); 383 else { 384 if ( !strcmp ( meth_str.c_str(), "geometric" ) ) 385 set_method ( GEOMETRIC ); 386 else if ( !strcmp ( meth_str.c_str(), "lognormal" ) ) { 387 set_method ( LOGNORMAL ); 388 set.lookupValue ( "beta", beta ); 389 } 390 } 391 string dbg_file; 392 if ( UI::get ( dbg_file, set, "dbg_file" ) ) 393 set_debug_file ( dbg_file ); 394 //validate() - not used 395 } 396 397 void merger_base::to_setting (Setting &set) const { 398 epdf::to_setting(set); 388 389 string dbg_filename; 390 if ( UI::get ( dbg_filename, set, "dbg_file" ) ) 391 set_debug_file( dbg_filename ); 392 393 } 394 395 void merger_base::to_setting (Setting &set) const { 396 epdf::to_setting(set); 399 397 400 UI::save( METHOD, set, "method"); 398 UI::save( METHOD, set, "method"); 399 400 if( METHOD == LOGNORMAL ) 401 UI::save (beta, set, "beta" ); 402 403 if( DBG ) 401 404 UI::save ( dbg_file->get_fname(), set, "dbg_file" ); 402 UI::save (beta, set, "beta" ); 403 } 404 405 void merger_base::validate() { 405 } 406 407 void merger_base::validate() { 406 408 // bdm_assert ( eSmp._w().length() > 0, "Empty support, use set_support()." ); 407 409 // bdm_assert ( dim == eSmp._samples() ( 0 ).length(), "Support points and rv are not compatible!" ); 408 epdf::validate(); 409 bdm_assert ( isnamed(), "mergers must be named" ); 410 } 410 epdf::validate(); 411 bdm_assert ( isnamed(), "mergers must be named" ); 412 } 413 411 414 // DEFAULTS FOR MERGER_BASE 412 415 const MERGER_METHOD merger_base::DFLT_METHOD = LOGNORMAL; -
library/bdm/stat/merger.h
r956 r957 104 104 eSmp.validate(); 105 105 } 106 107 106 108 //! set debug file 107 109 void set_debug_file ( const string fname ) { 108 110 if ( DBG ) delete dbg_file; 109 111 dbg_file = new it_file ( fname ); 110 if ( dbg_file ) DBG = true; 111 } 112 DBG = ( dbg_file != 0 ); 113 } 114 112 115 //! Set internal parameters used in approximation 113 116 void set_method ( MERGER_METHOD MTH = DFLT_METHOD, double beta0 = DFLT_beta ) {