Changeset 271 for bdm/estim

Show
Ignore:
Timestamp:
02/16/09 10:03:13 (15 years ago)
Author:
smidl
Message:

Next major revision

Location:
bdm/estim
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • bdm/estim/arx.h

    r270 r271  
    3131\f] 
    3232 
    33 Extension for time-variant parameters \f$\theta_t,r_t\f$ may be achived using exponential forgetting (Kulhavy and Zarrop, 1993). In such a case, the forgetting factor \c frg \f$\in <0,1>\f$ should be given in the constructor. Time-invariant parameters are estimated for \c frg = 1. 
     33See \ref tut_arx for mathematical treatment. 
     34 
     35The easiest way how to use the class is: 
     36\include arx_simple.cpp 
     37 
    3438*/ 
    3539class ARX: public BMEF { 
     
    8993        //!@{ 
    9094        const egiw* _e() const {return &est ;}; 
    91         const egiw& _epdf() const {return est;} 
     95        const egiw& posterior() const {return est;} 
    9296        //!@} 
    9397 
  • bdm/estim/libKF.cpp

    r270 r271  
    66using std::endl; 
    77 
    8 KalmanFull::KalmanFull ( mat A0, mat B0, mat C0, mat D0, mat R0, mat Q0, mat P0, vec mu0 ) { 
     8KalmanFull::KalmanFull ( mat A0, mat B0, mat C0, mat D0, mat Q0, mat R0, mat P0, vec mu0 ) { 
    99        dimx = A0.rows(); 
    1010        dimu = B0.cols(); 
     
    1515        it_assert_debug ( C0.cols() ==dimx, "KalmanFull: C is not square" ); 
    1616        it_assert_debug ( ( D0.rows() ==dimy ) || ( D0.cols() ==dimu ), "KalmanFull: D is not compatible" ); 
     17        it_assert_debug ( ( Q0.cols() ==dimx ) || ( Q0.rows() ==dimx ), "KalmanFull: Q is not compatible" ); 
    1718        it_assert_debug ( ( R0.cols() ==dimy ) || ( R0.rows() ==dimy ), "KalmanFull: R is not compatible" ); 
    18         it_assert_debug ( ( Q0.cols() ==dimx ) || ( Q0.rows() ==dimx ), "KalmanFull: Q is not compatible" ); 
    1919 
    2020        A = A0; 
     
    116116 
    117117 
    118 void KalmanCh::set_parameters ( const mat &A0,const mat &B0,const mat &C0,const mat &D0,const chmat &R0,const chmat &Q0 ) { 
    119  
    120         ( ( Kalman<chmat>* ) this )->set_parameters ( A0,B0,C0,D0,R0,Q0 ); 
     118void KalmanCh::set_parameters ( const mat &A0,const mat &B0,const mat &C0,const mat &D0,const chmat &Q0,const chmat &R0 ) { 
     119 
     120        ( ( Kalman<chmat>* ) this )->set_parameters ( A0,B0,C0,D0,Q0,R0 ); 
    121121        // Cholesky special! 
    122         preA.clear(); 
     122        preA=zeros(dimy+dimx+dimx,dimy+dimx); 
     123//      preA.clear(); 
    123124        preA.set_submatrix ( 0,0,R._Ch() ); 
    124125        preA.set_submatrix ( dimy+dimx,dimy,Q._Ch() ); 
  • bdm/estim/libKF.h

    r270 r271  
    109109        Kalman ( const Kalman<sq_T> &K0 ); 
    110110        //! Set parameters with check of relevance 
    111         void set_parameters ( const mat &A0,const mat &B0,const mat &C0,const mat &D0,const sq_T &R0,const sq_T &Q0 ); 
     111        void set_parameters ( const mat &A0,const mat &B0,const mat &C0,const mat &D0,const sq_T &Q0,const sq_T &R0 ); 
    112112        //! Set estimate values, used e.g. in initialization. 
    113113        void set_est ( const vec &mu0, const sq_T &P0 ) { 
     
    121121        void bayes ( const vec &dt ); 
    122122        //!access function 
    123         const epdf& _epdf() const {return est;} 
     123        const epdf& posterior() const {return est;} 
    124124        const enorm<sq_T>* _e() const {return &est;} 
    125125        //!access function 
     
    130130 
    131131/*! \brief Kalman filter in square root form 
     132 
     133Trivial example: 
     134\include kalman_simple.cpp 
     135  
    132136*/ 
    133137class KalmanCh : public Kalman<chmat>{ 
     
    142146        KalmanCh ():Kalman<chmat>(),preA(),postA(){}; 
    143147        //! Set parameters with check of relevance 
    144         void set_parameters ( const mat &A0,const mat &B0,const mat &C0,const mat &D0,const chmat &R0,const chmat &Q0 ); 
    145         void set_est ( const vec &mu0, const chmat &P0 ) { 
     148        void set_parameters ( const mat &A0,const mat &B0,const mat &C0,const mat &D0,const chmat &Q0,const chmat &R0 ); 
     149        void set_statistics ( const vec &mu0, const chmat &P0 ) { 
    146150                est.set_parameters ( mu0,P0 ); 
    147151        }; 
     
    187191        void set_est (vec mu0, mat P0){mu=mu0;P=P0;}; 
    188192        //!dummy! 
    189         const epdf& _epdf()const{return E;}; 
     193        const epdf& posterior()const{return E;}; 
    190194        const enorm<fsqmat>* _e()const{return &E;}; 
    191195        const mat _R(){return P;} 
     
    281285 
    282286template<class sq_T> 
    283 void Kalman<sq_T>::set_parameters ( const mat &A0,const  mat &B0, const mat &C0, const mat &D0, const sq_T &R0, const sq_T &Q0 ) { 
     287void Kalman<sq_T>::set_parameters ( const mat &A0,const  mat &B0, const mat &C0, const mat &D0, const sq_T &Q0, const sq_T &R0 ) { 
     288        dimx = A0.rows(); 
     289        dimy = C0.rows(); 
     290        dimu = B0.cols(); 
     291         
    284292        it_assert_debug ( A0.cols() ==dimx, "Kalman: A is not square" ); 
    285293        it_assert_debug ( B0.rows() ==dimx, "Kalman: B is not compatible" ); 
  • bdm/estim/libPF.h

    r270 r271  
    122122                for ( int i=0;i<n;i++ ) { 
    123123                        Bms[i] = new BM_T ( BMcond0 ); //copy constructor 
    124                         const epdf& pom=Bms[i]->_epdf(); 
     124                        const epdf& pom=Bms[i]->posterior(); 
    125125                        jest.set_elements ( i,1.0/n,&pom ); 
    126126                } 
     
    131131 
    132132        void bayes ( const vec &dt ); 
    133         const epdf& _epdf() const {return jest;} 
     133        const epdf& posterior() const {return jest;} 
    134134        const epdf* _e() const {return &jest;} //Fixme: is it useful? 
    135135        //! Set postrior of \c rvc to samples from epdf0. Statistics of Bms are not re-computed! Use only for initialization! 
     
    195195                                delete Bms[i]; 
    196196                                Bms[i] = new BM_T ( *Bms[ind ( i ) ] ); //copy constructor 
    197                                 const epdf& pom=Bms[i]->_epdf(); 
     197                                const epdf& pom=Bms[i]->posterior(); 
    198198                                jest.set_elements ( i,1.0/n,&pom ); 
    199199                        } 
  • bdm/estim/merger.h

    r270 r271  
    8181        void merge ( const epdf* g0 ); 
    8282//!Create a mixture density, make sure to call init() before the first call 
    83         void merge () {merge ( & ( Mix._epdf() ) );}; 
     83        void merge () {merge ( & ( Mix.posterior() ) );}; 
    8484 
    8585//! Merge log-likelihood values 
     
    8787//! sample from merged density 
    8888//! weight w is a 
    89         vec sample ( ) const { return Mix._epdf().sample();} 
     89        vec sample ( ) const { return Mix.posterior().sample();} 
    9090        double evallog ( const vec &dt ) const { 
    9191                vec dtf=ones ( dt.length() +1 ); 
  • bdm/estim/mixef.cpp

    r270 r271  
    124124double MixEF::logpred ( const vec &dt ) const { 
    125125 
    126         vec w=weights._epdf().mean(); 
     126        vec w=weights.posterior().mean(); 
    127127        double exLL=0.0; 
    128128        for ( int i=0;i<n;i++ ) { 
     
    137137        emix* tmp; 
    138138        tmp = new emix (  ); 
    139         tmp->set_parameters ( weights._epdf().mean(), pC, false ); 
     139        tmp->set_parameters ( weights.posterior().mean(), pC, false ); 
    140140        tmp->ownComs(); 
    141141        return tmp; 
  • bdm/estim/mixef.h

    r270 r271  
    5959                for ( int i=0;i<Coms.length();i++ ) { 
    6060//                      it_assert_debug(!x,"MixEF::MixEF : Incompatible components"); 
    61                         epdfs ( i ) =& ( Coms ( i )->_epdf() ); 
     61                        epdfs ( i ) =& ( Coms ( i )->posterior() ); 
    6262                } 
    6363                // last in the product is the weight 
    64                 epdfs ( n ) =& ( weights._epdf() ); 
     64                epdfs ( n ) =& ( weights.posterior() ); 
    6565                est = new eprod ( epdfs ); 
    6666        } 
     
    104104        void bayesB ( const mat &dt, const vec &wData ); 
    105105        double logpred ( const vec &dt ) const; 
    106         const epdf& _epdf() const {return *est;} 
     106        const epdf& posterior() const {return *est;} 
    107107        const eprod* _e() const {return est;} 
    108108        emix* epredictor() const;