Changeset 1063 for library

Show
Ignore:
Timestamp:
06/09/10 11:50:16 (14 years ago)
Author:
mido
Message:

a small patch of documentation, to be contiuned..

Location:
library
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/base/bdmbase.h

    r1060 r1063  
    570570 
    571571  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. 
    573573 
    574574  One of the main purposes of this macro is to allow variability in using enumerations. By relating them to their names through 
     
    736736        //! log upper bound of the density (see function qbounds) 
    737737         
    738         //! \var log_level_enums logfull 
    739         //! log full record of the density in the form of setting 
    740738        LOG_LEVEL(epdf,logmean,loglbound,logubound); 
    741739 
     
    801799        //! Set statistics to match given input epdf. Typically it copies statistics from epdf of the same type and projects those form different types 
    802800        //! \param pdf0 epdf to match 
    803         //! \param option placeholder for potential options 
    804801        void set_statistics(const epdf *pdf0) NOT_IMPLEMENTED_VOID; 
    805802        //!@} 
     
    13091306 
    13101307        /*! \brief Incremental Bayes rule 
    1311         @param dt vector of input data 
     1308        @param yt vector of input data 
    13121309        */ 
    13131310        virtual void bayes ( const vec &yt, const vec &cond = empty_vec ) =0; 
  • library/bdm/base/datasources.h

    r1060 r1063  
    269269        class = 'PdfDS'; 
    270270        pdf = configuration of bdm::pdf;          % any offspring of pdf, bdm::pdf::from_setting 
    271         --- optional --- 
     271        --- optional fields --- 
    272272        init_rv = RV({'names',...},[sizes,...],[times,...]);   % define what rv to initialize - typically delayed values, time=-1, etc.! 
    273273        init_values = [...];                      % vector of initial values corresponding to init_rv 
    274274        \endcode 
    275         Class does not inherits from 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. 
    276276         
    277277        If init_rv is not given, init_values are set to zero. 
  • library/bdm/base/user_info.h

    r1015 r1063  
    395395        //! The new instance of type T* is constructed and initialized with values stored in the Setting element[name] 
    396396        //! 
    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). 
    398399        template<class T> 
    399400        static bdm::shared_ptr<T> build ( const Setting &element, const string &name, SettingPresence settingPresence = optional ) { 
     
    412413        //! The new instance of type T* is constructed and initialized with values stored in the Setting element[index] 
    413414        //! 
    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). 
    415417        template<class T> 
    416418        static bdm::shared_ptr<T> build ( const Setting &element, const int index, SettingPresence settingPresence = optional ) { 
     
    447449 
    448450        //! 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. 
    450452        template<class T> static bool get ( T &instance, const Setting &element, const string &name, SettingPresence settingPresence = optional ) { 
    451453                if ( !element.exists ( name ) ) { 
     
    461463 
    462464        //! 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. 
    464466        template<class T> static bool get ( T &instance, const Setting &element, const int index, SettingPresence settingPresence = optional ) { 
    465467                if ( element.getLength() <= index ) { 
     
    490492 
    491493        //! 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. 
    493495        template<class T> static bool get ( Array<T> &array_to_load, const Setting &element, const string &name, SettingPresence settingPresence = optional ) { 
    494496                if ( !element.exists ( name ) ) { 
     
    504506 
    505507        //! 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. 
    507509        template<class T> static bool get ( Array<T> &array_to_load, const Setting &element, const int index, SettingPresence settingPresence = optional ) { 
    508510                if ( element.getLength() <= index ) { 
  • library/bdm/estim/arx.h

    r1036 r1063  
    229229 
    230230 
    231 /*! 
    232 * \brief ARX with partial forgetting 
     231/*! \brief ARX with partial forgetting 
    233232 
    234233Implements 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>. 
     
    261260 
    262261    void bayes ( const vec &val, const vec &cond );  
     262 
    263263        void validate() { 
    264264                ARX::validate(); 
  • library/bdm/estim/particles.h

    r1033 r1063  
    223223 
    224224class PF : public BM { 
    225         //! \var log_level_enums weights 
     225        //! \var log_level_enums logweights 
    226226        //! all weightes will be logged 
    227227 
    228         //! \var log_level_enums menas 
     228        //! \var log_level_enums logmeans 
    229229        //! means of particles will be logged 
    230230        LOG_LEVEL(PF,logweights,logmeans,logvars); 
  • library/bdm/stat/exp_family.cpp

    r1033 r1063  
    438438 
    439439void egamma::from_setting ( const Setting &set ) { 
    440                 epdf::from_setting ( set ); // reads rv 
    441                 UI::get ( alpha, set, "alpha", UI::compulsory ); 
    442                 UI::get ( beta, set, "beta", UI::compulsory ); 
    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} 
    444444         
    445445void egamma::to_setting ( Setting &set ) const 
     
    675675 
    676676void eEmp::from_setting ( const Setting &set ) { 
    677                 epdf::from_setting( set ); 
     677        epdf::from_setting( set ); 
    678678                 
    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 
     683void 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         
     691void eDirich::from_setting ( const Setting &set ) { 
     692        epdf::from_setting ( set ); 
     693        UI::get ( beta, set, "beta", UI::compulsory ); 
     694} 
     695 
    695696void eDirich::validate() { 
    696697                //check rv 
  • library/bdm/stat/exp_family.h

    r1058 r1063  
    3030 
    3131/*! 
    32 * \brief General conjugate exponential family posterior density. 
     32* \brief Abstract class of general conjugate exponential family posterior density. 
    3333 
    3434* More?... 
    3535*/ 
    36  
    3736class eEF : public epdf { 
    3837public: 
     
    540539                return beta; 
    541540        } 
    542         /*! configuration structure 
     541 
     542        /*! Create object from the following structure 
    543543        \code 
    544544        class = 'eDirich'; 
    545         beta  = [];           //parametr beta 
     545        beta  = [...];           % vector parameter beta 
     546        --- inherited fields --- 
     547        bdm::eEF::from_setting 
    546548        \endcode 
    547549        */ 
    548550        void from_setting ( const Setting &set ); 
     551 
    549552        void validate(); 
     553 
    550554        void to_setting ( Setting &set ) const; 
    551555}; 
    552556UIREGISTER ( eDirich ); 
    553557 
    554 /*! Product of Beta distributions 
     558/*! \brief Product of Beta distributions 
    555559 
    556560Continuous Dirichlet density of \f$n\f$-dimensional variable \f$x\f$ 
     
    567571                vec beta; 
    568572        public: 
    569                 //!\name Constructors 
    570                 //!@{ 
     573        //!\name Constructors 
     574        //!@{ 
    571575                         
    572                         eBeta () : eEF () {}; 
    573                         eBeta ( const eBeta &B0 ) : eEF (), alpha(B0.alpha),beta(B0.beta) { 
    574                                 validate(); 
    575                         }; 
    576                         //!@} 
     576        eBeta () : eEF () {}; 
     577        eBeta ( const eBeta &B0 ) : eEF (), alpha(B0.alpha),beta(B0.beta) { 
     578                validate(); 
     579        }; 
     580        //!@} 
    577581                         
    578                         //! using sampling procedure from wikipedia 
    579                         vec sample() const { 
    580                                 vec y ( beta.length() ); // all vectors 
    581                                 for ( int i = 0; i < beta.length(); i++ ) { 
    582                                         GamRNG.setup ( alpha ( i ), 1 ); 
    583                                         #pragma omp critical 
    584                                         double Ga = GamRNG(); 
     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(); 
    585589                                         
    586                                         GamRNG.setup ( beta ( i ), 1 ); 
    587                                         #pragma omp critical 
    588                                         double Gb = GamRNG(); 
     590                        GamRNG.setup ( beta ( i ), 1 ); 
     591                        #pragma omp critical 
     592                        double Gb = GamRNG(); 
    589593                                         
    590                                         y ( i ) = Ga/(Ga+Gb); 
    591                                 } 
    592                                 return y; 
    593                         } 
     594                        y ( i ) = Ga/(Ga+Gb); 
     595                } 
     596                return y; 
     597        } 
    594598                         
    595                         vec mean() const { 
    596                                 return elem_div(alpha, alpha + beta); // dot-division 
    597                         }; 
    598                         vec variance() const { 
    599                                 vec apb=alpha+beta; 
    600                                 return elem_div (elem_mult ( alpha, beta) , 
    601                                                                  elem_mult ( elem_mult(apb,apb), apb+1 ) ); 
    602                         } 
    603                         //! In this instance, val is ... 
    604                         double evallog_nn ( const vec &val ) const { 
    605                                 double tmp; 
    606                                 tmp = ( alpha - 1 ) * log ( val ) + (beta-1)*log(1-val); 
    607                                 return tmp; 
    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        } 
    609613                         
    610                         double lognc () const { 
    611                                 double lgb = 0.0; 
    612                                 for ( int i = 0; i < beta.length(); i++ ) { 
    613                                         lgb += -lgamma ( alpha(i)+beta(i) ) + lgamma(alpha(i)) + lgamma(beta(i)); 
    614                                 } 
    615                                 return lgb; 
    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        } 
    617621                         
    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        } 
    637646}; 
    638647UIREGISTER ( eBeta ); 
     
    682691/*! \brief Random Walk with vector Beta distribution 
    683692Using 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} 
    688697for each element of alpha and beta, mean value = rvc, variance = (k+1)*mean*mean; 
    689698 
     
    693702By default is it set to 0.1; 
    694703*/ 
    695  
    696704class mBeta: public pdf_internal<eBeta>{ 
    697705        //! vector of constants \f$ k \f$ of the random walk  
     
    701709 
    702710        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        //!  
    729739}; 
    730740UIREGISTER(mBeta); 
     
    829839        } 
    830840 
    831         /*! Create Gamma density 
    832         \f[ f(rv|rvc) = \Gamma(\alpha, \beta) \f] 
    833         from structure 
     841        /*! Create object from the following structure 
     842 
    834843        \code 
    835844        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 
    839849        \endcode 
     850         fulfilling formula \f[ f(rv|rvc) = \Gamma(\alpha, \beta) \f] 
    840851        */ 
    841852        void from_setting ( const Setting &set ); 
     853 
    842854        void to_setting ( Setting &set ) const; 
    843855        void validate();  
     
    16821694void resample(const vec &w, ivec &ind, RESAMPLING_METHOD=SYSTEMATIC); 
    16831695 
    1684 /*! 
    1685 \brief Weighted empirical density 
     1696/*! \brief Weighted empirical density 
    16861697 
    16871698Used e.g. in particle filters. 
     
    17711782 
    17721783        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        */ 
    17731795        void from_setting ( const Setting &set ); 
    1774  
    17751796}; 
    17761797UIREGISTER(eEmp); 
     
    19451966} 
    19461967 
    1947 /*! Dirac delta function distribution */ 
     1968/*! \brief Dirac delta function distribution */ 
    19481969class dirac: public epdf{ 
    19491970        public:  
     
    19601981        }; 
    19611982 
    1962 //// 
    1963 /////// 
     1983 
     1984/////////// 
     1985 
    19641986template<class sq_T> 
    19651987void mgnorm<sq_T >::set_parameters ( const shared_ptr<fnc> &g0, const sq_T &R0 ) { 
  • library/doc/tutorial/kalman.dox

    r661 r1063  
    3838\section exa Examples of Use 
    3939 
    40 The classes can be used directly in C++ or via User Info. The latter example is illustrated in file \subpage user_guide2. A very short example of the former follows: 
     40The 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: 
    4141 
    4242\include kalman_simple.cpp