Show
Ignore:
Timestamp:
08/08/09 13:42:18 (15 years ago)
Author:
smidl
Message:

1st step of mpdf redesign - BROKEN compile

Files:
1 modified

Legend:

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

    r477 r487  
    399399//! Conditional probability density, e.g. modeling some dependencies. 
    400400//TODO Samplecond can be generalized 
    401  
    402401class mpdf : public root { 
    403402protected: 
     
    406405        //! random variable in condition 
    407406        RV rvc; 
    408  
    409407private: 
    410         //! pointer to internal epdf 
    411         shared_ptr<epdf> shep; 
     408        //! internal epdf, used only as cache to avoid virtual calls of \c _rv() and \c _dimension() 
     409        epdf* ep; 
     410         
     411protected: 
     412        void set_ep(epdf &iepdf) { 
     413                ep = &iepdf; 
     414        } 
    412415 
    413416public: 
     
    415418        //! @{ 
    416419 
    417         mpdf() : dimc ( 0 ), rvc() { } 
    418  
    419         mpdf ( const mpdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), shep ( m.shep ) { } 
     420        mpdf() : dimc ( 0 ), rvc(), ep(NULL) { } 
     421 
     422        mpdf ( const mpdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), ep ( m.ep ) { } 
    420423        //!@} 
    421424 
     
    424427 
    425428        //! 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 
    426         virtual vec samplecond ( const vec &cond ); 
     429        virtual vec samplecond ( const vec &cond ){it_error("Not implemented");return vec(0);}; 
    427430 
    428431        //! 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 
    429         virtual mat samplecond_m ( const vec &cond, int N ); 
    430  
    431         //! Update \c ep so that it represents this mpdf conditioned on \c rvc = cond 
    432         virtual void condition ( const vec &cond ) { 
    433                 it_error ( "Not implemented" ); 
    434         }; 
     432        virtual mat samplecond_m ( const vec &cond, int N ){it_error("Not implemented");return mat();} 
     433 
    435434 
    436435        //! Shortcut for conditioning and evaluation of the internal epdf. In some cases,  this operation can be implemented efficiently. 
    437         virtual double evallogcond ( const vec &dt, const vec &cond ); 
     436        virtual double evallogcond ( const vec &dt, const vec &cond ){it_error("Not implemented");return 0.0;} 
    438437 
    439438        //! Matrix version of evallogcond 
    440         virtual vec evallogcond_m ( const mat &Dt, const vec &cond ); 
     439        virtual vec evallogcond_m ( const mat &Dt, const vec &cond ){it_error("Not implemented");return vec(0);} 
    441440 
    442441        //! Array<vec> version of evallogcond 
    443         virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ); 
     442        virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ){it_error("Not implemented");return vec(0);} 
    444443 
    445444        //! \name Access to attributes 
     
    447446 
    448447        RV _rv() { 
    449                 return shep->_rv(); 
     448                return ep->_rv(); 
    450449        } 
    451450        RV _rvc() { 
     
    454453        } 
    455454        int dimension() { 
    456                 return shep->dimension(); 
     455                return ep->dimension(); 
    457456        } 
    458457        int dimensionc() { 
     
    460459        } 
    461460 
    462         epdf *e() { 
    463                 return shep.get(); 
    464         } 
    465  
    466         void set_ep ( shared_ptr<epdf> ep ) { 
    467                 shep = ep; 
    468         } 
    469  
    470461        //! Load from structure with elements: 
    471462        //!  \code 
    472         //! { rv = {class="RV", names=(...),}; // RV describing meaning of random variable 
     463        //! { class = "mpdf_offspring", 
     464        //!   rv = {class="RV", names=(...),}; // RV describing meaning of random variable 
    473465        //!   rvc= {class="RV", names=(...),}; // RV describing meaning of random variable in condition 
    474466        //!   // elements of offsprings 
     
    485477        } 
    486478        void set_rv ( const RV &rv0 ) { 
    487                 shep->set_rv ( rv0 ); 
     479                ep->set_rv ( rv0 ); 
    488480        } 
    489481        bool isnamed() { 
    490                 return ( shep->isnamed() ) && ( dimc == rvc._dsize() ); 
    491         } 
    492         //!@} 
     482                return ( ep->isnamed() ) && ( dimc == rvc._dsize() ); 
     483        } 
     484        //!@} 
     485}; 
     486 
     487template <class EPDF> 
     488class mpdf_internal: public mpdf{ 
     489        protected : 
     490                EPDF iepdf; 
     491        public: 
     492                //! constructor 
     493                mpdf_internal(): mpdf(),iepdf(){set_ep(iepdf);} 
     494                //! Update \c iepdf so that it represents this mpdf conditioned on \c rvc = cond 
     495                //! This function provides convenient reimplementation in offsprings 
     496                        virtual void condition ( const vec &cond ) { 
     497                                it_error ( "Not implemented" ); 
     498                        }; 
     499                //!access function to iepdf 
     500                EPDF& e(){return iepdf;} 
     501                         
     502                //! Reimplements samplecond using \c condition() 
     503                vec samplecond ( const vec &cond ); 
     504                //! Reimplements evallogcond using \c condition() 
     505                double evallogcond ( const vec &val, const vec &cond ); 
     506                //! Efficient version of evallogcond for matrices  
     507                virtual vec evallogcond_m ( const mat &Dt, const vec &cond ); 
     508                //! Efficient version of evallogcond for Array<vec> 
     509                virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ); 
     510                //! Efficient version of samplecond  
     511                virtual mat samplecond_m ( const vec &cond, int N ); 
    493512}; 
    494513 
     
    686705*/ 
    687706class mepdf : public mpdf { 
     707 
     708shared_ptr<epdf> ipdf; 
    688709public: 
    689710        //!Default constructor 
     
    691712 
    692713        mepdf ( shared_ptr<epdf> em ) { 
    693                 set_ep ( em ); 
     714                ipdf = em; 
     715                set_ep(*ipdf.get()); 
    694716                dimc = 0; 
    695717        } 
     
    701723        //!  \code 
    702724        //! { class = "mepdf", 
    703         //!   epdfs = {class="epdfs",...} 
     725        //!   epdf = {class="epdf_offspring",...} 
    704726        //! } 
    705727        //! \endcode