- Main Page
- Related Pages
- Classes
- Files

# 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 #ifndef FN_H
    00013 #define FN_H
    00014
    00015 #include <itpp/itbase.h>
    00016 #include "libBM.h"
    00017
    00018 using namespace itpp;
    00019
    00021 class constfn : public fnc
    00022 {
    00024                 vec val;
    00025
    00026         public:
    00027                 //vec eval() {return val;};
    00029                 vec eval ( const vec &cond ) {return val;};
    00031                 constfn ( const vec &val0 ) :fnc(val0.length()), val ( val0 ) {};
    00032 };
    00033
    00035 class linfn: public fnc
    00036 {
    00038                 RV rv;
    00040                 mat A;
    00042                 vec B;
    00043         public :
    00044                 vec eval (const vec &cond ) {it_assert_debug ( cond.length() ==rv.count(), "linfn::eval Wrong cond." );return A*cond+B;};
    00045
    00046 //              linfn evalsome ( ivec &rvind );
    00048                 linfn ( const RV &rv0 ) : fnc(rv0.count()), rv ( rv0 ),A ( eye ( rv0.count() ) ),B ( zeros ( rv0.count() ) ) { };
    00050                 void set_parameters ( const mat &A0 , const vec &B0 ) {A=A0; B=B0;};
    00051 };
    00052
    00053
    00063 class diffbifn: public fnc
    00064 {
    00065         protected:
    00067                 RV rvx;
    00069                 RV rvu;
    00071                 int dimx;
    00073                 int dimu;
    00074         public:
    00076                 vec eval ( const vec &cond )
    00077                 {
    00078                         it_assert_debug ( cond.length() == ( dimx+dimu ), "linfn::eval Wrong cond." );
    00079                         return eval ( cond ( 0,dimx-1 ),cond ( dimx,dimx+dimu ) );//-1 = end (in matlab)
    00080                 };
    00081
    00083                 virtual vec eval ( const vec &x0, const vec &u0 ) {return zeros ( dimy );};
    00085                 virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full=true ) {};
    00087                 virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {};
    00089                 diffbifn (int dimy, const RV rvx0, const RV rvu0 ) : fnc(dimy), rvx ( rvx0 ),rvu ( rvu0 ) {dimx=rvx.count();dimu=rvu.count();};
    00091                 int _dimx() const{return dimx;}
    00093                 int _dimu() const{return dimu;}
    00094 };
    00095
    00097 //TODO can be generalized into multilinear form!
    00098 class bilinfn: public diffbifn
    00099 {
    00100                 mat A;
    00101                 mat B;
    00102         public :
    00103                 vec eval ( const  vec &x0, const vec &u0 );
    00104
    00106                 bilinfn ( const RV &rvx0, const RV &rvu0 ) : diffbifn (dimx, rvx0,rvu0 ) ,A ( eye ( dimx ) ),B ( zeros ( dimx,dimu ) )  {};
    00108                 bilinfn ( const RV &rvx0, const RV &rvu0, const mat &A0, const mat &B0 );
    00110                 void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full )
    00111                 {
    00112                         it_assert_debug ( ( F.cols() ==A.cols() ) & ( F.rows() ==A.rows() ),"Allocated F is not compatible." );
    00113                         if ( full ) F=A;        //else : nothing has changed no need to regenerate
    00114                 }
    00116                 void dfdu_cond ( const vec &x0, const vec &u0, mat &F,  bool full=true )
    00117                 {
    00118                         it_assert_debug ( ( F.cols() ==B.cols() ) & ( F.rows() ==B.rows() ),"Allocated F is not compatible." );
    00119                         if ( full ) F=B;        //else : nothing has changed no need to regenerate
    00120                 }
    00121 };
    00122
    00123 #endif // FN_H