Changeset 1066 for library/bdm/stat
- Timestamp:
- 06/09/10 16:20:11 (14 years ago)
- Location:
- library/bdm/stat
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/stat/discrete.h
r1064 r1066 163 163 UIREGISTER ( grid_fnc ); 164 164 165 //! Piecewise constant pdf on rectangular support 165 //! \brief Piecewise constant pdf on rectangular support 166 //! 166 167 //! Each point on the grid represents a centroid around which the density is constant. 167 168 //! This is a trivial point-mass density where all points have the same mass. … … 177 178 return log ( values ( sup.linear_index ( sup.nearest_point ( val ) ) ) ); 178 179 } 179 180 180 }; 181 181 } -
library/bdm/stat/emix.h
r1064 r1066 105 105 class emix; //forward 106 106 107 /*! Base class (Interface) for mixtures 108 */ 107 //! \brief Base class (interface) for mixtures 109 108 class emix_base : public epdf { 110 109 protected: … … 188 187 } 189 188 190 //! Load from structure with elements: 191 //! \code 192 //! { class='emix'; 193 //! pdfs = (..., ...); // list of pdfs in the mixture 194 //! weights = ( 0.5, 0.5 ); // weights of pdfs in the mixture 195 //! } 196 //! \endcode 197 //!@} 189 /*! Create object from the following structure 190 191 \code 192 class = 'emix'; 193 194 pdfs = { list of any bdm::pdf offsprings }; % pdfs in the mixture, bdm::pdf::from_setting 195 weights = [... ]; % vector of weights of pdfs in the mixture 196 --- inherited fields --- 197 bdm::emix_base::from_setting 198 \endcode 199 200 */ 198 201 void from_setting ( const Setting &set ); 202 199 203 void to_setting (Setting &set) const; 200 204 … … 270 274 //!@} 271 275 void from_setting ( const Setting &set ) ; 272 void 276 void to_setting (Setting &set) const; 273 277 274 278 … … 278 282 279 283 280 //! Product of independent epdfs. For dependent pdfs, use mprod.284 //! \brief Base class (interface) for bdm::eprod 281 285 class eprod_base: public epdf { 282 286 protected: … … 335 339 }; 336 340 341 //! \brief Product of independent epdfs. For dependent pdfs, use bdm::mprod. 337 342 class eprod: public eprod_base { 338 343 protected: … … 348 353 factors = epdfs0; 349 354 } 355 356 /*! Create object from the following structure 357 358 \code 359 class = 'eprod'; 360 pdfs = { list of any bdm::epdf offsprings }; % pdfs in the product, bdm::epdf::from_setting 361 --- inherited fields --- 362 bdm::eprod_base::from_setting 363 \endcode 364 365 */ 350 366 void from_setting(const Setting &set) { 351 367 UI::get(factors,set,"pdfs",UI::compulsory); … … 354 370 UIREGISTER(eprod); 355 371 356 //! similar to eprod but used only internally -- factors are external pointers372 //! \brief Internal class similar to eprod - factors are external pointers. To be used only internally! 357 373 class eprod_internal: public eprod_base { 358 374 protected: … … 402 418 //!@} 403 419 void from_setting ( const Setting &set ); 404 void 420 void to_setting (Setting &set) const; 405 421 virtual void validate(); 406 422 }; … … 409 425 410 426 411 //! Base class for all BM running as parallel update of internal BMs 412 427 //! \brief Base class for all BM running as parallel update of internal BMs 413 428 class ProdBMBase : public BM { 414 429 protected : -
library/bdm/stat/exp_family.h
r1064 r1066 36 36 class eEF : public epdf { 37 37 public: 38 // 38 // eEF() :epdf() {}; 39 39 //! default constructor 40 40 eEF () : epdf () {}; … … 216 216 return R.to_mat(); 217 217 } 218 // 218 // mlnorm<sq_T>* condition ( const RV &rvn ) const ; <=========== fails to cmpile. Why? 219 219 shared_ptr<pdf> condition ( const RV &rvn ) const; 220 220 … … 450 450 } 451 451 452 /*! Create Gauss-inverse-Wishart density 453 \f[ f(rv) = GiW(V,\nu) \f] 454 from structure 452 /*! Create object from the following structure 455 453 \code 454 456 455 class = 'egiw'; 457 V.L = []; // L part of matrix V 458 V.D = []; // D part of matrix V 459 -or- V = [] // full matrix V 460 -or- dV = []; // vector of diagonal of V (when V not given) 461 nu = []; // scalar \nu ((almost) degrees of freedom) 462 // when missing, it will be computed to obtain proper pdf 463 dimx = []; // dimension of the wishart part 464 rv = RV({'name'}) // description of RV 465 rvc = RV({'name'}) // description of RV in condition 456 dimx = [...]; % dimension of the wishart part 457 V.L = [...]; % L part of matrix V 458 V.D = [...]; % D part of matrix V 459 -or- V = [...]; % full matrix V 460 -or- dV = [...]; % vector of diagonal of V (when V not given) 461 462 rv = RV({'names',...},[sizes,...],[times,...]); % description of RV 463 rvc = RV({'names',...},[sizes,...],[times,...]); % description of RV in condition 464 465 --- optional fields --- 466 nu = []; % scalar \nu ((almost) degrees of freedom) 467 --- inherited fields --- 468 bdm::eEF::from_setting 466 469 \endcode 470 471 fulfilling formula \f[ f(rv) = GiW(V,\nu) \f] 472 473 If \nu is not given, it will be computed to obtain proper pdf. 467 474 468 475 \sa log_level_enums … … 696 703 */ 697 704 void from_setting ( const Setting &set ); 698 void 705 void to_setting (Setting &set) const; 699 706 void validate(); 700 707 }; … … 855 862 \code 856 863 class = 'egamma'; 857 alpha = [...]; % vector ofalpha858 beta = [...]; % vector ofbeta864 alpha = [...]; % vector alpha 865 beta = [...]; % vector beta 859 866 --- inherited fields --- 860 867 bdm::eEF::from_setting … … 910 917 class emix : public epdf { 911 918 protected: 912 913 914 919 int n; 920 vec &w; 921 Array<epdf*> Coms; 915 922 public: 916 923 //! Default constructor 917 918 919 924 emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {}; 925 void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;} 926 vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;}; 920 927 }; 921 928 */ … … 980 987 */ 981 988 void from_setting ( const Setting &set ); 982 void 989 void to_setting (Setting &set) const; 983 990 void validate(); 984 991 }; … … 1003 1010 iepdf.set_parameters ( -delta, delta ); 1004 1011 } 1005 void 1012 void to_setting (Setting &set) const { 1006 1013 pdf::to_setting ( set ); 1007 1014 UI::save( iepdf.mean(), set, "delta"); … … 1028 1035 //! Constant additive term 1029 1036 vec mu_const; 1030 // 1037 // vec& _mu; //cached epdf.mu; !!!!!! WHY NOT? 1031 1038 public: 1032 1039 //! \name Constructors … … 1128 1135 class mgnorm : public pdf_internal< enorm< sq_T > > { 1129 1136 private: 1130 // 1137 // vec μ WHY NOT? 1131 1138 shared_ptr<fnc> g; 1132 1139 … … 1148 1155 1149 1156 R = [1, 0; // covariance matrix 1150 1151 1157 0, 1]; 1158 --OR -- 1152 1159 dR = [1, 1]; // diagonal of cavariance matrix 1153 1160 … … 1214 1221 public: 1215 1222 mlstudent () : mlnorm<ldmat, enorm> (), 1216 Lambda (), 1223 Lambda (), _R ( iepdf._R() ) {} 1217 1224 //! constructor function 1218 1225 void set_parameters ( const mat &A0, const vec &mu0, const ldmat &R0, const ldmat& Lambda0 ) { … … 1276 1283 */ 1277 1284 void from_setting ( const Setting &set ); 1278 void 1285 void to_setting (Setting &set) const; 1279 1286 void validate(); 1280 1287 }; … … 1324 1331 }; 1325 1332 1326 void 1333 void validate () { 1327 1334 pdf_internal<eigamma>::validate(); 1328 1335 dimc = dimension(); … … 1362 1369 }; 1363 1370 1364 void 1371 void validate () { 1365 1372 mgamma::validate(); 1366 1373 dimc = dimension(); … … 1607 1614 } 1608 1615 1609 virtual void 1616 virtual void validate () { 1610 1617 epdf::validate(); 1611 1618 W.validate(); … … 1637 1644 X.inv ( iX ); 1638 1645 // compute 1639 // 1646 // \frac{ |\Psi|^{m/2}|X|^{-(m+p+1)/2}e^{-tr(\Psi X^{-1})/2} }{ 2^{mp/2}\Gamma_p(m/2)}, 1640 1647 mat M = Y.to_mat() * iX.to_mat(); 1641 1648 … … 1643 1650 //Fixme! Multivariate gamma omitted!! it is ok for sampling, but not otherwise!! 1644 1651 1645 /* 1646 1647 1648 1649 1650 1651 1652 /* if (0) { 1653 mat XX=X.to_mat(); 1654 mat YY=Y.to_mat(); 1655 1656 double log2 = 0.5*p*log(det(YY))-0.5*(delta+p+1)*log(det(XX))-0.5*trace(YY*inv(XX)); 1657 cout << log1 << "," << log2 << endl; 1658 }*/ 1652 1659 return log1; 1653 1660 }; … … 1746 1753 samples = Av; 1747 1754 }; 1748 virtual void 1755 virtual void validate (); 1749 1756 //! Potentially dangerous, use with care. 1750 1757 vec& _w() { … … 1799 1806 \code 1800 1807 class = 'eEmp'; 1801 samples = [...]; 1802 w = [...]; 1808 samples = [...]; % array of samples 1809 w = [...]; % weights of samples stored in vector 1803 1810 --- inherited fields --- 1804 1811 bdm::epdf::from_setting … … 1853 1860 // template<class sq_T> 1854 1861 // void enorm<sq_T>::tupdate ( double phi, mat &vbar, double nubar ) { 1855 // 1862 // // 1856 1863 // }; 1857 1864 … … 1869 1876 // template<class sq_T> 1870 1877 // double enorm<sq_T>::eval ( const vec &val ) const { 1871 // 1872 // 1873 // 1874 // 1878 // double pdfl,e; 1879 // pdfl = evallog ( val ); 1880 // e = exp ( pdfl ); 1881 // return e; 1875 1882 // }; 1876 1883 … … 1892 1899 // template<class sq_T> 1893 1900 // vec mlnorm<sq_T>::samplecond (const vec &cond, double &lik ) { 1894 // 1895 // 1896 // 1897 // 1901 // this->condition ( cond ); 1902 // vec smp = epdf.sample(); 1903 // lik = epdf.eval ( smp ); 1904 // return smp; 1898 1905 // } 1899 1906 1900 1907 // template<class sq_T> 1901 1908 // mat mlnorm<sq_T>::samplecond (const vec &cond, vec &lik, int n ) { 1902 // 1903 // 1904 // 1905 // 1906 // 1909 // int i; 1910 // int dim = rv.count(); 1911 // mat Smp ( dim,n ); 1912 // vec smp ( dim ); 1913 // this->condition ( cond ); 1907 1914 // 1908 // 1909 // 1910 // 1911 // 1912 // 1915 // for ( i=0; i<n; i++ ) { 1916 // smp = epdf.sample(); 1917 // lik ( i ) = epdf.eval ( smp ); 1918 // Smp.set_col ( i ,smp ); 1919 // } 1913 1920 // 1914 // 1921 // return Smp; 1915 1922 // } 1916 1923