Show
Ignore:
Timestamp:
06/22/09 13:17:49 (15 years ago)
Author:
smidl
Message:

merging works for merger_mx

Files:
1 modified

Legend:

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

    r388 r395  
    4848                        virtual double evallog_nn ( const vec &val ) const{it_error ( "Not implemented" );return 0.0;}; 
    4949                        //!Evaluate normalized log-probability 
    50                         virtual double evallog ( const vec &val ) const {double tmp;tmp= evallog_nn ( val )-lognc();it_assert_debug ( std::isfinite ( tmp ),"Infinite value" ); return tmp;} 
     50                        virtual double evallog ( const vec &val ) const { 
     51                                double tmp; 
     52                                tmp= evallog_nn ( val )-lognc(); 
     53                                it_assert_debug ( std::isfinite ( tmp ),"Infinite value" );  
     54                                return tmp;} 
    5155                        //!Evaluate normalized log-probability for many samples 
    5256                        virtual vec evallog ( const mat &Val ) const 
     
    125129                        void set_parameters ( const vec &mu,const sq_T &R ); 
    126130                        void from_setting(const Setting &root); 
     131                        void validate() { 
     132                                it_assert(mu.length()==R.rows(),"parameters mismatch"); 
     133                                dim = mu.length(); 
     134                        } 
    127135                        //!@} 
    128136 
     
    225233                        double& _nu()  {return nu;} 
    226234                        const double& _nu() const {return nu;} 
    227                         //!@} 
    228         }; 
     235                        void from_setting(const Setting &set){ 
     236                                set.lookupValue("nu",nu); 
     237                                set.lookupValue("dimx",dimx); 
     238                                mat V; 
     239                                UI::get(V,set,"V"); 
     240                                set_parameters(dimx, V, nu); 
     241                                RV* rv=UI::build<RV>(set,"rv"); 
     242                                set_rv(*rv); 
     243                                delete rv; 
     244                        } 
     245                        //!@} 
     246        }; 
     247        UIREGISTER(egiw); 
    229248 
    230249        /*! \brief Dirichlet posterior density 
     
    370389                        vec mean() const {return elem_div ( alpha,beta );} 
    371390                        vec variance() const {return elem_div ( alpha,elem_mult ( beta,beta ) ); } 
    372         }; 
    373  
     391                         
     392                        //! Load from structure with elements: 
     393                        //!  \code 
     394                        //! { alpha = [...];         // vector of alpha 
     395                        //!   beta = [...];          // vector of beta 
     396                        //!   rv = {class="RV",...}  // description 
     397                        //! } 
     398                        //! \endcode 
     399                        //!@} 
     400                        void from_setting(const Setting &set){ 
     401                                epdf::from_setting(set); // reads rv 
     402                                UI::get(alpha,set,"alpha"); 
     403                                UI::get(beta,set,"beta"); 
     404                                validate(); 
     405                        } 
     406                        void validate(){ 
     407                                it_assert(alpha.length() ==beta.length(), "parameters do not match"); 
     408                                dim =alpha.length(); 
     409                        } 
     410        }; 
     411UIREGISTER(egamma); 
    374412        /*! 
    375413         \brief Inverse-Gamma posterior density 
     
    462500                        vec mean() const {return ( high-low ) /2.0;} 
    463501                        vec variance() const {return ( pow ( high,2 ) +pow ( low,2 ) +elem_mult ( high,low ) ) /3.0;} 
     502                        //! Load from structure with elements: 
     503                        //!  \code 
     504                        //! { high = [...];          // vector of upper bounds 
     505                        //!   low = [...];           // vector of lower bounds 
     506                        //!   rv = {class="RV",...}  // description of RV 
     507                        //! } 
     508                        //! \endcode 
     509                        //!@} 
     510                        void from_setting(const Setting &set){ 
     511                                epdf::from_setting(set); // reads rv and rvc 
     512                                UI::get(high,set,"high"); 
     513                                UI::get(low,set,"low"); 
     514                        } 
    464515        }; 
    465516 
     
    650701                        void set_parameters ( double k, const vec &beta0 ); 
    651702                        void condition ( const vec &val ) {_beta=k/val;}; 
    652         }; 
    653  
     703                        //! Load from structure with elements: 
     704                        //!  \code 
     705                        //! { alpha = [...];         // vector of alpha 
     706                        //!   k = 1.1;               // multiplicative constant k 
     707                        //!   rv = {class="RV",...}  // description of RV 
     708                        //!   rvc = {class="RV",...} // description of RV in condition 
     709                        //! } 
     710                        //! \endcode 
     711                        //!@} 
     712                        void from_setting(const Setting &set){ 
     713                                mpdf::from_setting(set); // reads rv and rvc 
     714                                vec betatmp; // ugly but necessary 
     715                                UI::get(betatmp,set,"beta"); 
     716                                set.lookupValue("k",k); 
     717                                set_parameters(k,betatmp); 
     718                        } 
     719        }; 
     720        UIREGISTER(mgamma); 
     721         
    654722        /*! 
    655723        \brief  Inverse-Gamma random walk 
     
    10881156                mu = mu0; 
    10891157                R = R0; 
    1090                 dim = mu0.length(); 
    1091         }; 
    1092  
    1093         template<class sq_T> 
    1094         void enorm<sq_T>::from_setting(const Setting &root){ 
    1095                 vec mu; 
    1096                 UI::get(mu,root,"mu"); 
    1097                 mat R; 
    1098                 UI::get(R,root,"R"); 
    1099                 set_parameters(mu,R); 
     1158                validate(); 
     1159        }; 
     1160 
     1161        template<class sq_T> 
     1162        void enorm<sq_T>::from_setting(const Setting &set){ 
     1163                epdf::from_setting(set); //reads rv 
    11001164                 
    1101                 RV* r = UI::build<RV>(root,"rv"); 
    1102                 set_rv(*r);  
    1103                 delete r; 
     1165                UI::get(mu,set,"mu"); 
     1166                mat Rtmp;// necessary for conversion 
     1167                UI::get(Rtmp,set,"R"); 
     1168                R=Rtmp; // conversion 
     1169                validate(); 
    11041170        } 
    11051171