- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# functions.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 "../base/bdmbase.h"
    00016
    00017 namespace bdm {
    00018
    00020 class constfn : public fnc {
    00022         vec val;
    00023
    00024 public:
    00025         //vec eval() {return val;};
    00027         vec eval ( const vec &cond ) {
    00028                 return val;
    00029         };
    00031         constfn ( const vec &val0 ) : fnc(), val ( val0 ) {
    00032                 dimy = val.length();
    00033         };
    00034 };
    00035
    00037 class linfn: public fnc {
    00039         RV rv;
    00041         mat A;
    00043         vec B;
    00044 public :
    00045         vec eval ( const vec &cond ) {
    00046                 it_assert_debug ( cond.length() == A.cols(), "linfn::eval Wrong cond." );
    00047                 return A*cond + B;
    00048         };
    00049
    00050 //              linfn evalsome ( ivec &rvind );
    00052         linfn ( ) : fnc(), A ( ), B () { };
    00054         void set_parameters ( const mat &A0 , const vec &B0 ) {
    00055                 A = A0;
    00056                 B = B0;
    00057                 dimy = A.rows();
    00058         };
    00059 };
    00060
    00061
    00071 class diffbifn: public fnc {
    00072 protected:
    00074         RV rvx;
    00076         RV rvu;
    00078         int dimx;
    00080         int dimu;
    00081 public:
    00083         vec eval ( const vec &cond ) {
    00084                 it_assert_debug ( cond.length() == ( dimx + dimu ), "linfn::eval Wrong cond." );
    00085                 return eval ( cond ( 0, dimx - 1 ), cond ( dimx, dimx + dimu - 1 ) );//-1 = end (in matlab)
    00086         };
    00087
    00089         virtual vec eval ( const vec &x0, const vec &u0 ) {
    00090                 return zeros ( dimy );
    00091         };
    00093         virtual void dfdx_cond ( const vec &x0, const vec &u0, mat &A , bool full = true ) {};
    00095         virtual void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full = true ) {};
    00097         diffbifn () : fnc() {};
    00099         int _dimx() const {
    00100                 return dimx;
    00101         }
    00103         int _dimu() const {
    00104                 return dimu;
    00105         }
    00106 };
    00107
    00109 //TODO can be generalized into multilinear form!
    00110 class bilinfn: public diffbifn {
    00111         mat A;
    00112         mat B;
    00113 public :
    00116
    00117         bilinfn () : diffbifn () , A() , B()    {};
    00118         bilinfn ( const mat A0, const mat B0 ) {
    00119                 set_parameters ( A0, B0 );
    00120         };
    00122         void set_parameters ( const mat A0, const mat B0 ) {
    00123                 it_assert_debug ( A0.rows() == B0.rows(), "" );
    00124                 A = A0;
    00125                 B = B0;
    00126                 dimy = A.rows();
    00127                 dimx = A.cols();
    00128                 dimu = B.cols();
    00129         }
    00131
    00134         inline vec eval ( const  vec &x0, const vec &u0 ) {
    00135                 it_assert_debug ( x0.length() == dimx, "linfn::eval Wrong xcond." );
    00136                 it_assert_debug ( u0.length() == dimu, "linfn::eval Wrong ucond." );
    00137                 return A*x0 + B*u0;
    00138         }
    00139
    00140         void dfdx_cond ( const vec &x0, const vec &u0, mat &F, bool full ) {
    00141                 it_assert_debug ( ( F.cols() == A.cols() ) & ( F.rows() == A.rows() ), "Allocated F is not compatible." );
    00142                 if ( full ) F = A;      //else : nothing has changed no need to regenerate
    00143         }
    00145         void dfdu_cond ( const vec &x0, const vec &u0, mat &F,  bool full = true ) {
    00146                 it_assert_debug ( ( F.cols() == B.cols() ) & ( F.rows() == B.rows() ), "Allocated F is not compatible." );
    00147                 if ( full ) F = B;      //else : nothing has changed no need to regenerate
    00148         }
    00150 };
    00151
    00152 } //namespace
    00153 #endif // FN_H