Changeset 22 for bdm/stat

Show
Ignore:
Timestamp:
02/18/08 17:50:37 (16 years ago)
Author:
smidl
Message:

upravy Kalmana

Location:
bdm/stat
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/libBM.h

    r19 r22  
    7373//! Class representing function $f(x)$ of variable $x$ represented by \c rv 
    7474class fnc { 
    75         RV rv; 
     75protected: 
     76        int dimy; 
    7677public:  
    7778        //! function evaluates numerical value of $f(x)$ at $x=cond$ 
    78         virtual vec eval(vec &cond){}; //Fixme: virtual? 
     79        virtual vec eval(const vec &cond){}; //Fixme: virtual? 
     80        //! access function 
     81        int _dimy()const{return dimy;} 
    7982}; 
    8083 
     
    8588        double ll; 
    8689 
     90        //!Default constructor 
     91        BM(){ll=0;}; 
     92         
    8793        /*! \brief Incremental Bayes rule 
    8894        @param dt vector of input data 
     
    100106        //! Returns the required moment of the epdf 
    101107//      virtual vec moment ( const int order = 1 ); 
    102         //! Returns a sample from the density, $x \sim epdf(rv)$ 
     108        //! Returns a sample from the density, \f$x \sim epdf(rv)\f$ 
    103109        virtual vec sample ()=0; 
     110        //! Compute probability of argument \c val 
    104111        virtual double eval(const vec &val){}; 
    105112}; 
  • bdm/stat/libEF.h

    r15 r22  
    4040 
    4141/*! 
    42 * \brief General exponential family density 
     42* \brief Gaussian density with positive definite (decomposed) covariance matrix. 
    4343 
    4444* More?... 
     
    5252        enorm( RV &rv, vec &mu, sq_T &R ); 
    5353        enorm(); 
     54        //! tupdate in exponential form (not really handy) 
    5455        void tupdate( double phi, mat &vbar, double nubar ); 
    5556        void dupdate( mat &v,double nu=1.0 ); 
     57        //!tupdate used in KF 
     58        void tupdate(); 
     59        //!dupdate used in KF 
     60        double dupdate(); 
     61          
    5662        vec sample(); 
    5763        mat sample(int N); 
  • bdm/stat/libFN.cpp

    r19 r22  
    99} 
    1010 
    11 bilinfn::bilinfn ( const RV &x0, const RV &u0, const mat &A0, const mat &B0 ) 
     11bilinfn::bilinfn ( const RV &rvx0, const RV &rvu0, const mat &A0, const mat &B0 ) : diffbifn ( rvx0,rvu0 ) 
    1212{ 
    13         it_assert_debug ( A0.cols() ==A0.rows() ==x0.count(), "linfn:: wrong A" ); 
    14         it_assert_debug ( ( B0.rows() ==x0.count() ) & ( B0.cols() ==u0.count() ), "linfn:: wrong B" ); 
     13        //check input 
     14        it_assert_debug ( ( A0.cols() ==dimx ) & ( A0.rows() ==B0.rows() ), "linfn:: wrong A" ); 
     15        it_assert_debug ( ( B0.cols() ==dimu ), "linfn:: wrong B" ); 
    1516 
     17        // set dimensions 
     18        dimy = A0.rows(); 
     19 
     20        //set internals 
    1621        A = A0; 
    1722        B = B0; 
    18         rv=x0; rv.add ( u0 ); 
    19         indexlist=rv.indexlist(); 
    2023}; 
    2124 
     25inline vec bilinfn::eval ( const  vec &x0, const vec &u0 ) 
     26{ 
     27        it_assert_debug ( x0.length() ==dimx, "linfn::eval Wrong xcond." ); 
     28        it_assert_debug ( u0.length() ==dimu, "linfn::eval Wrong ucond." ); 
     29        return A*x0+B*u0; 
     30}; 
  • bdm/stat/libFN.h

    r19 r22  
    2020                RV rv; 
    2121                vec val; 
     22 
    2223 
    2324        public: 
     
    4445}; 
    4546 
     47 
     48/*! 
     49\brief Class representing a differentiable function of two variables $f(x,u)$. 
     50 
     51Function of two variables. 
     52 
     53TODO: 
     541) Technically, it could have a common parent (e.g. \c fnc ) with other functions. For now, we keep it as it is. 
     552) It could be generalized into multivariate form, (which was original meaning of \c fnc ). 
     56*/ 
     57class diffbifn: public fnc 
     58{ 
     59        protected: 
     60                RV rvx,rvu; 
     61                int dimx; 
     62                int dimu; 
     63        public: 
     64                //! Evaluates $f(x0,u0)$ (VS: Do we really need common eval? ) 
     65                vec eval ( const vec &cond ) 
     66                { 
     67                        it_assert_debug ( cond.length() == ( dimx+dimu ), "linfn::eval Wrong cond." ); 
     68                        return eval ( cond ( 0,dimx-1 ),cond ( dimx,dimx+dimu ) );//-1 = end (in matlab) 
     69                }; 
     70 
     71                //! Evaluates $f(x0,u0)$ 
     72                virtual vec eval ( const vec &x0, const vec &u0 ) {return zeros ( dimy );}; 
     73                //! Evaluates \f$A=\frac{d}{dx}f(x,u)|_{x0,u0}\f$ and writes result into \c A . @param full denotes that even unchanged entries are to be rewritten. When, false only the changed elements are computed. 
     74                virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full=true ) {}; 
     75                //! Evaluates \f$A=\frac{d}{du}f(x,u)|_{x0,u0}\f$ and writes result into \c A . @param full denotes that even unchanged entries are to be rewritten. When, false only the changed elements are computed. 
     76                virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {}; 
     77                //!Default constructor (dimy is not set!) 
     78                diffbifn ( const RV rvx0, const RV rvu0 ) : rvx ( rvx0 ),rvu ( rvu0 ) {dimx=rvx.count();dimu=rvu.count();}; 
     79                //! access function 
     80                int _dimx() const{return dimx;} 
     81                //! access function 
     82                int _dimu() const{return dimu;} 
     83}; 
     84 
    4685//! Class representing function $f(x,u) = Ax+Bu$ 
    47 class bilinfn: public fnc 
     86//TODO can be generalized into multilinear form! 
     87class bilinfn: public diffbifn 
    4888{ 
    49                 RV rv; 
    50                 ivec indexlist; // needed by evalsome 
    5189                mat A; 
    5290                mat B; 
    5391        public : 
    54                 vec eval ( vec &cond ) 
     92                vec eval ( const  vec &x0, const vec &u0 ); 
     93 
     94                //! Default constructor 
     95                bilinfn ( const RV &rvx0, const RV &rvu0 ) : diffbifn ( rvx0,rvu0 ) ,A ( eye ( dimx ) ),B ( zeros ( dimx,dimu ) )       {}; 
     96                // 
     97                bilinfn ( const RV &rvx0, const RV &rvu0, const mat &A0, const mat &B0 ); 
     98                // 
     99                void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full ) 
    55100                { 
    56                         it_assert_debug ( cond.length() ==rv.count(), "linfn::eval Wrong cond." ); 
    57                         int sizex = A.cols(); 
    58                         return A*cond(0,sizex-1)+B*cond(sizex,-1);//-1 = end (in matlab) 
    59                 }; 
    60                 vec eval ( vec &xcond, vec &ucond ) 
     101                        it_assert_debug ( ( F.cols() ==A.cols() ) & ( F.rows() ==A.rows() ),"Allocated F is not compatible." ); 
     102                        if ( full ) F=A;        //else : nothing has changed no need to regenerate 
     103                } 
     104                // 
     105                void dfdu_cond ( const vec &x0, const vec &u0, mat &F,  bool full=true ) 
    61106                { 
    62                         it_assert_debug ( xcond.length() ==rv.count(), "linfn::eval Wrong cond." ); 
    63                         return A*xcond+B*ucond; 
    64                 }; 
    65  
    66                 bilinfn evalsome ( ivec &rvind ); 
    67                 bilinfn ( const RV &x0, const RV &u0 ) :A ( eye ( x0.count() ) ),B ( zeros ( x0.count(),u0.count() ) ) 
    68                 { 
    69                         rv=x0; rv.add ( u0 ); 
    70                         indexlist=rv.indexlist(); 
    71                 }; 
    72                 bilinfn ( const RV &x0, const RV &u0, const mat &A0, const mat &B0 ); 
     107                        it_assert_debug ( ( F.cols() ==B.cols() ) & ( F.rows() ==B.rows() ),"Allocated F is not compatible." ); 
     108                        if ( full ) F=B;        //else : nothing has changed no need to regenerate 
     109                } 
    73110};