Changeset 1066 for library

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

another part - all conditional pdfs untill bdm::euni

Location:
library/bdm
Files:
6 modified

Legend:

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

    r1064 r1066  
    275275    class = 'RV'; 
    276276    names = {'a', 'b', 'c', ...};   // UNIQUE IDENTIFIER same names = same variable 
    277                                                                 // names are also used when storing results 
     277                                    // names are also used when storing results 
    278278    --- optional --- 
    279279    sizes = [1, 2, 3, ...];         // size of each name. default = ones() 
    280                                                                 // if size = -1, it is found out from previous instances of the same name 
     280                                    // if size = -1, it is found out from previous instances of the same name 
    281281    times = [-1, -2, 0, ...];       // time shifts with respect to current time, default = zeros() 
    282282    \endcode 
     
    725725SHAREDPTR ( pdf ); 
    726726 
    727 //! Probability density function with numerical statistics, e.g. posterior density. 
     727//! Abstract class representing probability density function with numerical statistics, e.g. posterior density. 
    728728class epdf : public pdf { 
    729729    //! \var log_level_enums logmean 
     
    820820    //! \name Access to attributes 
    821821    //! @{ 
    822  
    823     //! Load from structure with elements: 
    824     //!  \code 
    825     //! { rv = {class="RV", names=(...),}; // RV describing meaning of random variable 
    826     //!   // elements of offsprings 
    827     //! } 
     822    //! Create object from the following structure 
     823    //! 
     824    //! \code 
     825    //! rv = RV({'names',...},[sizes,...],[times,...]);   % RV describing meaning of random variable 
     826    //!    --- inherited fields --- 
     827    //! bdm::pdf::from_setting 
    828828    //! \endcode 
    829     //!@} 
     829    //! @} 
    830830    void from_setting ( const Setting &set ); 
    831831    void to_setting ( Setting &set ) const; 
     
    11291129        //establish c2c connection 
    11301130        rvc.dataind ( rvc_up, c2c_lo, c2c_up ); 
    1131 //              bdm_assert_debug ( c2c_lo.length() + v2c_lo.length() == condsize, "cond is not fully given" ); 
     1131//         bdm_assert_debug ( c2c_lo.length() + v2c_lo.length() == condsize, "cond is not fully given" ); 
    11321132    } 
    11331133 
     
    12981298 
    12991299    BM() : yrv(), dimy ( 0 ), rvc(), dimc ( 0 ), ll ( 0 ), evalll ( true ) { }; 
    1300     //  BM ( const BM &B ) :  yrv ( B.yrv ), dimy(B.dimy), rvc ( B.rvc ),dimc(B.dimc), ll ( B.ll ), evalll ( B.evalll ) {} 
     1300    //    BM ( const BM &B ) :  yrv ( B.yrv ), dimy(B.dimy), rvc ( B.rvc ),dimc(B.dimc), ll ( B.ll ), evalll ( B.evalll ) {} 
    13011301    //! \brief Copy function required in vectors, Arrays of BM etc. Have to be DELETED manually! 
    13021302    //! Prototype: \code BM* _copy() const {return new BM(*this);} \endcode 
  • library/bdm/estim/mixtures.h

    r1064 r1066  
    5656    //aux 
    5757    friend class eprod_mix; 
    58     //!Posterior on component parameters 
     58 
     59    //! \brief Posterior on component parameters 
    5960    class eprod_mix: public eprod_base { 
    6061    protected: 
  • library/bdm/estim/particles.h

    r1064 r1066  
    2020namespace bdm { 
    2121 
    22 //! class used in PF 
     22//! \brief Internal class used in PF 
    2323class MarginalizedParticleBase : public BM { 
    2424protected: 
     
    2828    shared_ptr<BM> bm; 
    2929 
    30     //! custom posterior - product of empirical and exact part 
     30    // custom posterior - product of empirical and exact part 
    3131    class eprod_2:public eprod_base { 
    3232    protected: 
     
    301301        //est.set_statistics ( w0, epdf0 ); 
    302302    }; 
    303     /*  void set_statistics ( const eEmp &epdf0 ) { 
    304                 bdm_assert_debug ( epdf0._rv().equal ( par->_rv() ), "Incompatible input" ); 
    305                 est = epdf0; 
    306         };*/ 
     303    /*    void set_statistics ( const eEmp &epdf0 ) { 
     304            bdm_assert_debug ( epdf0._rv().equal ( par->_rv() ), "Incompatible input" ); 
     305            est = epdf0; 
     306        };*/ 
    307307    //!@} 
    308308 
     
    336336    n               = 10;                 // number of particles 
    337337    resmethod       = 'systematic', or 'multinomial', or 'stratified' 
    338                                                                           // resampling method 
     338                                          // resampling method 
    339339    res_threshold   = 0.5;                // resample when active particles drop below 50% 
    340340    \endcode 
     
    494494 
    495495\f{eqnarray*}{ 
    496         x_t &=& g(x_{t-1}) + v_t,\\ 
    497         y_t &\sim &fy(x_t), 
    498         \f} 
    499  
    500         This particle is a only a shell creating the residues calling internal estimator of their parameters. The internal estimator can be of any compatible type, e.g. ARX for Gaussian residues with unknown mean and variance. 
    501  
    502         */ 
     496    x_t &=& g(x_{t-1}) + v_t,\\ 
     497    y_t &\sim &fy(x_t), 
     498    \f} 
     499 
     500    This particle is a only a shell creating the residues calling internal estimator of their parameters. The internal estimator can be of any compatible type, e.g. ARX for Gaussian residues with unknown mean and variance. 
     501 
     502    */ 
    503503class NoiseParticleX : public MarginalizedParticleBase { 
    504504protected: 
     
    599599 
    600600\f{eqnarray*}{ 
    601         x_t &=& g(x_{t-1}) + v_t,\\ 
    602         z_t &= &h(x_{t-1}) + w_t, 
    603         \f} 
    604  
    605         This particle is a only a shell creating the residues calling internal estimator of their parameters. The internal estimator can be of any compatible type, e.g. ARX for Gaussian residues with unknown mean and variance. 
    606  
    607         */ 
     601    x_t &=& g(x_{t-1}) + v_t,\\ 
     602    z_t &= &h(x_{t-1}) + w_t, 
     603    \f} 
     604 
     605    This particle is a only a shell creating the residues calling internal estimator of their parameters. The internal estimator can be of any compatible type, e.g. ARX for Gaussian residues with unknown mean and variance. 
     606 
     607    */ 
    608608class NoiseParticle : public MarginalizedParticleBase { 
    609609protected: 
  • library/bdm/stat/discrete.h

    r1064 r1066  
    163163UIREGISTER ( grid_fnc ); 
    164164 
    165 //! Piecewise constant pdf on rectangular support 
     165//! \brief Piecewise constant pdf on rectangular support 
     166//! 
    166167//! Each point on the grid represents a centroid around which the density is constant. 
    167168//! This is a trivial point-mass density where all points have the same mass. 
     
    177178        return log ( values ( sup.linear_index ( sup.nearest_point ( val ) ) ) ); 
    178179    } 
    179  
    180180}; 
    181181} 
  • library/bdm/stat/emix.h

    r1064 r1066  
    105105class emix; //forward 
    106106 
    107 /*! Base class (Interface) for mixtures 
    108 */ 
     107//! \brief Base class (interface) for mixtures 
    109108class emix_base : public epdf { 
    110109protected: 
     
    188187    } 
    189188 
    190     //! Load from structure with elements: 
    191     //!  \code 
    192     //! { class='emix'; 
    193     //!   pdfs = (..., ...);     // list of pdfs in the mixture 
    194     //!   weights = ( 0.5, 0.5 ); // weights of pdfs in the mixture 
    195     //! } 
    196     //! \endcode 
    197     //!@} 
     189    /*! Create object from the following structure 
     190 
     191    \code 
     192    class = 'emix'; 
     193 
     194    pdfs = { list of any bdm::pdf offsprings };   % pdfs in the mixture, bdm::pdf::from_setting 
     195    weights = [... ];                             % vector of weights of pdfs in the mixture 
     196    --- inherited fields --- 
     197    bdm::emix_base::from_setting 
     198    \endcode 
     199 
     200    */ 
    198201    void from_setting ( const Setting &set ); 
     202 
    199203    void to_setting  (Setting  &set) const; 
    200204 
     
    270274    //!@} 
    271275    void from_setting ( const Setting &set ) ; 
    272     void        to_setting  (Setting  &set) const; 
     276    void     to_setting  (Setting  &set) const; 
    273277 
    274278 
     
    278282 
    279283 
    280 //! Product of independent epdfs. For dependent pdfs, use mprod. 
     284//! \brief Base class (interface) for bdm::eprod 
    281285class eprod_base: public epdf { 
    282286protected: 
     
    335339}; 
    336340 
     341//! \brief Product of independent epdfs. For dependent pdfs, use bdm::mprod. 
    337342class eprod: public eprod_base { 
    338343protected: 
     
    348353        factors = epdfs0; 
    349354    } 
     355 
     356    /*! Create object from the following structure 
     357 
     358    \code 
     359    class = 'eprod'; 
     360    pdfs = { list of any bdm::epdf offsprings };   % pdfs in the product, bdm::epdf::from_setting 
     361    --- inherited fields --- 
     362    bdm::eprod_base::from_setting 
     363    \endcode 
     364 
     365    */ 
    350366    void from_setting(const Setting &set) { 
    351367        UI::get(factors,set,"pdfs",UI::compulsory); 
     
    354370UIREGISTER(eprod); 
    355371 
    356 //! similar to eprod but used only internally -- factors are external pointers 
     372//! \brief Internal class similar to eprod - factors are external pointers. To be used only internally!   
    357373class eprod_internal: public eprod_base { 
    358374protected: 
     
    402418    //!@} 
    403419    void from_setting ( const Setting &set ); 
    404     void        to_setting  (Setting  &set) const; 
     420    void     to_setting  (Setting  &set) const; 
    405421    virtual void validate(); 
    406422}; 
     
    409425 
    410426 
    411 //! Base class for all BM running as parallel update of internal BMs 
    412  
     427//! \brief Base class for all BM running as parallel update of internal BMs 
    413428class ProdBMBase : public BM { 
    414429protected : 
  • library/bdm/stat/exp_family.h

    r1064 r1066  
    3636class eEF : public epdf { 
    3737public: 
    38 //      eEF() :epdf() {}; 
     38//    eEF() :epdf() {}; 
    3939    //! default constructor 
    4040    eEF () : epdf () {}; 
     
    216216        return R.to_mat(); 
    217217    } 
    218     //  mlnorm<sq_T>* condition ( const RV &rvn ) const ; <=========== fails to cmpile. Why? 
     218    //    mlnorm<sq_T>* condition ( const RV &rvn ) const ; <=========== fails to cmpile. Why? 
    219219    shared_ptr<pdf> condition ( const RV &rvn ) const; 
    220220 
     
    450450    } 
    451451 
    452     /*! Create Gauss-inverse-Wishart density 
    453     \f[ f(rv) = GiW(V,\nu) \f] 
    454     from structure 
     452    /*! Create object from the following structure 
    455453    \code 
     454 
    456455    class = 'egiw'; 
    457     V.L     = [];             // L part of matrix V 
    458     V.D     = [];             // D part of matrix V 
    459     -or- V  = []              // full matrix V 
    460     -or- dV = [];               // vector of diagonal of V (when V not given) 
    461     nu      = [];               // scalar \nu ((almost) degrees of freedom) 
    462                                                   // when missing, it will be computed to obtain proper pdf 
    463     dimx    = [];               // dimension of the wishart part 
    464     rv = RV({'name'})         // description of RV 
    465     rvc = RV({'name'})        // description of RV in condition 
     456    dimx    = [...];       % dimension of the wishart part 
     457    V.L     = [...];       % L part of matrix V 
     458    V.D     = [...];       % D part of matrix V 
     459    -or- V  = [...];       % full matrix V 
     460    -or- dV = [...];       % vector of diagonal of V (when V not given) 
     461 
     462    rv = RV({'names',...},[sizes,...],[times,...]);   % description of RV 
     463    rvc = RV({'names',...},[sizes,...],[times,...]);  % description of RV in condition 
     464 
     465    --- optional fields --- 
     466    nu      = [];             % scalar \nu ((almost) degrees of freedom) 
     467    --- inherited fields --- 
     468    bdm::eEF::from_setting 
    466469    \endcode 
     470 
     471    fulfilling formula \f[ f(rv) = GiW(V,\nu) \f] 
     472 
     473    If \nu is not given, it will be computed to obtain proper pdf. 
    467474 
    468475    \sa log_level_enums 
     
    696703    */ 
    697704    void from_setting ( const Setting &set ); 
    698     void        to_setting  (Setting  &set) const; 
     705    void     to_setting  (Setting  &set) const; 
    699706    void validate(); 
    700707}; 
     
    855862    \code 
    856863    class = 'egamma'; 
    857     alpha = [...];         % vector of alpha 
    858     beta = [...];          % vector of beta 
     864    alpha = [...];         % vector alpha 
     865    beta = [...];          % vector beta 
    859866    --- inherited fields --- 
    860867    bdm::eEF::from_setting 
     
    910917class emix : public epdf { 
    911918protected: 
    912         int n; 
    913         vec &w; 
    914         Array<epdf*> Coms; 
     919    int n; 
     920    vec &w; 
     921    Array<epdf*> Coms; 
    915922public: 
    916923//! Default constructor 
    917         emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {}; 
    918         void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;} 
    919         vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;}; 
     924    emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {}; 
     925    void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;} 
     926    vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;}; 
    920927}; 
    921928*/ 
     
    980987     */ 
    981988    void from_setting ( const Setting &set ); 
    982     void        to_setting  (Setting  &set) const; 
     989    void     to_setting  (Setting  &set) const; 
    983990    void validate(); 
    984991}; 
     
    10031010        iepdf.set_parameters ( -delta, delta ); 
    10041011    } 
    1005     void        to_setting  (Setting  &set) const { 
     1012    void     to_setting  (Setting  &set) const { 
    10061013        pdf::to_setting ( set ); 
    10071014        UI::save( iepdf.mean(), set, "delta"); 
     
    10281035    //! Constant additive term 
    10291036    vec mu_const; 
    1030 //                      vec& _mu; //cached epdf.mu; !!!!!! WHY NOT? 
     1037//            vec& _mu; //cached epdf.mu; !!!!!! WHY NOT? 
    10311038public: 
    10321039    //! \name Constructors 
     
    11281135class mgnorm : public pdf_internal< enorm< sq_T > > { 
    11291136private: 
    1130 //                      vec &mu; WHY NOT? 
     1137//            vec &mu; WHY NOT? 
    11311138    shared_ptr<fnc> g; 
    11321139 
     
    11481155 
    11491156    R = [1, 0;             // covariance matrix 
    1150         0, 1]; 
    1151         --OR -- 
     1157        0, 1]; 
     1158        --OR -- 
    11521159    dR = [1, 1];           // diagonal of cavariance matrix 
    11531160 
     
    12141221public: 
    12151222    mlstudent () : mlnorm<ldmat, enorm> (), 
    1216         Lambda (),      _R ( iepdf._R() ) {} 
     1223        Lambda (),    _R ( iepdf._R() ) {} 
    12171224    //! constructor function 
    12181225    void set_parameters ( const mat &A0, const vec &mu0, const ldmat &R0, const ldmat& Lambda0 ) { 
     
    12761283    */ 
    12771284    void from_setting ( const Setting &set ); 
    1278     void        to_setting  (Setting  &set) const; 
     1285    void     to_setting  (Setting  &set) const; 
    12791286    void validate(); 
    12801287}; 
     
    13241331    }; 
    13251332 
    1326     void        validate () { 
     1333    void     validate () { 
    13271334        pdf_internal<eigamma>::validate(); 
    13281335        dimc = dimension(); 
     
    13621369    }; 
    13631370 
    1364     void        validate () { 
     1371    void     validate () { 
    13651372        mgamma::validate(); 
    13661373        dimc = dimension(); 
     
    16071614    } 
    16081615 
    1609     virtual void        validate () { 
     1616    virtual void     validate () { 
    16101617        epdf::validate(); 
    16111618        W.validate(); 
     
    16371644        X.inv ( iX ); 
    16381645        // compute 
    1639 //                              \frac{ |\Psi|^{m/2}|X|^{-(m+p+1)/2}e^{-tr(\Psi X^{-1})/2} }{ 2^{mp/2}\Gamma_p(m/2)}, 
     1646//                 \frac{ |\Psi|^{m/2}|X|^{-(m+p+1)/2}e^{-tr(\Psi X^{-1})/2} }{ 2^{mp/2}\Gamma_p(m/2)}, 
    16401647        mat M = Y.to_mat() * iX.to_mat(); 
    16411648 
     
    16431650        //Fixme! Multivariate gamma omitted!! it is ok for sampling, but not otherwise!! 
    16441651 
    1645         /*                              if (0) { 
    1646                                                 mat XX=X.to_mat(); 
    1647                                                 mat YY=Y.to_mat(); 
    1648  
    1649                                                 double log2 = 0.5*p*log(det(YY))-0.5*(delta+p+1)*log(det(XX))-0.5*trace(YY*inv(XX)); 
    1650                                                 cout << log1 << "," << log2 << endl; 
    1651                                         }*/ 
     1652        /*                if (0) { 
     1653                            mat XX=X.to_mat(); 
     1654                            mat YY=Y.to_mat(); 
     1655 
     1656                            double log2 = 0.5*p*log(det(YY))-0.5*(delta+p+1)*log(det(XX))-0.5*trace(YY*inv(XX)); 
     1657                            cout << log1 << "," << log2 << endl; 
     1658                        }*/ 
    16521659        return log1; 
    16531660    }; 
     
    17461753        samples = Av; 
    17471754    }; 
    1748     virtual void        validate (); 
     1755    virtual void     validate (); 
    17491756    //! Potentially dangerous, use with care. 
    17501757    vec& _w()  { 
     
    17991806    \code 
    18001807    class = 'eEmp'; 
    1801     samples = [...];               % array of samples 
    1802     w = [...];                                     % weights of samples stored in vector 
     1808    samples = [...];  % array of samples 
     1809    w = [...];        % weights of samples stored in vector 
    18031810    --- inherited fields --- 
    18041811    bdm::epdf::from_setting 
     
    18531860// template<class sq_T> 
    18541861// void enorm<sq_T>::tupdate ( double phi, mat &vbar, double nubar ) { 
    1855 //      // 
     1862//     // 
    18561863// }; 
    18571864 
     
    18691876// template<class sq_T> 
    18701877// double enorm<sq_T>::eval ( const vec &val ) const { 
    1871 //      double pdfl,e; 
    1872 //      pdfl = evallog ( val ); 
    1873 //      e = exp ( pdfl ); 
    1874 //      return e; 
     1878//     double pdfl,e; 
     1879//     pdfl = evallog ( val ); 
     1880//     e = exp ( pdfl ); 
     1881//     return e; 
    18751882// }; 
    18761883 
     
    18921899// template<class sq_T> 
    18931900// vec mlnorm<sq_T>::samplecond (const  vec &cond, double &lik ) { 
    1894 //      this->condition ( cond ); 
    1895 //      vec smp = epdf.sample(); 
    1896 //      lik = epdf.eval ( smp ); 
    1897 //      return smp; 
     1901//     this->condition ( cond ); 
     1902//     vec smp = epdf.sample(); 
     1903//     lik = epdf.eval ( smp ); 
     1904//     return smp; 
    18981905// } 
    18991906 
    19001907// template<class sq_T> 
    19011908// mat mlnorm<sq_T>::samplecond (const vec &cond, vec &lik, int n ) { 
    1902 //      int i; 
    1903 //      int dim = rv.count(); 
    1904 //      mat Smp ( dim,n ); 
    1905 //      vec smp ( dim ); 
    1906 //      this->condition ( cond ); 
     1909//     int i; 
     1910//     int dim = rv.count(); 
     1911//     mat Smp ( dim,n ); 
     1912//     vec smp ( dim ); 
     1913//     this->condition ( cond ); 
    19071914// 
    1908 //      for ( i=0; i<n; i++ ) { 
    1909 //              smp = epdf.sample(); 
    1910 //              lik ( i ) = epdf.eval ( smp ); 
    1911 //              Smp.set_col ( i ,smp ); 
    1912 //      } 
     1915//     for ( i=0; i<n; i++ ) { 
     1916//         smp = epdf.sample(); 
     1917//         lik ( i ) = epdf.eval ( smp ); 
     1918//         Smp.set_col ( i ,smp ); 
     1919//     } 
    19131920// 
    1914 //      return Smp; 
     1921//     return Smp; 
    19151922// } 
    19161923