Changeset 1079 for library/bdm/stat/merger.h
- Timestamp:
- 06/10/10 21:54:57 (14 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/stat/merger.h
r1072 r1079 32 32 //! weights of the sources -- no restrictions 33 33 vec w; 34 //! get ith source34 //! source pdfs -- conditioning allowed 35 35 Array<shared_ptr<epdf> > sources; 36 36 //! merge 37 v oid merge() NOT_IMPLEMENTED_VOID;37 virtual void merge() NOT_IMPLEMENTED_VOID; 38 38 //! 39 39 //! check if all epdfs are on the same support 40 void validate () {40 void validate_sources() { 41 41 int n=sources.length(); 42 42 … … 75 75 vec mea=zeros(dim); 76 76 // go through all sources 77 epdf * si; 77 78 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(); 79 84 sq_T wCi = Ci; wCi*=w(i); 80 vec mi = s ources(i)->mean();85 vec mi = si->mean(); 81 86 switch (method) { 82 87 case ARITHMETIC:{ … … 133 138 However, 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$. 134 139 For merging of more general cases, use offsprings merger_mix and merger_grid. 140 141 \TODO use sources for extensions 135 142 */ 136 class merger_base : public epdf{143 class MergerDiscrete : public MergerBase { 137 144 protected: 138 //! Elements of composition 139 Array<shared_ptr<pdf> > pdfs;140 145 //! partial sources 146 Array<shared_ptr< pdf > > part_sources; 147 141 148 //! Data link for each pdf in pdfs 142 149 Array<datalink_m2e*> dls; … … 177 184 178 185 //! 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 ) { 180 187 } 181 188 182 189 //!Constructor from sources 183 merger_base ( const Array<shared_ptr<pdf> > &S );190 MergerDiscrete ( const Array<shared_ptr<pdf> > &S ); 184 191 185 192 //! 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 ); 187 194 188 195 //! Set support points from rectangular grid … … 205 212 206 213 //! 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 ) { 208 215 METHOD = MTH; 209 216 beta = beta0; … … 216 223 217 224 //! Destructor 218 virtual ~ merger_base() {225 virtual ~MergerDiscrete() { 219 226 for ( int i = 0; i < Nsources; i++ ) { 220 227 delete dls ( i ); … … 229 236 230 237 //!Merge given sources in given points 231 v irtual void merge ();238 void merge (); 232 239 233 240 //! Merge log-likelihood values in points using method specified by parameter METHOD 234 241 vec merge_points ( mat &lW ); 235 242 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 //!@} 252 244 253 245 //! \name Access to attributes … … 258 250 return eSmp; 259 251 } 252 253 eEmp & merger() {return eSmp;} 260 254 261 255 /*! Create object from the following structure … … 279 273 //!@} 280 274 }; 281 UIREGISTER ( merger_base );282 SHAREDPTR ( merger_base );275 UIREGISTER ( MergerDiscrete ); 276 SHAREDPTR ( MergerDiscrete ); 283 277 284 278 //! \brief Merger using importance sampling with mixture proposal density 285 class merger_mix : public merger_base {279 class merger_mix : public MergerDiscrete { 286 280 protected: 287 281 //!Internal mixture of EF models … … 311 305 //! Set sources and prepare all internal structures 312 306 void set_sources ( const Array<shared_ptr<pdf> > &S ) { 313 merger_base::set_sources ( S );307 MergerDiscrete::set_sources ( S ); 314 308 //Nsources = S.length(); 315 309 } … … 349 343 emix* proposal() { 350 344 emix* tmp = Mix.epredictor(); 351 tmp->set_rv ( rv);345 tmp->set_rv ( merger()._rv() ); 352 346 return tmp; 353 347 } … … 376 370 void validate(); 377 371 372 // const emix &merger(){return *Mpred;} 378 373 //! @} 379 374 };