Changeset 265 for bdm/stat

Show
Ignore:
Timestamp:
02/09/09 23:14:58 (15 years ago)
Author:
smidl
Message:

UI in matlab

Location:
bdm/stat
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/libBM.cpp

    r263 r265  
    5252RV::RV() : tsize ( 0 ), len ( 0 ), ids ( 0 ),  sizes ( 0 ), times ( 0 ),names ( 0 ) {}; 
    5353 
    54 RV::RV(string name, int id){ 
    55         it_assert(id>=RVcounter,"RV::This id is already taken"); 
    56         RVcounter=id; 
     54RV::RV(string name, int id, int sz, int tm){ 
     55        if (id>RVcounter) {RVcounter=id;}; 
    5756        Array<string> A(1); A(0)=name; 
    58         init(vec_1(id),A,vec_1(1),vec_1(0)); 
     57        init(vec_1(id),A,vec_1(sz),vec_1(tm)); 
    5958} 
    6059 
  • bdm/stat/libBM.h

    r263 r265  
    7878                RV (); 
    7979                //! Constructor of a single RV with given id 
    80                 RV (string name, int id); 
     80                RV (string name, int id, int sz=1, int tm=0); 
    8181 
    8282                //! Printing output e.g. for debugging. 
     
    490490                        L.logit ( L_ut,tmp.mid ( Drv.count(), Urv.count() ) ); 
    491491                } 
    492         }; 
    493  
    494         /*! \brief Bayesian Model of the world, i.e. all uncertainty is modeled by probabilities. 
     492                //!access function  
     493                virtual RV _drv() const {return concat(Drv,Urv);} 
     494                //!access function  
     495                const RV& _urv() const {return Urv;} 
     496        }; 
     497 
     498        /*! \brief Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities. 
    495499 
    496500        */ 
     
    500504                //!Random variable of the posterior 
    501505                RV rv; 
     506                //! Random variable of the data (optional) 
     507                RV drv; 
    502508                //!Logarithm of marginalized data likelihood. 
    503509                double ll; 
     
    537543                //!access function 
    538544                const RV& _rv() const {return rv;} 
     545                //!access function  
     546                const RV& _drv() const {return drv;} 
     547                //!set drv 
     548                void set_drv(const RV &rv){drv=rv;} 
    539549                //!access function 
    540550                double _ll() const {return ll;} 
  • bdm/stat/libDS.cpp

    r263 r265  
    4444void ArxDS::step() { 
    4545        double tmp; 
     46        //shift history 
     47        H.shift_right ( 0, Drv.count() +Urv.count() ); 
     48 
     49        H.set_subvector ( Drv.count(), U ); // write U after Drv 
     50 
    4651        //get regressor 
    4752        rgr = rgrlnk.get_val ( H ); 
    4853        // Eval Y 
    49         Y = model.samplecond ( rgr,tmp ); 
     54        H.set_subvector ( 0, model.samplecond ( rgr,tmp ) ); 
    5055 
    51         //shift history 
    52         H.shift_right ( 0, Drv.count() +Urv.count() ); 
    53         //fill new data 
    54         H.set_subvector ( Drv.count(),Y ); 
    55  
    56         //Leaving U.length() empty slots - these will be filled by write() 
    5756} 
    5857 
     
    6059RV fullrgr ( const RV &drv0, const RV &urv0, const RV &rrv0 ) { 
    6160        RV T ( urv0 ); 
    62         RV pom = concat(drv0, urv0); 
     61        RV pom = concat ( drv0, urv0 ); 
    6362        int mint = rrv0.mint(); 
    6463        for ( int i=0; i>mint; i-- ) { 
     
    6968} 
    7069 
    71 ArxDS::ArxDS ( RV &drv, RV &urv, RV &rrv ) :  
    72                 DS(drv,urv), Rrv(rrv), Hrv( fullrgr ( drv,urv,rrv )), //RVs 
    73                 Y(drv.count()), H(Hrv.count()) ,rgr ( rrv.count() ),  //tmp variables 
    74                 rgrlnk (Hrv ,rrv ) ,model ( drv,rrv ) { 
     70ArxDS::ArxDS ( RV &drv, RV &urv, RV &rrv ) : 
     71                DS ( drv,urv ), Rrv ( rrv ), Hrv ( concat(drv,fullrgr ( drv,urv,rrv )) ), //RVs 
     72                H ( Hrv.count() ) ,U ( urv.count() ),rgr ( rrv.count() ),  //tmp variables 
     73                rgrlnk ( rrv, Hrv ) ,model ( drv,rrv ) { 
    7574} 
  • bdm/stat/libDS.h

    r263 r265  
    5353        */ 
    5454        class ArxDS : public DS { 
     55        protected: 
    5556                //! Rv of the regressor 
    5657                RV Rrv; 
    5758                //! Rv of the history (full regressor) 
    5859                RV Hrv; 
    59                 //! Internal storage of results 
    60                 vec Y; 
    61                 //! History, ordered as \f$[u_t, y_{t-1 }, u_{t-1}, \ldots]\f$  
     60                //! History, ordered as \f$[y_t, u_t, y_{t-1 }, u_{t-1}, \ldots]\f$ 
    6261                vec H; 
     62                //! (future) input 
     63                vec U; 
    6364                //! temporary variable for regressor 
    6465                vec rgr; 
    65                 //! data link: val = y, cond = u; local = rgr; 
     66                //! data link: H -> rgr 
    6667                datalink_e2e rgrlnk; 
    67                 //! model of Y - linear Gaussian  
     68                //! model of Y - linear Gaussian 
    6869                mlnorm<chmat> model; 
     70                //! options 
     71                bool opt_L_theta; 
     72                //! loggers 
     73                int L_theta; 
     74                int L_R; 
    6975                public: 
    70                 void getdata ( vec &dt ){it_assert_debug(dt.length()==Y.length(),"ArxDS");  
    71                         dt=concat(Y,H.left(Urv.count()));}; 
    72                 void getdata ( vec &dt, const ivec &indexes ){it_assert_debug(dt.length()==Y.length(),"ArxDS"); dt=Y(indexes);}; 
    73                 void write ( vec &ut ){it_assert_debug(ut.length()==Urv.count(),"ArxDS"); H.set_subvector(0,ut);}; 
    74                 void write ( vec &ut, const ivec &indexes ){it_assert_debug(ut.length()==Urv.count(),"ArxDS"); set_subvector(H,indexes,ut);}; 
     76                void getdata ( vec &dt ) { 
     77                        it_assert_debug ( dt.length() ==Drv.count(),"ArxDS" ); 
     78                        dt=H.left ( Urv.count() +Drv.count() ); 
     79                }; 
     80                void getdata ( vec &dt, const ivec &indexes ) { 
     81                        it_assert_debug ( dt.length() ==indeces.length(),"ArxDS" ); 
     82                        dt=H ( indexes ); 
     83                }; 
     84                void write ( vec &ut ) { 
     85                        it_assert_debug ( ut.length() ==Urv.count(),"ArxDS" ); 
     86                        U=ut; 
     87                }; 
     88                void write ( vec &ut, const ivec &indexes ) { 
     89                        it_assert_debug ( ut.length() ==indeces.length(),"ArxDS" ); 
     90                        set_subvector ( U, indexes,ut ); 
     91                }; 
    7592                void step(); 
    7693                //!Default constructor 
    77                 ArxDS ( RV &drv, RV &urv, RV &rrv); 
     94                ArxDS ( RV &drv, RV &urv, RV &rrv ); 
    7895                //! Set parameters of the internal model 
    79                 void set_parameters(const mat &Th0, const vec mu0, const chmat &sqR0) 
    80                 {model.set_parameters(Th0, mu0, sqR0); }; 
     96                void set_parameters ( const mat &Th0, const vec mu0, const chmat &sqR0 ) 
     97                { model.set_parameters ( Th0, mu0, sqR0 ); }; 
     98                //! set options from a string 
     99                void set_options ( const string &s ) { 
     100                        opt_L_theta= ( s.find ( "L_theta" ) !=string::npos ); 
     101                }; 
     102                virtual void log_add ( logger &L ) { 
     103                        DS::log_add ( L ); 
     104                        mat &A =model._A(); 
     105                        mat R =model._R(); 
     106                        if ( opt_L_theta ) {L_theta=L.add ( RV("{theta }", vec_1(A.rows() *A.cols())),"t" );} 
     107                        if ( opt_L_theta ) {L_R=L.add ( RV("{R }", vec_1(R.rows() *R.cols())),"r" );} 
     108                } 
     109                virtual void logit ( logger &L ) { 
     110                        DS::logit ( L ); 
     111                        mat &A =model._A(); 
     112                        mat R =model._R(); 
     113                        if ( opt_L_theta ) {L.logit ( L_theta,vec ( A._data(), A.rows() *A.cols() ) );}; 
     114                        if ( opt_L_theta ) {L.logit ( L_R, vec ( R._data(), R.rows() *R.rows() ) );}; 
     115                } 
     116 
    81117        }; 
    82118 
     119        class ARXDS : public ArxDS { 
     120        public: 
     121                ARXDS ( RV &drv, RV &urv, RV &rrv ) : ArxDS ( drv,urv,rrv ) {} 
     122 
     123                void getdata ( vec &dt ) {dt=H;} 
     124                void getdata ( vec &dt, const ivec &indeces ) {dt=H ( indeces );} 
     125                virtual RV _drv() const {return Hrv;} 
     126 
     127        }; 
    83128}; //namespace 
    84129