Changeset 1063
- Timestamp:
- 06/09/10 11:50:16 (15 years ago)
- Location:
- library
- Files:
-
- 8 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.h
r1060 r1063 570 570 571 571 This macro has to be called within a class declaration. Its argument \a classname has to correspond to that wrapping class. 572 This macro defines a log_level instance which can be modified either directly or by the means of # UI class.572 This macro defines a log_level instance which can be modified either directly or by the means of #bdm::UI class. 573 573 574 574 One of the main purposes of this macro is to allow variability in using enumerations. By relating them to their names through … … 736 736 //! log upper bound of the density (see function qbounds) 737 737 738 //! \var log_level_enums logfull739 //! log full record of the density in the form of setting740 738 LOG_LEVEL(epdf,logmean,loglbound,logubound); 741 739 … … 801 799 //! Set statistics to match given input epdf. Typically it copies statistics from epdf of the same type and projects those form different types 802 800 //! \param pdf0 epdf to match 803 //! \param option placeholder for potential options804 801 void set_statistics(const epdf *pdf0) NOT_IMPLEMENTED_VOID; 805 802 //!@} … … 1309 1306 1310 1307 /*! \brief Incremental Bayes rule 1311 @param dt vector of input data1308 @param yt vector of input data 1312 1309 */ 1313 1310 virtual void bayes ( const vec &yt, const vec &cond = empty_vec ) =0; -
library/bdm/base/datasources.h
r1060 r1063 269 269 class = 'PdfDS'; 270 270 pdf = configuration of bdm::pdf; % any offspring of pdf, bdm::pdf::from_setting 271 --- optional ---271 --- optional fields --- 272 272 init_rv = RV({'names',...},[sizes,...],[times,...]); % define what rv to initialize - typically delayed values, time=-1, etc.! 273 273 init_values = [...]; % vector of initial values corresponding to init_rv 274 274 \endcode 275 Class does not inheritsfrom bdm::DS::from_setting, names of data are taken from pdf.rv and pdf.rvc.275 Class does not call from bdm::DS::from_setting, names of data are taken from pdf.rv and pdf.rvc. 276 276 277 277 If init_rv is not given, init_values are set to zero. -
library/bdm/base/user_info.h
r1015 r1063 395 395 //! The new instance of type T* is constructed and initialized with values stored in the Setting element[name] 396 396 //! 397 //! If there does not exist any sub-element named #name and settingPresence is #optional, an empty bdm::shared_ptr<T> is returned. When settingPresence is #compulsory, the returned bdm::shared_ptr<T> is never empty (an exception is thrown when the object isn't found). 397 //! If there does not exist any sub-element named name and settingPresence is optional, an empty bdm::shared_ptr<T> is returned. 398 //! When settingPresence is compulsory, the returned bdm::shared_ptr<T> is never empty (an exception is thrown when the object isn't found). 398 399 template<class T> 399 400 static bdm::shared_ptr<T> build ( const Setting &element, const string &name, SettingPresence settingPresence = optional ) { … … 412 413 //! The new instance of type T* is constructed and initialized with values stored in the Setting element[index] 413 414 //! 414 //! If there does not exist any sub-element indexed by #index, and settingPresence is #optional, an empty bdm::shared_ptr<T> is returned. When settingPresence is #compulsory, the returned bdm::shared_ptr<T> is never empty (an exception is thrown when the object isn't found). 415 //! If there does not exist any sub-element indexed by index, and settingPresence is optional, an empty bdm::shared_ptr<T> is returned. 416 //! When settingPresence is compulsory, the returned bdm::shared_ptr<T> is never empty (an exception is thrown when the object isn't found). 415 417 template<class T> 416 418 static bdm::shared_ptr<T> build ( const Setting &element, const int index, SettingPresence settingPresence = optional ) { … … 447 449 448 450 //! The existing instance of type T is initialized with values stored in the Setting element[name] 449 //! If there does not exist any sub-element named #name, this method returns false.451 //! If there does not exist any sub-element named name, this method returns false. 450 452 template<class T> static bool get ( T &instance, const Setting &element, const string &name, SettingPresence settingPresence = optional ) { 451 453 if ( !element.exists ( name ) ) { … … 461 463 462 464 //! The existing instance of type T is initialized with values stored in the Setting element[index] 463 //! If there does not exist any sub-element indexed by #index, this method returns false.465 //! If there does not exist any sub-element indexed by index, this method returns false. 464 466 template<class T> static bool get ( T &instance, const Setting &element, const int index, SettingPresence settingPresence = optional ) { 465 467 if ( element.getLength() <= index ) { … … 490 492 491 493 //! The existing array of type T is initialized with values stored in the Setting element[name] 492 //! If there is not any sub-element named #name, this method returns false.494 //! If there is not any sub-element named name, this method returns false. 493 495 template<class T> static bool get ( Array<T> &array_to_load, const Setting &element, const string &name, SettingPresence settingPresence = optional ) { 494 496 if ( !element.exists ( name ) ) { … … 504 506 505 507 //! The existing array of type T is initialized with values stored in the Setting element[index] 506 //! If there is not any sub-element indexed by #index, this method returns false.508 //! If there is not any sub-element indexed by index, this method returns false. 507 509 template<class T> static bool get ( Array<T> &array_to_load, const Setting &element, const int index, SettingPresence settingPresence = optional ) { 508 510 if ( element.getLength() <= index ) { -
library/bdm/estim/arx.h
r1036 r1063 229 229 230 230 231 /*! 232 * \brief ARX with partial forgetting 231 /*! \brief ARX with partial forgetting 233 232 234 233 Implements partial forgetting when <tt>bayes(const vec &yt, const vec &cond=empty_vec)</tt> is called, where \c cond is a vector <em>(regressor', forg.factor')</em>. … … 261 260 262 261 void bayes ( const vec &val, const vec &cond ); 262 263 263 void validate() { 264 264 ARX::validate(); -
library/bdm/estim/particles.h
r1033 r1063 223 223 224 224 class PF : public BM { 225 //! \var log_level_enums weights225 //! \var log_level_enums logweights 226 226 //! all weightes will be logged 227 227 228 //! \var log_level_enums menas228 //! \var log_level_enums logmeans 229 229 //! means of particles will be logged 230 230 LOG_LEVEL(PF,logweights,logmeans,logvars); -
library/bdm/stat/exp_family.cpp
r1033 r1063 438 438 439 439 void egamma::from_setting ( const Setting &set ) { 440 441 442 443 440 epdf::from_setting ( set ); // reads rv 441 UI::get ( alpha, set, "alpha", UI::compulsory ); 442 UI::get ( beta, set, "beta", UI::compulsory ); 443 } 444 444 445 445 void egamma::to_setting ( Setting &set ) const … … 675 675 676 676 void eEmp::from_setting ( const Setting &set ) { 677 677 epdf::from_setting( set ); 678 678 679 UI::get( samples, set, "samples", UI::compulsory ); 680 UI::get ( w, set, "w", UI::compulsory ); 681 } 682 683 void eEmp::validate (){ 684 epdf::validate(); 685 bdm_assert (samples.length()==w.length(),"samples and weigths are of different lengths"); 686 n = w.length(); 687 if (n>0) 688 pdf::dim = samples ( 0 ).length(); 689 } 690 691 void eDirich::from_setting ( const Setting &set ) { 692 epdf::from_setting ( set ); 693 UI::get ( beta, set, "beta", UI::compulsory ); 694 } 679 UI::get( samples, set, "samples", UI::compulsory ); 680 UI::get ( w, set, "w", UI::compulsory ); 681 } 682 683 void eEmp::validate (){ 684 epdf::validate(); 685 bdm_assert (samples.length()==w.length(),"samples and weigths are of different lengths"); 686 n = w.length(); 687 if (n>0) 688 pdf::dim = samples ( 0 ).length(); 689 } 690 691 void eDirich::from_setting ( const Setting &set ) { 692 epdf::from_setting ( set ); 693 UI::get ( beta, set, "beta", UI::compulsory ); 694 } 695 695 696 void eDirich::validate() { 696 697 //check rv -
library/bdm/stat/exp_family.h
r1058 r1063 30 30 31 31 /*! 32 * \brief General conjugate exponential family posterior density.32 * \brief Abstract class of general conjugate exponential family posterior density. 33 33 34 34 * More?... 35 35 */ 36 37 36 class eEF : public epdf { 38 37 public: … … 540 539 return beta; 541 540 } 542 /*! configuration structure 541 542 /*! Create object from the following structure 543 543 \code 544 544 class = 'eDirich'; 545 beta = []; //parametr beta 545 beta = [...]; % vector parameter beta 546 --- inherited fields --- 547 bdm::eEF::from_setting 546 548 \endcode 547 549 */ 548 550 void from_setting ( const Setting &set ); 551 549 552 void validate(); 553 550 554 void to_setting ( Setting &set ) const; 551 555 }; 552 556 UIREGISTER ( eDirich ); 553 557 554 /*! Product of Beta distributions558 /*! \brief Product of Beta distributions 555 559 556 560 Continuous Dirichlet density of \f$n\f$-dimensional variable \f$x\f$ … … 567 571 vec beta; 568 572 public: 569 570 573 //!\name Constructors 574 //!@{ 571 575 572 573 574 575 576 576 eBeta () : eEF () {}; 577 eBeta ( const eBeta &B0 ) : eEF (), alpha(B0.alpha),beta(B0.beta) { 578 validate(); 579 }; 580 //!@} 577 581 578 579 580 581 582 583 584 582 //! using sampling procedure from wikipedia 583 vec sample() const { 584 vec y ( beta.length() ); // all vectors 585 for ( int i = 0; i < beta.length(); i++ ) { 586 GamRNG.setup ( alpha ( i ), 1 ); 587 #pragma omp critical 588 double Ga = GamRNG(); 585 589 586 587 588 590 GamRNG.setup ( beta ( i ), 1 ); 591 #pragma omp critical 592 double Gb = GamRNG(); 589 593 590 591 592 593 594 y ( i ) = Ga/(Ga+Gb); 595 } 596 return y; 597 } 594 598 595 596 597 598 599 600 601 602 603 604 605 606 607 608 599 vec mean() const { 600 return elem_div(alpha, alpha + beta); // dot-division 601 }; 602 vec variance() const { 603 vec apb=alpha+beta; 604 return elem_div (elem_mult ( alpha, beta) , 605 elem_mult ( elem_mult(apb,apb), apb+1 ) ); 606 } 607 //! In this instance, val is ... 608 double evallog_nn ( const vec &val ) const { 609 double tmp; 610 tmp = ( alpha - 1 ) * log ( val ) + (beta-1)*log(1-val); 611 return tmp; 612 } 609 613 610 611 612 613 614 615 616 614 double lognc () const { 615 double lgb = 0.0; 616 for ( int i = 0; i < beta.length(); i++ ) { 617 lgb += -lgamma ( alpha(i)+beta(i) ) + lgamma(alpha(i)) + lgamma(beta(i)); 618 } 619 return lgb; 620 } 617 621 618 /*! configuration structure 619 \code 620 class = 'eBeta'; 621 beta = []; //parametr beta 622 alpha = []; //parametr alpha 623 \endcode 624 */ 625 void from_setting ( const Setting &set ){ 626 UI::get(alpha, set, "alpha", UI::compulsory); 627 UI::get(beta, set, "beta", UI::compulsory); 628 } 629 void validate(){ 630 bdm_assert(alpha.length()==beta.length(), "eBeta:: alpha and beta length do not match"); 631 dim = alpha.length(); 632 }; 633 void to_setting ( Setting &set ) const{ 634 UI::save(alpha, set, "alpha"); 635 UI::save(beta, set, "beta"); 636 } 622 /*! Create object from the following structure 623 624 \code 625 class = 'eBeta'; 626 alpha = [...]; % vector parameter alpha 627 beta = [...]; % vector parameter beta of the same length as alpha 628 \endcode 629 630 Class does not call bdm::eEF::from_setting 631 */ 632 void from_setting ( const Setting &set ){ 633 UI::get(alpha, set, "alpha", UI::compulsory); 634 UI::get(beta, set, "beta", UI::compulsory); 635 } 636 637 void validate(){ 638 bdm_assert(alpha.length()==beta.length(), "eBeta:: alpha and beta length do not match"); 639 dim = alpha.length(); 640 } 641 642 void to_setting ( Setting &set ) const{ 643 UI::save(alpha, set, "alpha"); 644 UI::save(beta, set, "beta"); 645 } 637 646 }; 638 647 UIREGISTER ( eBeta ); … … 682 691 /*! \brief Random Walk with vector Beta distribution 683 692 Using simple assignment 684 \f{eqnarray }685 \alpha & =& rvc / k + \beta_c \\686 \beta & = &(1-rvc) / k + \beta_c \\687 \f {eqnarray}693 \f{eqnarray*} 694 \alpha & = & rvc / k + \beta_c \\ 695 \beta & = &(1-rvc) / k + \beta_c \\ 696 \f} 688 697 for each element of alpha and beta, mean value = rvc, variance = (k+1)*mean*mean; 689 698 … … 693 702 By default is it set to 0.1; 694 703 */ 695 696 704 class mBeta: public pdf_internal<eBeta>{ 697 705 //! vector of constants \f$ k \f$ of the random walk … … 701 709 702 710 public: 703 void condition ( const vec &val ) { 704 this->iepdf.alpha = elem_div(val , k) + betac; 705 this->iepdf.beta = elem_div (1-val , k) + betac; 706 }; 707 /*! Create Beta random walk 708 \f[ f(rv|rvc) = \prod Beta(rvc,k) \f] 709 from structure 710 \code 711 class = 'mBeta'; 712 k = 1; // multiplicative constant k 713 --- optional --- 714 rv = RV({'name'},size) // description of RV 715 beta = []; // initial value of beta 716 betac = []; // initial value of beta stabilizing constant 717 \endcode 718 */ 719 void from_setting ( const Setting &set ); 720 void to_setting (Setting &set) const; 721 void validate(){ 722 723 pdf_internal<eBeta>::validate(); 724 bdm_assert(betac.length()==dimension(),"Incomaptible betac"); 725 bdm_assert(k.length()==dimension(),"Incomaptible k"); 726 dimc = iepdf.dimension(); 727 } 728 //! 711 void condition ( const vec &val ) { 712 this->iepdf.alpha = elem_div(val , k) + betac; 713 this->iepdf.beta = elem_div (1-val , k) + betac; 714 }; 715 716 /*! Create Beta random walk 717 \f[ f(rv|rvc) = \prod Beta(rvc,k) \f] 718 from structure 719 \code 720 class = 'mBeta'; 721 k = 1; // multiplicative constant k 722 --- optional --- 723 rv = RV({'name'},size) // description of RV 724 beta = []; // initial value of beta 725 betac = []; // initial value of beta stabilizing constant 726 \endcode 727 */ 728 void from_setting ( const Setting &set ); 729 730 void to_setting (Setting &set) const; 731 732 void validate(){ 733 pdf_internal<eBeta>::validate(); 734 bdm_assert(betac.length()==dimension(),"Incomaptible betac"); 735 bdm_assert(k.length()==dimension(),"Incomaptible k"); 736 dimc = iepdf.dimension(); 737 } 738 //! 729 739 }; 730 740 UIREGISTER(mBeta); … … 829 839 } 830 840 831 /*! Create Gamma density 832 \f[ f(rv|rvc) = \Gamma(\alpha, \beta) \f] 833 from structure 841 /*! Create object from the following structure 842 834 843 \code 835 844 class = 'egamma'; 836 alpha = [...]; // vector of alpha 837 beta = [...]; // vector of beta 838 rv = RV({'name'}) // description of RV 845 alpha = [...]; % vector of alpha 846 beta = [...]; % vector of beta 847 --- inherited fields --- 848 bdm::eEF::from_setting 839 849 \endcode 850 fulfilling formula \f[ f(rv|rvc) = \Gamma(\alpha, \beta) \f] 840 851 */ 841 852 void from_setting ( const Setting &set ); 853 842 854 void to_setting ( Setting &set ) const; 843 855 void validate(); … … 1682 1694 void resample(const vec &w, ivec &ind, RESAMPLING_METHOD=SYSTEMATIC); 1683 1695 1684 /*! 1685 \brief Weighted empirical density 1696 /*! \brief Weighted empirical density 1686 1697 1687 1698 Used e.g. in particle filters. … … 1771 1782 1772 1783 void to_setting ( Setting &set ) const; 1784 1785 /*! Create object from the following structure 1786 1787 \code 1788 class = 'eEmp'; 1789 samples = [...]; % array of samples 1790 w = [...]; % weights of samples stored in vector 1791 --- inherited fields --- 1792 bdm::epdf::from_setting 1793 \endcode 1794 */ 1773 1795 void from_setting ( const Setting &set ); 1774 1775 1796 }; 1776 1797 UIREGISTER(eEmp); … … 1945 1966 } 1946 1967 1947 /*! Dirac delta function distribution */1968 /*! \brief Dirac delta function distribution */ 1948 1969 class dirac: public epdf{ 1949 1970 public: … … 1960 1981 }; 1961 1982 1962 //// 1963 /////// 1983 1984 /////////// 1985 1964 1986 template<class sq_T> 1965 1987 void mgnorm<sq_T >::set_parameters ( const shared_ptr<fnc> &g0, const sq_T &R0 ) { -
library/doc/tutorial/kalman.dox
r661 r1063 38 38 \section exa Examples of Use 39 39 40 The classes can be used directly in C++ or via User Info. The latter example is illustrated in file \subpage u ser_guide2. A very short example of the former follows:40 The classes can be used directly in C++ or via User Info. The latter example is illustrated in file \subpage ui. A very short example of the former follows: 41 41 42 42 \include kalman_simple.cpp