Changeset 766 for library/bdm/base

Show
Ignore:
Timestamp:
01/11/10 22:55:57 (14 years ago)
Author:
mido
Message:

abstract methods restored wherever they are meaningful
macros NOT_IMPLEMENTED and NOT_IMPLEMENTED_VOID defined to make sources shorter
emix::set_parameters and mmix::set_parameters removed, corresponding acces methods created and the corresponding validate methods improved appropriately
some compilator warnings were avoided
and also a few other things cleaned up

Location:
library/bdm/base
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/base/bdmbase.cpp

    r746 r766  
    2727}; 
    2828 
    29 int RV::init ( const string &name, int size ) { 
     29int RV::assign_id( const string &name, int size ) { 
    3030        //Refer 
    3131        int id; 
     
    8686        int id; 
    8787        for ( int i = 0; i < len; i++ ) { 
    88                 id = init ( in_names ( i ), in_sizes ( i ) ); 
     88                id = assign_id ( in_names ( i ), in_sizes ( i ) ); 
    8989                ids ( i ) = id; 
    9090        } 
     
    100100 
    101101bool RV::add ( const RV &rv2 ) { 
    102         // TODO 
    103102        if ( rv2.len > 0 ) { //rv2 is nonempty 
    104103                ivec ind = rv2.findself ( *this ); //should be -1 all the time 
     
    146145} 
    147146 
    148 shared_ptr<pdf> epdf::condition ( const RV &rv ) const { 
    149         bdm_warning ( "Not implemented" ); 
    150         return shared_ptr<pdf>(); 
    151 } 
    152  
    153 shared_ptr<epdf> epdf::marginal ( const RV &rv ) const { 
    154         bdm_warning ( "Not implemented" ); 
    155         return shared_ptr<epdf>(); 
    156 } 
     147shared_ptr<pdf> epdf::condition ( const RV &rv ) const NOT_IMPLEMENTED( shared_ptr<pdf>() ); 
     148 
     149 
     150shared_ptr<epdf> epdf::marginal ( const RV &rv ) const NOT_IMPLEMENTED( shared_ptr<epdf>() ); 
    157151 
    158152mat epdf::sample_mat ( int N ) const { 
  • library/bdm/base/bdmbase.h

    r760 r766  
    108108 
    109109        //! auxiliary function used in constructor 
    110         void init ( const Array<std::string> &in_names, const ivec &in_sizes, const ivec &in_times ); 
    111         int init ( const string &name, int size ); 
     110        void init( const Array<std::string> &in_names, const ivec &in_sizes, const ivec &in_times ); 
     111 
     112        //! auxiliary function assigning unique integer index related to the passed name and size of the random variable 
     113        int assign_id( const string &name, int size ); 
     114 
    112115        //! Private constructor from IDs, potentially dangerous since all ids must be valid! 
    113116        //! dummy is there to prevent confusion with RV(" string"); 
     
    319322 
    320323        //! log this vector 
    321         virtual void log_vector ( int id, const vec &v ) { 
    322                 bdm_error ( "Not implemented" ); 
    323         }; 
     324        virtual void log_vector ( int id, const vec &v ) = 0; 
    324325 
    325326        virtual Setting & log_to_setting ( int id ) { 
    326327                return settings ( id )->add ( Setting::TypeGroup ); 
    327328        } 
    328  
    329329        //! log this double 
    330         virtual void logit ( int id, const double &d ) { 
    331                 bdm_error ( "Not implemented" ); 
    332         }; 
     330        virtual void logit ( int id, const double &d ) = 0; 
    333331 
    334332        //! Shifts storage position for another time step. 
    335         virtual void step() { 
    336                 bdm_error ( "Not implemneted" ); 
    337         }; 
     333        virtual void step() = 0; 
    338334 
    339335        //! Finalize storing information 
     
    385381        //!dimension of the condition 
    386382        int dimc; 
     383 
    387384        //! random variable in condition 
    388385        RV rvc; 
     
    402399        pdf ( const pdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), dim ( m.dim ), rv ( m.rv ) { } 
    403400 
    404         //! copy of the current object - make sure to implement 
    405         virtual pdf* _copy_() const { 
    406                 return new pdf ( *this ); 
    407         } 
    408401        //!@} 
    409402 
     
    412405 
    413406        //! Returns a sample from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv 
    414         virtual vec samplecond ( const vec &cond ) { 
    415                 bdm_error ( "Not implemented" ); 
    416                 return vec(); 
    417         } 
     407        virtual vec samplecond ( const vec &cond ) = 0; 
    418408 
    419409        //! Returns \param N samples from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv 
     
    421411 
    422412        //! Shortcut for conditioning and evaluation of the internal epdf. In some cases,  this operation can be implemented efficiently. 
    423         virtual double evallogcond ( const vec &yt, const vec &cond ) { 
    424                 bdm_error ( "Not implemented" ); 
    425                 return 0.0; 
    426         } 
     413        virtual double evallogcond ( const vec &yt, const vec &cond ) = 0; 
    427414 
    428415        //! Matrix version of evallogcond 
     
    521508        } 
    522509         
    523         epdf* _copy_() const { 
    524                 return new epdf ( *this ); 
    525         } 
    526510        //!@} 
    527511 
     
    530514 
    531515        //! Returns a sample, \f$ x \f$ from density \f$ f_x()\f$ 
    532         virtual vec sample() const { 
    533                 bdm_error ( "not implemented" ); 
    534                 return vec(); 
    535         } 
     516        virtual vec sample() const = 0; 
    536517 
    537518        //! Returns N samples, \f$ [x_1 , x_2 , \ldots \ \f$  from density \f$ f_x(rv)\f$ 
     
    540521        //! Compute log-probability of argument \c val 
    541522        //! In case the argument is out of suport return -Infinity 
    542         virtual double evallog ( const vec &val ) const { 
    543                 bdm_error ( "not implemented" ); 
    544                 return 0.0; 
    545         } 
    546  
     523        virtual double evallog ( const vec &val ) const = 0; 
     524         
    547525        //! Compute log-probability of multiple values argument \c val 
    548526        virtual vec evallog_mat ( const mat &Val ) const; 
     
    557535        virtual shared_ptr<epdf> marginal ( const RV &rv ) const; 
    558536 
    559         //! return expected value 
    560         virtual vec mean() const { 
    561                 bdm_error ( "not implemneted" ); 
    562                 return vec(); 
    563         } 
     537        virtual vec mean() const = 0; 
    564538 
    565539        //! return expected variance (not covariance!) 
    566         virtual vec variance() const { 
    567                 bdm_error ( "not implemneted" ); 
    568                 return vec(); 
    569         } 
     540        virtual vec variance() const = 0; 
    570541 
    571542        //! Lower and upper bounds of \c percentage % quantile, returns mean-2*sigma as default 
     
    639610        //! Update \c iepdf so that it represents this pdf conditioned on \c rvc = cond 
    640611        //! This function provides convenient reimplementation in offsprings 
    641         virtual void condition ( const vec &cond ) { 
    642                 bdm_error ( "Not implemented" ); 
    643         } 
     612        virtual void condition ( const vec &cond ) = 0; 
    644613 
    645614        //!access function to iepdf 
     
    942911        } 
    943912        //! Returns full vector of observed data=[output, input] 
    944         virtual void getdata ( vec &dt ) const { 
    945                 bdm_error ( "abstract class" ); 
    946         } 
     913        virtual void getdata ( vec &dt ) const = 0; 
     914 
    947915        //! Returns data records at indeces. 
    948         virtual void getdata ( vec &dt, const ivec &indeces ) { 
    949                 bdm_error ( "abstract class" ); 
    950         } 
    951  
    952         //! Accepts action variable and schedule it for application. 
    953         virtual void write ( const vec &ut ) { 
    954                 bdm_error ( "abstract class" ); 
    955         } 
     916        virtual void getdata ( vec &dt, const ivec &indeces ) = 0; 
     917 
     918        //! Accepts action variable and schedule it for application.     
     919        virtual void write ( const vec &ut ) = 0; 
    956920 
    957921        //! Accepts action variables at specific indeces 
    958         virtual void write ( const vec &ut, const ivec &indeces ) { 
    959                 bdm_error ( "abstract class" ); 
    960         } 
     922        virtual void write ( const vec &ut, const ivec &indeces ) = 0; 
    961923 
    962924        //! Moves from \f$ t \f$ to \f$ t+1 \f$, i.e. perfroms the actions and reads response of the system. 
    963         virtual void step() { 
    964                 bdm_error ( "abstract class" ); 
    965         } 
     925        virtual void step() = 0; 
    966926 
    967927        //! Register DS for logging into logger L 
     
    1033993//      BM ( const BM &B ) :  yrv ( B.yrv ), dimy(B.dimy), rvc ( B.rvc ),dimc(B.dimc), ll ( B.ll ), evalll ( B.evalll ) {} 
    1034994        //! \brief Copy function required in vectors, Arrays of BM etc. Have to be DELETED manually! 
    1035         //! Prototype: \code BM* _copy_() const {return new BM(*this);} \endcode 
    1036         virtual BM* _copy_() const { 
    1037                 return NULL; 
    1038         }; 
     995        //! Prototype: \code BM* _copy() const {return new BM(*this);} \endcode 
     996        virtual BM* _copy() const {             return NULL;    }; // TODO NEBUDE TU TAKY LEPSI BDM_ERROR??! 
    1039997        //!@} 
    1040998 
     
    10541012        //! This function evaluates only \f$ y_t \f$, condition is assumed to be the last used in bayes(). 
    10551013        //! See bdm::BM::predictor for conditional version. 
    1056         virtual double logpred ( const vec &yt ) const { 
    1057                 bdm_error ( "Not implemented" ); 
    1058                 return 0.0; 
    1059         } 
     1014        virtual double logpred ( const vec &yt ) const = 0; 
    10601015 
    10611016        //! Matrix version of logpred 
     
    10691024 
    10701025        //!Constructs a predictive density \f$ f(d_{t+1} |d_{t}, \ldots d_{0}) \f$ 
    1071         virtual epdf* epredictor() const { 
    1072                 bdm_error ( "Not implemented" ); 
    1073                 return NULL; 
    1074         }; 
     1026        virtual epdf* epredictor() const = 0; 
     1027 
    10751028        //!Constructs conditional density of 1-step ahead predictor \f$ f(d_{t+1} |d_{t+h-1}, \ldots d_{t}) \f$ 
    1076         virtual pdf* predictor() const { 
    1077                 bdm_error ( "Not implemented" ); 
    1078                 return NULL; 
    1079         }; 
     1029        virtual pdf* predictor() const = 0; 
     1030 
    10801031        //!@} 
    10811032 
  • library/bdm/base/datasources.h

    r738 r766  
    129129        } 
    130130 
     131        //! Accepts action variable and schedule it for application.     
     132        virtual void write ( const vec &ut ) NOT_IMPLEMENTED_VOID; 
     133                 
     134        //! Accepts action variables at specific indeces 
     135        virtual void write ( const vec &ut, const ivec &indeces ) NOT_IMPLEMENTED_VOID; 
     136 
    131137        /*! 
    132138        \code 
     
    182188        } 
    183189 
     190 
     191        //! Returns data records at indeces. 
     192        virtual void getdata ( vec &dt, const ivec &indeces ) NOT_IMPLEMENTED_VOID; 
     193 
     194 
    184195        /*! 
    185196        \code 
     
    353364        } 
    354365 
     366        virtual void write ( const vec &ut, const ivec &indeces ) NOT_IMPLEMENTED_VOID; 
     367 
    355368        /*! UI for stateDS 
    356369 
  • library/bdm/base/loggers.cpp

    r737 r766  
    4848 
    4949void memlog::from_setting ( const Setting &set ) { 
    50         // TODO tady se natvrdo ocekava existence stringu, nejsou zadne defaulty.. je to tak OK? 
    5150        UI::get ( maxlen,  set, "maxlen", UI::compulsory ); 
    5251        UI::get ( filename, set, "filename" ); 
     
    174173 
    175174void dirfilelog::from_setting ( const Setting &set ) { 
    176         // TODO tady se natvrdo ocekava existence stringu, nejsou zadne defaulty.. je to tak OK? 
    177175        dirname = ( const char* ) set["dirname"]; 
    178176        maxlen = set["maxlen"]; 
  • library/bdm/base/loggers.h

    r737 r766  
    7878        /*! \brief UI for memlog 
    7979 
    80         TODO dat tam kam patri, a to celej blok 
    81  
    8280        \code 
    8381        logger = { 
     
    130128        /*! \brief UI for stdlog 
    131129 
    132         TODO dat tam kam patri, a to celej blok 
    133  
    134130        \code 
    135131        logger = { 
     
    140136        void from_setting ( const Setting &set ) { 
    141137        } 
    142  
    143138}; 
    144139UIREGISTER ( stdlog );