Changeset 634

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

Dirichlet sampling with unit test

Location:
library
Files:
1 added
2 modified

Legend:

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

    r629 r634  
    297297                //!@} 
    298298 
     299                //! using sampling procedure from wikipedia 
    299300                vec sample() const { 
    300                         bdm_error ("Not implemented"); 
    301                         return vec(); 
     301                        vec y(beta.length()); 
     302                        for (int i=0; i<beta.length(); i++){ 
     303                                GamRNG.setup(beta(i),1); 
     304                                y(i)=GamRNG.sample(); 
     305                        } 
     306                        return y/sum(y); 
    302307                } 
    303308 
    304309                vec mean() const {return beta / sum (beta);}; 
    305                 vec variance() const {double gamma = sum (beta); return elem_mult (beta, (beta + 1)) / (gamma* (gamma + 1));} 
     310                vec variance() const {double gamma = sum (beta); return elem_mult (beta, (gamma-beta)) / (gamma*gamma* (gamma + 1));} 
    306311                //! In this instance, val is ... 
    307312                double evallog_nn (const vec &val) const { 
     
    321326                //!access function 
    322327                vec& _beta()  {return beta;} 
    323                 //!Set internal parameters 
    324 }; 
     328                /*! configuration structure  
     329                \code  
     330                class = 'eDirich';     
     331                beta  = [];           //parametr beta 
     332                \endcode 
     333                */ 
     334                void from_setting(const Setting &set){ 
     335                        epdf::from_setting(set); 
     336                        UI::get(beta,set, "beta", UI::compulsory); 
     337                        validate(); 
     338                } 
     339                void validate() { 
     340                        //check rv 
     341                        dim = beta.length(); 
     342                } 
     343}; 
     344UIREGISTER(eDirich); 
    325345 
    326346//! \brief Estimator for Multinomial density 
  • library/tests/epdf_test.cpp

    r547 r634  
    7575        CHECK_CLOSE ( observed, actual, 0.1 ); 
    7676} 
     77 
     78TEST(test_dirich){ 
     79        epdf_harness::test_config ( "edirich.cfg" ); 
     80}