Changeset 19 for bdm/stat

Show
Ignore:
Timestamp:
02/16/08 15:12:24 (16 years ago)
Author:
smidl
Message:

Switch to CMake

Location:
bdm/stat
Files:
1 removed
6 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/libBM.cpp

    r15 r19  
    6868} 
    6969 
     70ivec 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  
    2525*/ 
    2626class RV { 
    27         int size,len; 
     27        //! size = sum of sizes 
     28        int size; 
     29        //! len = number of individual rvs 
     30        int len; 
    2831        ivec ids; 
    2932        ivec sizes; 
     
    4649 
    4750        //! Return length (number of scalars) of the RV. 
    48         int count() {return size;} 
     51        int count() const {return size;} ; 
    4952        //TODO why not inline and later?? 
    5053         
     
    6164        //! Generate new \c RV with \c time shifted by delta. 
    6265        void t(int delta); 
     66        //! generate a list of indeces, i.e. which  
     67        ivec indexlist(); 
    6368}; 
    6469 
     
    6671 
    6772 
    68 //! Class representing function of variables 
     73//! Class representing function $f(x)$ of variable $x$ represented by \c rv 
    6974class fnc { 
    7075        RV rv; 
     76public:  
     77        //! function evaluates numerical value of $f(x)$ at $x=cond$ 
     78        virtual vec eval(vec &cond){}; //Fixme: virtual? 
    7179}; 
    7280 
     
    93101//      virtual vec moment ( const int order = 1 ); 
    94102        //! Returns a sample from the density, $x \sim epdf(rv)$ 
    95         virtual vec sample (){}; 
     103        virtual vec sample ()=0; 
    96104        virtual double eval(const vec &val){}; 
    97105}; 
     
    119127*/ 
    120128class DS { 
     129protected: 
    121130        //!Observed variables, returned by \c getdata(). 
    122131        RV Drv;  
  • bdm/stat/libDS.cpp

    r18 r19  
    22#include "libDS.h" 
    33 
    4 using namespace itpp; 
     4//using namespace itpp; 
    55 
    66void MemDS::getdata(vec &dt){ 
     7        int i; 
     8         
    79        it_assert_debug(dt.length()==rowid.length(), "MemDS:getdata incompatible dt"); 
    810        for(i=0;i<rowid.length();i++){ 
     
    1214 
    1315void MemDS::getdata(vec &dt,ivec &indeces){ 
    14         int j; 
     16        int j,i; 
    1517        it_assert_debug(dt.length()==indeces.length(), "MemDS:getdata incompatible dt"); 
    1618        for(i=0;i<indeces.length();i++){ 
     
    3234} 
    3335 
    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.") 
     36MemDS::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."); 
    3739         
    38         time = max(delayes);  
     40        time = max(delays);  
    3941        Data = Dat; 
    4042} 
  • bdm/stat/libDS.h

    r18 r19  
    1515 
    1616#include <itpp/itbase.h> 
    17 //#include <std> 
     17#include "libBM.h" 
    1818 
    1919using namespace itpp; 
     
    3838        void write(vec &ut){it_error("MemDS::write is not supported");} 
    3939        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}; 
    4143 
    4244 
  • bdm/stat/libFN.cpp

    r14 r19  
    22#include "libFN.h" 
    33 
    4 using namespace itpp; 
    5  
    64using std::endl; 
    75 
    8 constfn::constfn(RV rv){ 
    9  
     6linfn linfn::evalsome ( ivec &rvind ) 
     7{ 
     8        return *this; 
    109} 
    1110 
    12 vec constfn::evalsome(ivec rvind){ 
    13          
    14 } 
     11bilinfn::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  
    22// C++ Interface: itpp_ext 
    33// 
    4 // Description:  
     4// Description: 
    55// 
    66// 
     
    1414 
    1515using namespace itpp; 
    16   
    17 class constfn : public fnc { 
    18         RV rv; 
    19         ivec indexlist; // needed by evalsome 
    20         vec val; 
    2116 
    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 
     18class 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$ 
     31class 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$ 
     47class 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};