Show
Ignore:
Timestamp:
08/05/09 14:40:03 (15 years ago)
Author:
mido
Message:

panove, vite, jak jsem peclivej na upravu kodu.. snad se vam bude libit:) konfigurace je v souboru /system/astylerc

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/base/datasources.h

    r384 r477  
    2828*/ 
    2929class MemDS : public DS { 
    30         protected: 
     30protected: 
    3131        //! internal matrix of data 
    3232        mat Data; 
     
    4242        void getdata ( vec &dt, const ivec &indeces ); 
    4343        void set_rvs ( RV &drv, RV &urv ); 
    44         void write ( vec &ut ) {it_error ( "MemDS::write is not supported" );} 
    45         void write ( vec &ut,ivec &indices ) {it_error ( "MemDS::write is not supported" );} 
     44        void write ( vec &ut ) { 
     45                it_error ( "MemDS::write is not supported" ); 
     46        } 
     47        void write ( vec &ut, ivec &indices ) { 
     48                it_error ( "MemDS::write is not supported" ); 
     49        } 
    4650        void step(); 
    4751        //!Default constructor 
     
    5761public: 
    5862        void getdata ( vec &dt ) { 
    59                 it_assert_debug ( dt.length() ==Data.rows(),"" ); 
    60                 dt = Data.get_col(time); 
    61         }; 
    62         void getdata ( vec &dt, const ivec &indeces ){ 
    63                 it_assert_debug ( dt.length() ==indeces.length(),"" ); 
    64                 vec tmp(indeces.length()); 
    65                 tmp = Data.get_col(time); 
    66                 dt = tmp(indeces); 
     63                it_assert_debug ( dt.length() == Data.rows(), "" ); 
     64                dt = Data.get_col ( time ); 
     65        }; 
     66        void getdata ( vec &dt, const ivec &indeces ) { 
     67                it_assert_debug ( dt.length() == indeces.length(), "" ); 
     68                vec tmp ( indeces.length() ); 
     69                tmp = Data.get_col ( time ); 
     70                dt = tmp ( indeces ); 
    6771        }; 
    6872        //! returns number of data in the file; 
    69         int ndat(){return Data.cols();} 
     73        int ndat() { 
     74                return Data.cols(); 
     75        } 
    7076        //! no sense to log this type 
    7177        void log_add ( logger &L ) {}; 
     
    7480}; 
    7581 
    76 /*!  
     82/*! 
    7783* \brief Read Data Matrix from an IT file 
    7884 
     
    8389 
    8490public: 
    85         ITppFileDS ( const string &fname, const string &varname ) :FileDS() { 
     91        ITppFileDS ( const string &fname, const string &varname ) : FileDS() { 
    8692                it_file it ( fname ); 
    87                 it << Name ( varname );  
     93                it << Name ( varname ); 
    8894                it >> Data; 
    8995                time = 0; 
     
    9197        }; 
    9298 
    93         ITppFileDS () :FileDS() { 
    94         }; 
    95  
    96         void from_setting( const Setting &set ); 
     99        ITppFileDS () : FileDS() { 
     100        }; 
     101 
     102        void from_setting ( const Setting &set ); 
    97103 
    98104        // TODO dodelat void to_setting( Setting &set ) const; 
     
    100106}; 
    101107 
    102 UIREGISTER(ITppFileDS); 
     108UIREGISTER ( ITppFileDS ); 
    103109 
    104110/*! 
     
    113119public: 
    114120        //! Constructor - create DS from a CSV file. 
    115         CsvFileDS ( const string& fname, const string& orientation = "BY_COL" ); 
     121        CsvFileDS ( const string& fname, const string& orientation = "BY_COL" ); 
    116122}; 
    117123 
     
    145151        void getdata ( vec &dt ) { 
    146152                //it_assert_debug ( dt.length() ==Drv.count(),"ArxDS" ); 
    147                 dt=H; 
     153                dt = H; 
    148154        }; 
    149155        void getdata ( vec &dt, const ivec &indices ) { 
    150                 it_assert_debug ( dt.length() ==indices.length(),"ArxDS" ); 
    151                 dt=H ( indices ); 
     156                it_assert_debug ( dt.length() == indices.length(), "ArxDS" ); 
     157                dt = H ( indices ); 
    152158        }; 
    153159        void write ( vec &ut ) { 
    154160                //it_assert_debug ( ut.length() ==Urv.count(),"ArxDS" ); 
    155                 U=ut; 
     161                U = ut; 
    156162        }; 
    157163        void write ( vec &ut, const ivec &indices ) { 
    158                 it_assert_debug ( ut.length() ==indices.length(),"ArxDS" ); 
    159                 set_subvector ( U, indices,ut ); 
     164                it_assert_debug ( ut.length() == indices.length(), "ArxDS" ); 
     165                set_subvector ( U, indices, ut ); 
    160166        }; 
    161167        void step(); 
     
    163169        ArxDS ( ) {}; 
    164170        //! Set parameters of the internal model, H is maximum time delay 
    165         void set_parameters ( const mat &Th0, const vec mu0, const chmat &sqR0 ) 
    166         { model.set_parameters ( Th0, mu0, sqR0 );}; 
     171        void set_parameters ( const mat &Th0, const vec mu0, const chmat &sqR0 ) { 
     172                model.set_parameters ( Th0, mu0, sqR0 ); 
     173        }; 
    167174        //! Set 
    168175        void set_drv ( RV &yrv, RV &urv, RV &rrv ) { 
    169176                Rrv = rrv; 
    170177                Urv = urv; 
    171                 dt_size = yrv._dsize() +urv._dsize(); 
    172  
    173                 RV drv = concat ( yrv,urv ); 
     178                dt_size = yrv._dsize() + urv._dsize(); 
     179 
     180                RV drv = concat ( yrv, urv ); 
    174181                Drv = drv; 
    175182                int td = rrv.mint(); 
    176                 H.set_size ( drv._dsize() * ( -td+1 ) ); 
     183                H.set_size ( drv._dsize() * ( -td + 1 ) ); 
    177184                U.set_size ( Urv._dsize() ); 
    178                 for ( int i=-1;i>=td;i-- ) { 
     185                for ( int i = -1; i >= td; i-- ) { 
    179186                        drv.t ( -1 ); 
    180187                        Drv.add ( drv ); //shift u1 
    181188                } 
    182                 rgrlnk.set_connection ( rrv,Drv ); 
     189                rgrlnk.set_connection ( rrv, Drv ); 
    183190 
    184191                dtsize = Drv._dsize(); 
     
    187194        //! set options from a string 
    188195        void set_options ( const string &s ) { 
    189                 opt_L_theta= ( s.find ( "L_theta" ) !=string::npos ); 
     196                opt_L_theta = ( s.find ( "L_theta" ) != string::npos ); 
    190197        }; 
    191198        virtual void log_add ( logger &L ) { 
    192199                //DS::log_add ( L ); too long!! 
    193                 L_dt=L.add ( Drv ( 0,dt_size ),"" ); 
    194                 L_ut=L.add ( Urv,"" ); 
    195  
    196                 mat &A =model._A(); 
    197                 mat R =model._R(); 
    198                 if ( opt_L_theta ) {L_theta=L.add ( RV ( "{th }", vec_1 ( A.rows() *A.cols() ) ),"t" );} 
    199                 if ( opt_L_theta ) {L_R=L.add ( RV ( "{R }", vec_1 ( R.rows() *R.cols() ) ),"r" );} 
     200                L_dt = L.add ( Drv ( 0, dt_size ), "" ); 
     201                L_ut = L.add ( Urv, "" ); 
     202 
     203                mat &A = model._A(); 
     204                mat R = model._R(); 
     205                if ( opt_L_theta ) { 
     206                        L_theta = L.add ( RV ( "{th }", vec_1 ( A.rows() * A.cols() ) ), "t" ); 
     207                } 
     208                if ( opt_L_theta ) { 
     209                        L_R = L.add ( RV ( "{R }", vec_1 ( R.rows() * R.cols() ) ), "r" ); 
     210                } 
    200211        } 
    201212        virtual void logit ( logger &L ) { 
     
    204215                L.logit ( L_ut, U ); 
    205216 
    206                 mat &A =model._A(); 
    207                 mat R =model._R(); 
    208                 if ( opt_L_theta ) {L.logit ( L_theta,vec ( A._data(), A.rows() *A.cols() ) );}; 
    209                 if ( opt_L_theta ) {L.logit ( L_R, vec ( R._data(), R.rows() *R.rows() ) );}; 
     217                mat &A = model._A(); 
     218                mat R = model._R(); 
     219                if ( opt_L_theta ) { 
     220                        L.logit ( L_theta, vec ( A._data(), A.rows() *A.cols() ) ); 
     221                }; 
     222                if ( opt_L_theta ) { 
     223                        L.logit ( L_R, vec ( R._data(), R.rows() *R.rows() ) ); 
     224                }; 
    210225        } 
    211226 
     
    242257        Result is ARX data source offering with full history as Drv. 
    243258        */ 
    244         void from_setting( const Setting &set ); 
     259        void from_setting ( const Setting &set ); 
    245260 
    246261        // TODO dodelat void to_setting( Setting &set ) const; 
    247262}; 
    248263 
    249 UIREGISTER( ArxDS ); 
     264UIREGISTER ( ArxDS ); 
    250265 
    251266class stateDS : public DS { 
     
    264279        int L_xt; 
    265280public: 
    266         void getdata ( vec &dt0 ) {dt0=dt;} 
    267         void getdata ( vec &dt0, const ivec &indeces ) {dt0=dt ( indeces );} 
    268  
    269         stateDS ( mpdf* IM0, mpdf* OM0, int usize ) :DS ( ),IM ( IM0 ),OM ( OM0 ), 
     281        void getdata ( vec &dt0 ) { 
     282                dt0 = dt; 
     283        } 
     284        void getdata ( vec &dt0, const ivec &indeces ) { 
     285                dt0 = dt ( indeces ); 
     286        } 
     287 
     288        stateDS ( mpdf* IM0, mpdf* OM0, int usize ) : DS ( ), IM ( IM0 ), OM ( OM0 ), 
    270289                        dt ( OM0->dimension() ), xt ( IM0->dimension() ), ut ( usize ) {} 
    271290 
    272         stateDS(){} 
    273  
    274         ~stateDS() {delete IM; delete OM;} 
     291        stateDS() {} 
     292 
     293        ~stateDS() { 
     294                delete IM; 
     295                delete OM; 
     296        } 
    275297        virtual void step() { 
    276                 xt=IM->samplecond ( concat ( xt,ut ) ); 
    277                 dt=OM->samplecond ( concat ( xt,ut ) ); 
     298                xt = IM->samplecond ( concat ( xt, ut ) ); 
     299                dt = OM->samplecond ( concat ( xt, ut ) ); 
    278300        }; 
    279301 
    280302        virtual void log_add ( logger &L ) { 
    281303                DS::log_add ( L ); 
    282                 L_xt=L.add ( IM->_rv(),"true" ); 
     304                L_xt = L.add ( IM->_rv(), "true" ); 
    283305        } 
    284306        virtual void logit ( logger &L ) { 
    285307                DS::logit ( L ); 
    286                 L.logit ( L_xt,xt ); 
    287         } 
    288  
    289         /*! UI for stateDS  
     308                L.logit ( L_xt, xt ); 
     309        } 
     310 
     311        /*! UI for stateDS 
    290312 
    291313        The DS is constructed from a structure with fields: 
     
    295317                //Internal model 
    296318                IM = { type = "mpdf"; //<-- valid offspring! e.g. "mlnorm" 
    297                         rv = { //description of x_t  
     319                        rv = { //description of x_t 
    298320                                names=["name1",...]; 
    299321                                sizes=[2,1]; // optional default=[1,1...]; 
    300322                                times=[0,0]; // optional default=[0,0...]; 
    301323                                } 
    302                         rvu= { //description of  u_t  
     324                        rvu= { //description of  u_t 
    303325                                //optional default=empty 
    304                                 }        
     326                                } 
    305327 
    306328                        // remaining fields depending on the chosen type 
     
    308330                //Observation model 
    309331                OM = { type = "mpdf-offspring"; 
    310                         rv = {}; //description of d_t  
    311                         rvu = {type="internal", path="system.IM.rvu"}; //description of u_t  
    312                  
     332                        rv = {}; //description of d_t 
     333                        rvu = {type="internal", path="system.IM.rvu"}; //description of u_t 
     334 
    313335                        //remaining fields 
    314336                } 
     
    316338        \endcode 
    317339        */ 
    318         void from_setting( const Setting &set ); 
     340        void from_setting ( const Setting &set ); 
    319341 
    320342        // TODO dodelat void to_setting( Setting &set ) const; 
     
    322344}; 
    323345 
    324 UIREGISTER(stateDS); 
     346UIREGISTER ( stateDS ); 
    325347 
    326348}; //namespace