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         public:
00065                 vec eval ( const vec &cond )
00066                 {
00067                         it_assert_debug ( cond.length() == ( dimx+dimu ), "linfn::eval Wrong cond." );
00068                         return eval ( cond ( 0,dimx-1 ),cond ( dimx,dimx+dimu ) );//-1 = end (in matlab)
00069                 };
00070 
00072                 virtual vec eval ( const vec &x0, const vec &u0 ) {return zeros ( dimy );};
00074                 virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full=true ) {};
00076                 virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {};
00078                 diffbifn ( const RV rvx0, const RV rvu0 ) : rvx ( rvx0 ),rvu ( rvu0 ) {dimx=rvx.count();dimu=rvu.count();};
00080                 int _dimx() const{return dimx;}
00082                 int _dimu() const{return dimu;}
00083 };
00084 
00086 //TODO can be generalized into multilinear form!
00087 class bilinfn: public diffbifn
00088 {
00089                 mat A;
00090                 mat B;
00091         public :
00092                 vec eval ( const  vec &x0, const vec &u0 );
00093 
00095                 bilinfn ( const RV &rvx0, const RV &rvu0 ) : diffbifn ( rvx0,rvu0 ) ,A ( eye ( dimx ) ),B ( zeros ( dimx,dimu ) )       {};
00096                 //
00097                 bilinfn ( const RV &rvx0, const RV &rvu0, const mat &A0, const mat &B0 );
00098                 //
00099                 void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full )
00100                 {
00101                         it_assert_debug ( ( F.cols() ==A.cols() ) & ( F.rows() ==A.rows() ),"Allocated F is not compatible." );
00102                         if ( full ) F=A;        //else : nothing has changed no need to regenerate
00103                 }
00104                 //
00105                 void dfdu_cond ( const vec &x0, const vec &u0, mat &F,  bool full=true )
00106                 {
00107                         it_assert_debug ( ( F.cols() ==B.cols() ) & ( F.rows() ==B.rows() ),"Allocated F is not compatible." );
00108                         if ( full ) F=B;        //else : nothing has changed no need to regenerate
00109                 }
00110 };

Generated on Thu Feb 28 16:54:40 2008 for mixpp by  doxygen 1.5.3