Legend:
- Unmodified
- Added
- Removed
-
bdm/stat/libBM.cpp
r15 r19 68 68 } 69 69 70 ivec RV::indexlist(){ 71 ivec indlist(size); 72 int i; 73 int pos = 0; 74 for(i=0;i<len;i++){ 75 indlist.set_subvector(pos,pos+sizes(i)-1, ids(i)); 76 } 77 } -
bdm/stat/libBM.h
r18 r19 25 25 */ 26 26 class RV { 27 int size,len; 27 //! size = sum of sizes 28 int size; 29 //! len = number of individual rvs 30 int len; 28 31 ivec ids; 29 32 ivec sizes; … … 46 49 47 50 //! Return length (number of scalars) of the RV. 48 int count() {return size;}51 int count() const {return size;} ; 49 52 //TODO why not inline and later?? 50 53 … … 61 64 //! Generate new \c RV with \c time shifted by delta. 62 65 void t(int delta); 66 //! generate a list of indeces, i.e. which 67 ivec indexlist(); 63 68 }; 64 69 … … 66 71 67 72 68 //! Class representing function of variables73 //! Class representing function $f(x)$ of variable $x$ represented by \c rv 69 74 class fnc { 70 75 RV rv; 76 public: 77 //! function evaluates numerical value of $f(x)$ at $x=cond$ 78 virtual vec eval(vec &cond){}; //Fixme: virtual? 71 79 }; 72 80 … … 93 101 // virtual vec moment ( const int order = 1 ); 94 102 //! Returns a sample from the density, $x \sim epdf(rv)$ 95 virtual vec sample () {};103 virtual vec sample ()=0; 96 104 virtual double eval(const vec &val){}; 97 105 }; … … 119 127 */ 120 128 class DS { 129 protected: 121 130 //!Observed variables, returned by \c getdata(). 122 131 RV Drv; -
bdm/stat/libDS.cpp
r18 r19 2 2 #include "libDS.h" 3 3 4 using namespace itpp;4 //using namespace itpp; 5 5 6 6 void MemDS::getdata(vec &dt){ 7 int i; 8 7 9 it_assert_debug(dt.length()==rowid.length(), "MemDS:getdata incompatible dt"); 8 10 for(i=0;i<rowid.length();i++){ … … 12 14 13 15 void MemDS::getdata(vec &dt,ivec &indeces){ 14 int j ;16 int j,i; 15 17 it_assert_debug(dt.length()==indeces.length(), "MemDS:getdata incompatible dt"); 16 18 for(i=0;i<indeces.length();i++){ … … 32 34 } 33 35 34 MemDS::MemDS( vec&Dat, ivec &rowid, ivec &delays){35 it_assert_debug(max(rowid)<=Dat.rows ,"MemDS rowid is too high for given Dat.")36 it_assert_debug(max(delays)<Dat.cols ,"MemDS delays are too high.")36 MemDS::MemDS(mat &Dat, ivec &rowid, ivec &delays){ 37 it_assert_debug(max(rowid)<=Dat.rows(),"MemDS rowid is too high for given Dat."); 38 it_assert_debug(max(delays)<Dat.cols(),"MemDS delays are too high."); 37 39 38 time = max(delay es);40 time = max(delays); 39 41 Data = Dat; 40 42 } -
bdm/stat/libDS.h
r18 r19 15 15 16 16 #include <itpp/itbase.h> 17 //#include <std> 17 #include "libBM.h" 18 18 19 19 using namespace itpp; … … 38 38 void write(vec &ut){it_error("MemDS::write is not supported");} 39 39 void write(vec &ut,ivec &indexes){it_error("MemDS::write is not supported");} 40 } 40 void step(); 41 MemDS(mat &Dat, ivec &rowid, ivec &delays); 42 }; 41 43 42 44 -
bdm/stat/libFN.cpp
r14 r19 2 2 #include "libFN.h" 3 3 4 using namespace itpp;5 6 4 using std::endl; 7 5 8 constfn::constfn(RV rv){ 9 6 linfn linfn::evalsome ( ivec &rvind ) 7 { 8 return *this; 10 9 } 11 10 12 vec constfn::evalsome(ivec rvind){ 13 14 } 11 bilinfn::bilinfn ( const RV &x0, const RV &u0, const mat &A0, const mat &B0 ) 12 { 13 it_assert_debug ( A0.cols() ==A0.rows() ==x0.count(), "linfn:: wrong A" ); 14 it_assert_debug ( ( B0.rows() ==x0.count() ) & ( B0.cols() ==u0.count() ), "linfn:: wrong B" ); 15 16 A = A0; 17 B = B0; 18 rv=x0; rv.add ( u0 ); 19 indexlist=rv.indexlist(); 20 }; 21 -
bdm/stat/libFN.h
r15 r19 2 2 // C++ Interface: itpp_ext 3 3 // 4 // Description: 4 // Description: 5 5 // 6 6 // … … 14 14 15 15 using namespace itpp; 16 17 class constfn : public fnc {18 RV rv;19 ivec indexlist; // needed by evalsome20 vec val;21 16 22 public: 23 vec eval() {return val;}; 24 vec eval(vec &cond) {return val;}; 25 26 vec evalsome(ivec &rvind); 27 } 17 //! class representing function $f(x) = a$, here rv is empty 18 class constfn : public fnc 19 { 20 RV rv; 21 vec val; 22 23 public: 24 vec eval() {return val;}; 25 vec eval ( vec &cond ) {return val;}; 26 //!Default constructor 27 constfn ( const vec &val0 ) :rv(),val ( val0 ) {}; 28 }; 29 30 //! Class representing function $f(x) = Ax+B$ 31 class linfn: public fnc 32 { 33 RV rv; 34 ivec indexlist; // needed by evalsome 35 mat A; 36 vec B; 37 public : 38 vec eval ( vec &cond ) {it_assert_debug ( cond.length() ==rv.count(), "linfn::eval Wrong cond." );return A*cond+B;}; 39 40 linfn evalsome ( ivec &rvind ); 41 linfn ( const RV &rv0 ) :rv ( rv0 ),A ( eye ( rv0.count() ) ),B ( zeros ( rv0.count() ) ) { indexlist=rv.indexlist();}; 42 linfn ( const RV &rv0, const mat &A0 ) : rv ( rv0 ), A ( A0 ), B ( zeros ( rv0.count() ) ) { indexlist=rv.indexlist();}; 43 linfn ( const RV &rv0, const mat &A0, const vec &B0 ) :rv ( rv0 ), A ( A0 ), B ( B0 ) { indexlist=rv.indexlist();}; 44 }; 45 46 //! Class representing function $f(x,u) = Ax+Bu$ 47 class bilinfn: public fnc 48 { 49 RV rv; 50 ivec indexlist; // needed by evalsome 51 mat A; 52 mat B; 53 public : 54 vec eval ( vec &cond ) 55 { 56 it_assert_debug ( cond.length() ==rv.count(), "linfn::eval Wrong cond." ); 57 int sizex = A.cols(); 58 return A*cond(0,sizex-1)+B*cond(sizex,-1);//-1 = end (in matlab) 59 }; 60 vec eval ( vec &xcond, vec &ucond ) 61 { 62 it_assert_debug ( xcond.length() ==rv.count(), "linfn::eval Wrong cond." ); 63 return A*xcond+B*ucond; 64 }; 65 66 bilinfn evalsome ( ivec &rvind ); 67 bilinfn ( const RV &x0, const RV &u0 ) :A ( eye ( x0.count() ) ),B ( zeros ( x0.count(),u0.count() ) ) 68 { 69 rv=x0; rv.add ( u0 ); 70 indexlist=rv.indexlist(); 71 }; 72 bilinfn ( const RV &x0, const RV &u0, const mat &A0, const mat &B0 ); 73 };