Show
Ignore:
Timestamp:
06/10/10 21:54:57 (14 years ago)
Author:
smidl
Message:

Changes in merger + change in loading ARX

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/stat/merger.h

    r1072 r1079  
    3232                //! weights of the sources -- no restrictions 
    3333                vec w; 
    34                 //! get ith source 
     34                //! source pdfs -- conditioning allowed 
    3535                Array<shared_ptr<epdf> > sources; 
    3636                //! merge  
    37                 void merge() NOT_IMPLEMENTED_VOID; 
     37                virtual void merge() NOT_IMPLEMENTED_VOID; 
    3838                //!  
    3939                //! check if all epdfs are on the same support 
    40                 void validate() { 
     40                void validate_sources() { 
    4141                        int n=sources.length(); 
    4242                         
     
    7575                        vec mea=zeros(dim); 
    7676                        // go through all sources 
     77                        epdf * si; 
    7778                        for (int i=0; i<n; i++){ 
    78                                 sq_T Ci = sources(i)->covariance(); 
     79                                si = dynamic_cast<epdf*>(sources(i).get());  // transform pdf into epdf 
     80 
     81                                if (!si) {bdm_error("Can't merger this type of pdf: " + sources(i)->to_string());} 
     82                                 
     83                                sq_T Ci = si->covariance(); 
    7984                                sq_T wCi = Ci; wCi*=w(i); 
    80                                 vec mi = sources(i)->mean(); 
     85                                vec mi = si->mean(); 
    8186                                switch (method) { 
    8287                                        case ARITHMETIC:{ 
     
    133138However, these operations can not be performed in general. Hence, this class merges only sources on common support, \f$ y_i={}, z_i={}, \forall i \f$. 
    134139For merging of more general cases, use offsprings merger_mix and merger_grid. 
     140 
     141\TODO use sources for extensions 
    135142*/ 
    136 class merger_base : public epdf { 
     143class MergerDiscrete : public MergerBase { 
    137144protected: 
    138     //! Elements of composition 
    139     Array<shared_ptr<pdf> > pdfs; 
    140  
     145        //! partial sources 
     146        Array<shared_ptr< pdf > > part_sources; 
     147         
    141148    //! Data link for each pdf in pdfs 
    142149    Array<datalink_m2e*> dls; 
     
    177184 
    178185    //! Default constructor 
    179     merger_base () : Npoints ( 0 ), Nsources ( 0 ), DBG ( false ), dbg_file ( 0 ) { 
     186    MergerDiscrete () : Npoints ( 0 ), Nsources ( 0 ), DBG ( false ), dbg_file ( 0 ) { 
    180187    } 
    181188 
    182189    //!Constructor from sources 
    183     merger_base ( const Array<shared_ptr<pdf> > &S ); 
     190    MergerDiscrete ( const Array<shared_ptr<pdf> > &S ); 
    184191 
    185192    //! Function setting the main internal structures 
    186     void set_sources ( const Array<shared_ptr<pdf> > &Sources ); 
     193    void set_sources ( const Array<shared_ptr<pdf> > &PartSources ); 
    187194 
    188195    //! Set support points from rectangular grid 
     
    205212 
    206213    //! Set internal parameters used in approximation 
    207     void set_method ( MERGER_METHOD MTH = DFLT_METHOD, double beta0 = DFLT_beta ) { 
     214    void set_method ( MERGER_METHOD MTH = GEOMETRIC, double beta0 = 1.2 ) { 
    208215        METHOD = MTH; 
    209216        beta = beta0; 
     
    216223 
    217224    //! Destructor 
    218     virtual ~merger_base() { 
     225    virtual ~MergerDiscrete() { 
    219226        for ( int i = 0; i < Nsources; i++ ) { 
    220227            delete dls ( i ); 
     
    229236 
    230237    //!Merge given sources in given points 
    231     virtual void merge (); 
     238    void merge (); 
    232239 
    233240    //! Merge log-likelihood values in points using method specified by parameter METHOD 
    234241    vec merge_points ( mat &lW ); 
    235242 
    236  
    237     //! sample from merged density 
    238 //! weight w is a 
    239     vec mean() const; 
    240  
    241     mat covariance() const; 
    242  
    243     vec variance() const; 
    244  
    245     //! Compute log-probability of argument \c val 
    246     virtual double evallog ( const vec &val ) const NOT_IMPLEMENTED(0); 
    247  
    248     //! Returns a sample, \f$ x \f$ from density \f$ f_x()\f$ 
    249     virtual vec sample() const NOT_IMPLEMENTED(0); 
    250  
    251     //!@} 
     243  //!@} 
    252244 
    253245    //! \name Access to attributes 
     
    258250        return eSmp; 
    259251    } 
     252 
     253        eEmp & merger() {return eSmp;} 
    260254 
    261255    /*! Create object from the following structure 
     
    279273    //!@} 
    280274}; 
    281 UIREGISTER ( merger_base ); 
    282 SHAREDPTR ( merger_base ); 
     275UIREGISTER ( MergerDiscrete ); 
     276SHAREDPTR ( MergerDiscrete ); 
    283277 
    284278//! \brief Merger using importance sampling with mixture proposal density 
    285 class merger_mix : public merger_base { 
     279class merger_mix : public MergerDiscrete { 
    286280protected: 
    287281    //!Internal mixture of EF models 
     
    311305    //! Set sources and prepare all internal structures 
    312306    void set_sources ( const Array<shared_ptr<pdf> > &S ) { 
    313         merger_base::set_sources ( S ); 
     307        MergerDiscrete::set_sources ( S ); 
    314308        //Nsources = S.length(); 
    315309    } 
     
    349343    emix* proposal() { 
    350344        emix* tmp = Mix.epredictor(); 
    351         tmp->set_rv ( rv ); 
     345        tmp->set_rv ( merger()._rv() ); 
    352346        return tmp; 
    353347    } 
     
    376370    void validate(); 
    377371 
     372//      const emix &merger(){return *Mpred;} 
    378373    //! @} 
    379374};