Legend:
- Unmodified
- Added
- Removed
-
bdm/stat/emix.cpp
r178 r181 31 31 } 32 32 33 // mprod::mprod ( Array<mpdf*> mFacs, bool overlap) : mpdf ( RV(), RV() ), n ( mFacs.length() ), epdfs ( n ), mpdfs ( mFacs ), rvinds ( n ), rvcinrv ( n ), rvc inds( n ) {33 // mprod::mprod ( Array<mpdf*> mFacs, bool overlap) : mpdf ( RV(), RV() ), n ( mFacs.length() ), epdfs ( n ), mpdfs ( mFacs ), rvinds ( n ), rvcinrv ( n ), rvcsinrvc ( n ) { 34 34 // int i; 35 35 // bool rvaddok; … … 54 54 // rvcinrv ( i ) = mpdfs ( i )->_rvc().dataind ( rv ); 55 55 // // find ith rvc in common rv 56 // rvc inds( i ) = mpdfs ( i )->_rvc().dataind ( rvc );56 // rvcsinrvc ( i ) = mpdfs ( i )->_rvc().dataind ( rvc ); 57 57 // // 58 58 // /* if ( rvcinrv ( i ).length() >0 ) {independent = false;} 59 // if ( rvc inds( i ).length() >0 ) {independent = false;}*/59 // if ( rvcsinrvc ( i ).length() >0 ) {independent = false;}*/ 60 60 // } 61 61 // }; -
bdm/stat/emix.h
r178 r181 40 40 public: 41 41 //!Default constructor 42 emix ( const RV &rv ) : epdf ( rv ) {};42 emix ( const RV &rv ) : epdf ( rv ) {}; 43 43 //! Set weights \c w and components \c Coms , Coms are not copied! 44 44 void set_parameters ( const vec &w, const Array<epdf*> &Coms, bool copy=true ); … … 60 60 //! returns a pointer to the internal mean value. Use with Care! 61 61 vec& _w() {return w;} 62 virtual ~emix() {if (destroyComs){for(int i=0;i<Coms.length();i++){delete Coms(i);}}}62 virtual ~emix() {if ( destroyComs ) {for ( int i=0;i<Coms.length();i++ ) {delete Coms ( i );}}} 63 63 //! Auxiliary function for taking ownership of the Coms() 64 void ownComs() {destroyComs=true;}64 void ownComs() {destroyComs=true;} 65 65 }; 66 66 … … 75 75 class mprod: public compositepdf, public mpdf { 76 76 protected: 77 // pointers to epdfs77 //! pointers to epdfs - shortcut to mpdfs()._epdf() 78 78 Array<epdf*> epdfs; 79 79 //! Indeces of rvc in common rvc 80 Array<ivec> rvcinds; 80 Array<ivec> rvcsinrvc; 81 //! Indeces of common rvc in rvcs 82 Array<ivec> rvcinrvcs; 81 83 public: 82 84 /*!\brief Constructor from list of mFacs, 83 Additional parameter overlap is left for future use. Do not set to true for mprod.84 85 */ 85 mprod ( Array<mpdf*> mFacs): compositepdf(mFacs), mpdf(getrv(true),RV()), epdfs(n), rvcinds(n) 86 { setrvc(rv,rvc); 87 setrvcinrv(rvc,rvcinds); 88 setindices(rv); 89 for(int i=0;i<n;i++){epdfs(i)=&(mpdfs(i)->_epdf());} 90 }; 91 92 double evalpdflog ( const vec &val ) const { 86 mprod ( Array<mpdf*> mFacs ) : compositepdf ( mFacs ), mpdf ( getrv ( true ),RV() ), epdfs ( n ), rvcsinrvc ( n ) { 87 setrvc ( rv,rvc ); 88 setindices ( rv ); 89 for ( int i = 0;i < n;i++ ) { 90 // find ith rvc in common rv 91 rvcsinrvc ( i ) = mpdfs ( i )->_rvc().dataind ( rvc ); 92 //and vice-versa 93 rvcinrvcs ( i ) = rvc.dataind ( mpdfs ( i )->_rvc() ); 94 } 95 96 for ( int i=0;i<n;i++ ) { 97 epdfs ( i ) =& ( mpdfs ( i )->_epdf() ); 98 } 99 }; 100 101 double evalcond ( const vec &val, const vec &cond ) const { 93 102 int i; 94 103 double res = 0.0; 104 vec condi; 95 105 for ( i = n - 1;i > 0;i++ ) { 96 if ( rvcinds ( i ).length() > 0 ) 97 {mpdfs ( i )->condition ( val ( rvcinds ( i ) ) );} 106 if ( ( rvcsinrvc ( i ).length() > 0 ) || ( rvcsinrv ( i ).length() > 0 ) ) { 107 condi = zeros ( rvcsinrvc ( i ).length() +rvcsinrv ( i ).length() ); 108 //copy part of the rvc into condi 109 set_subvector ( condi, rvcinrvcs ( i ), get_vec ( cond,rvcsinrvc ( i ) ) ); 110 //copy part of the rv into condi 111 set_subvector ( condi, rvinrvcs ( i ), get_vec ( val,rvcsinrv ( i ) ) ); 112 mpdfs ( i )->condition ( condi ); 113 } 98 114 // add logarithms 99 115 res += epdfs ( i )->evalpdflog ( val ( rvsinrv ( i ) ) ); … … 107 123 ll = 0; 108 124 for ( int i = ( n - 1 );i >= 0;i-- ) { 109 if ( ( rvcinds ( i ).length() > 0 )||( rvcsinrv ( i ).length() > 0 )) {110 condi = zeros ( rvcsinrv (i).length() + rvcinds(i).length() );125 if ( ( rvcsinrvc ( i ).length() > 0 ) || ( rvcsinrv ( i ).length() > 0 ) ) { 126 condi = zeros ( rvcsinrv ( i ).length() + rvcsinrvc ( i ).length() ); 111 127 // copy data in condition 112 set_subvector ( condi,rvc inds( i ), cond );128 set_subvector ( condi,rvcsinrvc ( i ), cond ); 113 129 // copy data in already generated sample 114 set_subvector ( condi,rvinrvcs ( i ), get_vec (smp,rvcsinrv(i)) );130 set_subvector ( condi,rvinrvcs ( i ), get_vec ( smp,rvcsinrv ( i ) ) ); 115 131 116 132 mpdfs ( i )->condition ( condi ); … … 169 185 double tmp=0; 170 186 for ( int i=0;i<epdfs.length();i++ ) { 171 tmp+=epdfs (i)->evalpdflog(val(rvinds(i)));187 tmp+=epdfs ( i )->evalpdflog ( val ( rvinds ( i ) ) ); 172 188 } 173 189 return tmp; 174 190 } 175 191 //!access function 176 const epdf* operator () ( int i) const {it_assert_debug(i<epdfs.length(),"wrong index");return epdfs(i);}192 const epdf* operator () ( int i ) const {it_assert_debug ( i<epdfs.length(),"wrong index" );return epdfs ( i );} 177 193 }; 178 194 -
bdm/stat/libBM.cpp
r178 r181 213 213 } 214 214 215 void compositepdf::setrvcinrv(const RV &rvc, Array<ivec> &rvinds){216 for (int i = 0;i < n;i++ ) {217 // find ith rv in common rv218 rvinds ( i ) = mpdfs ( i )->_rvc().dataind ( rvc );219 }220 }221 222 223 215 void BM::bayesB(const mat &Data){ 224 216 for(int t=0;t<Data.cols();t++){bayes(Data.get_col(t));} -
bdm/stat/libBM.h
r178 r181 19 19 using namespace itpp; 20 20 21 //! Structure of RV (used internally) 21 //! Structure of RV (used internally), i.e. expanded RVs 22 22 class str{ 23 23 public: 24 //! vector id ids (non-unique!) 24 25 ivec ids; 26 //! vector of times 25 27 ivec times; 28 //!Default constructor 26 29 str(ivec ids0, ivec times0):ids(ids0),times(times0){ 27 30 it_assert_debug(times0.length()==ids0.length(),"Incompatible input"); … … 262 265 public: 263 266 compositepdf(Array<mpdf*> A0): n(A0.length()), mpdfs(A0), rvsinrv(n), rvcsinrv(n),rvinrvcs(n){}; 267 //! find common rv, flag \param checkoverlap modifies whether overlaps are acceptable 264 268 RV getrv(bool checkoverlap=false); 269 //! common rvc of all mpdfs is written to rvc 265 270 void setrvc(const RV &rv, RV &rvc); 271 //! fill all rv*inrv* according to 266 272 void setindices(const RV &rv); 267 void setrvcinrv(const RV &rvc, Array<ivec> &rvcind);268 273 }; 269 274 -
bdm/stat/libEF.h
r178 r181 230 230 }; 231 231 232 //! Estimator for Multinomial density232 //! \brief Estimator for Multinomial density 233 233 class multiBM : public BMEF { 234 234 protected: 235 235 //! Conjugate prior and posterior 236 236 eDirich est; 237 //! Pointer inside est to sufficient statistics 237 238 vec β 238 239 public: … … 241 242 //!Copy constructor 242 243 multiBM ( const multiBM &B ) : BMEF ( B ),est ( rv,B.beta ),beta ( est._beta() ) {} 243 244 //! Sets sufficient statistics to match that of givefrom mB0 244 245 void set_statistics ( const BM* mB0 ) {const multiBM* mB=dynamic_cast<const multiBM*> ( mB0 ); beta=mB->beta;} 245 246 void bayes ( const vec &dt ) {