- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

# 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 #ifndef FN_H
    00013 #define FN_H
    00014
    00015 #include "libBM.h"
    00016
    00017 namespace bdm{
    00018
    00020 class constfn : public fnc
    00021 {
    00023                 vec val;
    00024
    00025         public:
    00026                 //vec eval() {return val;};
    00028                 vec eval ( const vec &cond ) {return val;};
    00030                 constfn ( const vec &val0 ) :fnc(), val ( val0 ) {dimy=val.length();};
    00031 };
    00032
    00034 class linfn: public fnc
    00035 {
    00037                 RV rv;
    00039                 mat A;
    00041                 vec B;
    00042         public :
    00043                 vec eval (const vec &cond ) {it_assert_debug ( cond.length() ==A.cols(), "linfn::eval Wrong cond." );return A*cond+B;};
    00044
    00045 //              linfn evalsome ( ivec &rvind );
    00047                 linfn ( ) : fnc(), A ( ),B () { };
    00049                 void set_parameters ( const mat &A0 , const vec &B0 ) {A=A0; B=B0; dimy=A.rows();};
    00050 };
    00051
    00052
    00062 class diffbifn: public fnc
    00063 {
    00064         protected:
    00066                 RV rvx;
    00068                 RV rvu;
    00070                 int dimx;
    00072                 int dimu;
    00073         public:
    00075                 vec eval ( const vec &cond )
    00076                 {
    00077                         it_assert_debug ( cond.length() == ( dimx+dimu ), "linfn::eval Wrong cond." );
    00078                         return eval ( cond ( 0,dimx-1 ),cond ( dimx,dimx+dimu-1 ) );//-1 = end (in matlab)
    00079                 };
    00080
    00082                 virtual vec eval ( const vec &x0, const vec &u0 ) {return zeros ( dimy );};
    00084                 virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full=true ) {};
    00086                 virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {};
    00088                 diffbifn () : fnc() {};
    00090                 int _dimx() const{return dimx;}
    00092                 int _dimu() const{return dimu;}
    00093 };
    00094
    00096 //TODO can be generalized into multilinear form!
    00097 class bilinfn: public diffbifn
    00098 {
    00099                 mat A;
    00100                 mat B;
    00101         public :
    00104
    00105                 bilinfn () : diffbifn () ,A() ,B()      {};
    00106                 bilinfn (const mat A0, const mat B0) {set_parameters(A0,B0);};
    00108                 void set_parameters(const mat A0, const mat B0){
    00109                         it_assert_debug(A0.rows()==B0.rows(),"");
    00110                         A=A0;B=B0;
    00111                         dimy=A.rows();
    00112                         dimx=A.cols();
    00113                         dimu=B.cols();
    00114                 }
    00116
    00119                 inline vec eval ( const  vec &x0, const vec &u0 )
    00120                 {
    00121                         it_assert_debug ( x0.length() ==dimx, "linfn::eval Wrong xcond." );
    00122                         it_assert_debug ( u0.length() ==dimu, "linfn::eval Wrong ucond." );
    00123                         return A*x0+B*u0;
    00124                 }
    00125
    00126                 void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full )
    00127                 {
    00128                         it_assert_debug ( ( F.cols() ==A.cols() ) & ( F.rows() ==A.rows() ),"Allocated F is not compatible." );
    00129                         if ( full ) F=A;        //else : nothing has changed no need to regenerate
    00130                 }
    00132                 void dfdu_cond ( const vec &x0, const vec &u0, mat &F,  bool full=true )
    00133                 {
    00134                         it_assert_debug ( ( F.cols() ==B.cols() ) & ( F.rows() ==B.rows() ),"Allocated F is not compatible." );
    00135                         if ( full ) F=B;        //else : nothing has changed no need to regenerate
    00136                 }
    00138 };
    00139
    00140 } //namespace
    00141 #endif // FN_H