Changeset 713 for library/bdm
- Timestamp:
- 11/10/09 11:03:09 (15 years ago)
- Location:
- library/bdm
- Files:
-
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.cpp
r700 r713 156 156 } 157 157 158 mat epdf::sample_m ( int N ) const {158 mat epdf::sample_mat ( int N ) const { 159 159 mat X = zeros ( dim, N ); 160 160 for ( int i = 0; i < N; i++ ) X.set_col ( i, this->sample() ); … … 162 162 } 163 163 164 vec epdf::evallog_m ( const mat &Val ) const {164 vec epdf::evallog_mat ( const mat &Val ) const { 165 165 vec x ( Val.cols() ); 166 166 for ( int i = 0; i < Val.cols(); i++ ) { … … 171 171 } 172 172 173 vec epdf::evallog_m ( const Array<vec> &Avec ) const {173 vec epdf::evallog_mat ( const Array<vec> &Avec ) const { 174 174 vec x ( Avec.size() ); 175 175 for ( int i = 0; i < Avec.size(); i++ ) { … … 180 180 } 181 181 182 mat pdf::samplecond_m ( const vec &cond, int N ) {182 mat pdf::samplecond_mat ( const vec &cond, int N ) { 183 183 mat M ( dimension(), N ); 184 184 for ( int i = 0; i < N; i++ ) { -
library/bdm/base/bdmbase.h
r712 r713 429 429 430 430 //! Returns \param N samples from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv 431 virtual mat samplecond_m ( const vec &cond, int N );431 virtual mat samplecond_mat ( const vec &cond, int N ); 432 432 433 433 //! Shortcut for conditioning and evaluation of the internal epdf. In some cases, this operation can be implemented efficiently. … … 438 438 439 439 //! Matrix version of evallogcond 440 virtual vec evallogcond_m ( const mat &Yt, const vec &cond ) {440 virtual vec evallogcond_mat ( const mat &Yt, const vec &cond ) { 441 441 vec v ( Yt.cols() ); 442 442 for ( int i = 0; i < Yt.cols(); i++ ) { … … 447 447 448 448 //! Array<vec> version of evallogcond 449 virtual vec evallogcond_m ( const Array<vec> &Yt, const vec &cond ) {449 virtual vec evallogcond_mat ( const Array<vec> &Yt, const vec &cond ) { 450 450 bdm_error ( "Not implemented" ); 451 451 return vec(); … … 534 534 535 535 //! Returns N samples, \f$ [x_1 , x_2 , \ldots \ \f$ from density \f$ f_x(rv)\f$ 536 virtual mat sample_m ( int N ) const;536 virtual mat sample_mat ( int N ) const; 537 537 538 538 //! Compute log-probability of argument \c val … … 544 544 545 545 //! Compute log-probability of multiple values argument \c val 546 virtual vec evallog_m ( const mat &Val ) const;546 virtual vec evallog_mat ( const mat &Val ) const; 547 547 548 548 //! Compute log-probability of multiple values argument \c val 549 virtual vec evallog_m ( const Array<vec> &Avec ) const;549 virtual vec evallog_mat ( const Array<vec> &Avec ) const; 550 550 551 551 //! Return conditional density on the given RV, the remaining rvs will be in conditioning … … 669 669 double evallogcond ( const vec &val, const vec &cond ); 670 670 //! Efficient version of evallogcond for matrices 671 virtual vec evallogcond_m ( const mat &Dt, const vec &cond );671 virtual vec evallogcond_mat ( const mat &Dt, const vec &cond ); 672 672 //! Efficient version of evallogcond for Array<vec> 673 virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond );673 virtual vec evallogcond_mat ( const Array<vec> &Dt, const vec &cond ); 674 674 //! Efficient version of samplecond 675 virtual mat samplecond_m ( const vec &cond, int N );675 virtual mat samplecond_mat ( const vec &cond, int N ); 676 676 677 677 void validate() { … … 1117 1117 1118 1118 //! Matrix version of logpred 1119 vec logpred_m ( const mat &Yt ) const {1119 vec logpred_mat ( const mat &Yt ) const { 1120 1120 vec tmp ( Yt.cols() ); 1121 1121 for ( int i = 0; i < Yt.cols(); i++ ) { … … 1253 1253 1254 1254 template<class EPDF> 1255 mat pdf_internal<EPDF>::samplecond_m ( const vec &cond, int N ) {1255 mat pdf_internal<EPDF>::samplecond_mat ( const vec &cond, int N ) { 1256 1256 condition ( cond ); 1257 1257 mat temp ( dimension(), N ); … … 1274 1274 1275 1275 template<class EPDF> 1276 vec pdf_internal<EPDF>::evallogcond_m ( const mat &Yt, const vec &cond ) {1276 vec pdf_internal<EPDF>::evallogcond_mat ( const mat &Yt, const vec &cond ) { 1277 1277 condition ( cond ); 1278 return iepdf.evallog_m ( Yt );1278 return iepdf.evallog_mat ( Yt ); 1279 1279 } 1280 1280 1281 1281 template<class EPDF> 1282 vec pdf_internal<EPDF>::evallogcond_m ( const Array<vec> &Yt, const vec &cond ) {1282 vec pdf_internal<EPDF>::evallogcond_mat ( const Array<vec> &Yt, const vec &cond ) { 1283 1283 condition ( cond ); 1284 return iepdf.evallog_m ( Yt );1284 return iepdf.evallog_mat ( Yt ); 1285 1285 } 1286 1286 -
library/bdm/stat/emix.h
r711 r713 159 159 return tmp; 160 160 }; 161 vec evallog_m ( const mat &Val ) const {161 vec evallog_mat ( const mat &Val ) const { 162 162 vec x = zeros ( Val.cols() ); 163 163 for ( int i = 0; i < w.length(); i++ ) { 164 x += w ( i ) * exp ( Coms ( i )->evallog_m ( Val ) );164 x += w ( i ) * exp ( Coms ( i )->evallog_mat ( Val ) ); 165 165 } 166 166 return log ( x ); 167 167 }; 168 /* 168 169 //! Auxiliary function that returns pdflog for each component 169 mat evallog_ M( const mat &Val ) const {170 mat evallog_mat ( const mat &Val ) const { 170 171 mat X ( w.length(), Val.cols() ); 171 172 for ( int i = 0; i < w.length(); i++ ) { 172 X.set_row ( i, w ( i ) *exp ( Coms ( i )->evallog_m ( Val ) ) );173 X.set_row ( i, w ( i ) *exp ( Coms ( i )->evallog_mat ( Val ) ) ); 173 174 } 174 175 return X; 175 176 }; 177 */ 176 178 177 179 shared_ptr<epdf> marginal ( const RV &rv ) const; … … 180 182 shared_ptr<pdf> condition ( const RV &rv ) const; 181 183 182 //Access methods184 //Access methods 183 185 //! returns a pointer to the internal mean value. Use with Care! 184 186 vec& _w() { … … 197 199 } 198 200 } 201 202 //! Load from structure with elements: 203 //! \code 204 //! { class='emix'; 205 //! pdfs = (..., ...); // list of pdfs in the mixture 206 //! weights = ( 0.5, 0.5 ); // weights of pdfs in the mixture 207 //! } 208 //! \endcode 209 //!@} 210 void from_setting ( const Setting &set ) { 211 UI::get ( Coms, set, "pdfs", UI::compulsory ); 212 213 if( !UI::get( w, set, "weights", UI::optional ) ) 214 { 215 int len = Coms.length(); 216 w.set_length( len ); 217 double default_weight = 1.0 / len; 218 for( int i=0; i < len; i++) 219 w(i) = default_weight; 220 } 221 } 199 222 }; 200 223 SHAREDPTR( emix ); 224 UIREGISTER ( emix ); 201 225 202 226 /*! … … 322 346 return res; 323 347 } 324 vec evallogcond_m ( const mat &Dt, const vec &cond ) {348 vec evallogcond_mat ( const mat &Dt, const vec &cond ) { 325 349 vec tmp ( Dt.cols() ); 326 350 for ( int i = 0; i < Dt.cols(); i++ ) { … … 329 353 return tmp; 330 354 }; 331 vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ) {355 vec evallogcond_mat ( const Array<vec> &Dt, const vec &cond ) { 332 356 vec tmp ( Dt.length() ); 333 357 for ( int i = 0; i < Dt.length(); i++ ) { -
library/bdm/stat/exp_family.h
r693 r713 58 58 } 59 59 //!Evaluate normalized log-probability for many samples 60 virtual vec evallog_m (const mat &Val) const {60 virtual vec evallog_mat (const mat &Val) const { 61 61 vec x (Val.cols()); 62 62 for (int i = 0;i < Val.cols();i++) {x (i) = evallog_nn (Val.get_col (i)) ;} … … 64 64 } 65 65 //!Evaluate normalized log-probability for many samples 66 virtual vec evallog_m (const Array<vec> &Val) const {66 virtual vec evallog_mat (const Array<vec> &Val) const { 67 67 vec x (Val.length()); 68 68 for (int i = 0;i < Val.length();i++) {x (i) = evallog_nn (Val (i)) ;} -
library/bdm/stat/merger.cpp
r693 r713 151 151 if ( pdfs ( i )->dimension() == dim ) { 152 152 // no need for conditioning or marginalization 153 lw_src = pdfs ( i )->evallogcond_m ( Smp , vec(0));153 lw_src = pdfs ( i )->evallogcond_mat ( Smp , vec(0)); 154 154 } else { 155 155 // compute likelihood of marginal on the conditional variable