work/mixpp/bdm/stat/libFN.h

00001 //
00002 // C++ Interface: itpp_ext
00003 //
00004 // Description:
00005 //
00006 //
00007 // Author: smidl <smidl@utia.cas.cz>, (C) 2008
00008 //
00009 // Copyright: See COPYING file that comes with this distribution
00010 //
00011 //
00012 #include <itpp/itbase.h>
00013 #include "libBM.h"
00014 
00015 using namespace itpp;
00016 
00018 class constfn : public fnc
00019 {
00020                 RV rv;
00021                 vec val;
00022 
00023 
00024         public:
00025                 vec eval() {return val;};
00026                 vec eval ( vec &cond ) {return val;};
00028                 constfn ( const vec &val0 ) :rv(),val ( val0 ) {};
00029 };
00030 
00032 class linfn: public fnc
00033 {
00034                 RV rv;
00035                 ivec indexlist; // needed by evalsome
00036                 mat A;
00037                 vec B;
00038         public :
00039                 vec eval ( vec &cond ) {it_assert_debug ( cond.length() ==rv.count(), "linfn::eval Wrong cond." );return A*cond+B;};
00040 
00041                 linfn evalsome ( ivec &rvind );
00042                 linfn ( const RV &rv0 ) :rv ( rv0 ),A ( eye ( rv0.count() ) ),B ( zeros ( rv0.count() ) ) { indexlist=rv.indexlist();};
00043                 linfn ( const RV &rv0, const mat &A0 ) : rv ( rv0 ), A ( A0 ), B ( zeros ( rv0.count() ) ) { indexlist=rv.indexlist();};
00044                 linfn ( const RV &rv0, const mat &A0, const vec &B0 ) :rv ( rv0 ), A ( A0 ), B ( B0 ) { indexlist=rv.indexlist();};
00045 };
00046 
00047 
00057 class diffbifn: public fnc
00058 {
00059         protected:
00060                 RV rvx,rvu;
00061                 int dimx;
00062                 int dimu;
00063                 int dimy;
00064         public:
00066                 vec eval ( const vec &cond )
00067                 {
00068                         it_assert_debug ( cond.length() == ( dimx+dimu ), "linfn::eval Wrong cond." );
00069                         return eval ( cond ( 0,dimx-1 ),cond ( dimx,dimx+dimu ) );//-1 = end (in matlab)
00070                 };
00071 
00073                 virtual vec eval ( const vec &x0, const vec &u0 ) {return zeros ( dimy );};
00075                 virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full=true ) {};
00077                 virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {};
00079                 diffbifn ( const RV rvx0, const RV rvu0 ) : rvx ( rvx0 ),rvu ( rvu0 ) {dimx=rvx.count();dimu=rvu.count();};
00081                 int _dimx() const{return dimx;}
00083                 int _dimu() const{return dimu;}
00084 };
00085 
00087 //TODO can be generalized into multilinear form!
00088 class bilinfn: public diffbifn
00089 {
00090                 mat A;
00091                 mat B;
00092         public :
00093                 vec eval ( const  vec &x0, const vec &u0 );
00094 
00096                 bilinfn ( const RV &rvx0, const RV &rvu0 ) : diffbifn ( rvx0,rvu0 ) ,A ( eye ( dimx ) ),B ( zeros ( dimx,dimu ) )       {};
00097                 //
00098                 bilinfn ( const RV &rvx0, const RV &rvu0, const mat &A0, const mat &B0 );
00099                 //
00100                 void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full )
00101                 {
00102                         it_assert_debug ( ( F.cols() ==A.cols() ) & ( F.rows() ==A.rows() ),"Allocated F is not compatible." );
00103                         if ( full ) F=A;        //else : nothing has changed no need to regenerate
00104                 }
00105                 //
00106                 void dfdu_cond ( const vec &x0, const vec &u0, mat &F,  bool full=true )
00107                 {
00108                         it_assert_debug ( ( F.cols() ==B.cols() ) & ( F.rows() ==B.rows() ),"Allocated F is not compatible." );
00109                         if ( full ) F=B;        //else : nothing has changed no need to regenerate
00110                 }
00111 };

Generated on Sun Feb 17 16:14:14 2008 for mixpp by  doxygen 1.5.3