Changeset 637
- Timestamp:
- 09/27/09 00:58:02 (15 years ago)
- Location:
- library/bdm/stat
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/stat/exp_family.cpp
r629 r637 81 81 - 0.5 * dimx * ( m * log2 + 0.5 * ( dimx - 1 ) * log2pi ) - lg; 82 82 83 bdm_assert_debug ( ( ( -nkG - nkW ) > -Inf ) && ( ( -nkG - nkW ) < Inf ), "ARX improper" ); 83 // bdm_assert_debug ( ( ( -nkG - nkW ) > -Inf ) && ( ( -nkG - nkW ) < Inf ), "ARX improper" ); 84 if (-nkG - nkW==Inf){ 85 cout << "??" <<endl; 86 } 84 87 return -nkG - nkW; 85 88 } … … 260 263 } 261 264 262 ivec eEmp::resample (RESAMPLING_METHOD method ) {263 i vec ind = zeros_i ( n );265 void eEmp::resample ( ivec &ind, RESAMPLING_METHOD method ) { 266 ind = zeros_i ( n ); 264 267 ivec N_babies = zeros_i ( n ); 265 268 vec cumDist = cumsum ( w ); … … 334 337 } 335 338 336 339 // copy the internals according to ind 337 340 for ( i = 0; i < n; i++ ) { 338 341 if ( ind ( i ) != i ) { … … 341 344 w ( i ) = 1.0 / n; 342 345 } 343 344 return ind;345 346 } 346 347 -
library/bdm/stat/exp_family.h
r634 r637 344 344 UIREGISTER(eDirich); 345 345 346 /*! Random Walk on Dirichlet 347 Using simple assignment 348 \f[ \beta = rvc / k + \beta_c \f] 349 hence, mean value = rvc, variance = (k+1)*mean*mean; 350 351 The greater k is, the greater is the variance of the random walk; 352 353 \f$ \beta_c \f$ is used as regularizing element to avoid corner cases, i.e. when one element of rvc is zero. 354 By default is it set to 0.1; 355 */ 356 357 class mDirich: public mpdf_internal<eDirich> { 358 protected: 359 //! constant \f$ k \f$ of the random walk 360 double k; 361 //! cache of beta_i 362 vec &_beta; 363 //! stabilizing coefficient \f$ \beta_c \f$ 364 vec betac; 365 public: 366 mDirich(): mpdf_internal<eDirich>(), _beta(iepdf._beta()){}; 367 void condition (const vec &val) {_beta = val/k+betac; }; 368 /*! Create Dirichlet random walk 369 \f[ f(rv|rvc) = Di(rvc*k) \f] 370 from structure 371 \code 372 class = 'mDirich'; 373 k = 1; // multiplicative constant k 374 --- optional --- 375 rv = RV({'name'},size) // description of RV 376 beta0 = []; // initial value of beta 377 betac = []; // initial value of beta 378 \endcode 379 */ 380 void from_setting (const Setting &set) { 381 mpdf::from_setting (set); // reads rv and rvc 382 if (_rv()._dsize()>0){ 383 rvc = _rv().copy_t(-1); 384 } 385 vec beta0; 386 if (!UI::get (beta0, set, "beta0", UI::optional)){ 387 beta0 = ones(_rv()._dsize()); 388 } 389 if (!UI::get (betac, set, "betac", UI::optional)){ 390 betac = 0.1*ones(_rv()._dsize()); 391 } 392 _beta = beta0; 393 394 UI::get (k, set, "k", UI::compulsory); 395 validate(); 396 } 397 void validate() { 398 iepdf.validate(); 399 bdm_assert(_beta.length()==betac.length(),"beta0 and betac are not compatible"); 400 if (_rv()._dsize()>0){ 401 bdm_assert( (_rv()._dsize()==dimension()) , "Size of rv does not match with beta"); 402 } 403 dimc = _beta.length(); 404 }; 405 }; 406 UIREGISTER(mDirich); 407 346 408 //! \brief Estimator for Multinomial density 347 409 class multiBM : public BMEF … … 1196 1258 Array<vec>& _samples() {return samples;}; 1197 1259 //! access function 1260 const vec& _sample(int i) const {return samples(i);}; 1261 //! access function 1198 1262 const Array<vec>& _samples() const {return samples;}; 1199 1263 //! Function performs resampling, i.e. removal of low-weight samples and duplication of high-weight samples such that the new samples represent the same density. 1200 ivec resample (RESAMPLING_METHOD method = SYSTEMATIC); 1201 1264 //! The vector with indeces of new samples is returned in variable \c index. 1265 void resample ( ivec &index, RESAMPLING_METHOD method = SYSTEMATIC); 1266 1267 //! Resampling without returning index of new particles. 1268 void resample (RESAMPLING_METHOD method = SYSTEMATIC){ivec ind; resample(ind,method);}; 1269 1202 1270 //! inherited operation : NOT implemented 1203 1271 vec sample() const {