Changeset 637

Show
Ignore:
Timestamp:
09/27/09 00:58:02 (15 years ago)
Author:
smidl
Message:

new Dirichlet random walk + numerics in egiw

Location:
library/bdm/stat
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/stat/exp_family.cpp

    r629 r637  
    8181                     - 0.5 * dimx * ( m * log2 + 0.5 * ( dimx - 1 ) * log2pi )  - lg; 
    8282 
    83         bdm_assert_debug ( ( ( -nkG - nkW ) > -Inf ) && ( ( -nkG - nkW ) < Inf ), "ARX improper" ); 
     83//      bdm_assert_debug ( ( ( -nkG - nkW ) > -Inf ) && ( ( -nkG - nkW ) < Inf ), "ARX improper" ); 
     84if (-nkG - nkW==Inf){ 
     85        cout << "??" <<endl; 
     86} 
    8487        return -nkG - nkW; 
    8588} 
     
    260263} 
    261264 
    262 ivec eEmp::resample ( RESAMPLING_METHOD method ) { 
    263         ivec ind = zeros_i ( n ); 
     265void eEmp::resample ( ivec &ind, RESAMPLING_METHOD method ) { 
     266        ind = zeros_i ( n ); 
    264267        ivec N_babies = zeros_i ( n ); 
    265268        vec cumDist = cumsum ( w ); 
     
    334337        } 
    335338 
    336         // copy the internals according to ind 
     339// copy the internals according to ind 
    337340        for ( i = 0; i < n; i++ ) { 
    338341                if ( ind ( i ) != i ) { 
     
    341344                w ( i ) = 1.0 / n; 
    342345        } 
    343  
    344         return ind; 
    345346} 
    346347 
  • library/bdm/stat/exp_family.h

    r634 r637  
    344344UIREGISTER(eDirich); 
    345345 
     346/*! Random Walk on Dirichlet 
     347Using 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 
     357class 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}; 
     406UIREGISTER(mDirich); 
     407 
    346408//! \brief Estimator for Multinomial density 
    347409class multiBM : public BMEF 
     
    11961258                Array<vec>& _samples() {return samples;}; 
    11971259                //! access function 
     1260                const vec& _sample(int i) const {return samples(i);}; 
     1261                //! access function 
    11981262                const Array<vec>& _samples() const {return samples;}; 
    11991263                //! 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                 
    12021270                //! inherited operation : NOT implemented 
    12031271                vec sample() const {