Changeset 168 for bdm/stat/emix.h

Show
Ignore:
Timestamp:
09/18/08 19:54:09 (16 years ago)
Author:
smidl
Message:

Work on mixtures of EF, small changes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/emix.h

    r165 r168  
    8282        //! Indeces of rvc in common rvc 
    8383        Array<ivec> rvcinds; 
    84         //! Indicate independence of its factors 
    85         bool independent; 
     84//      //! Indicate independence of its factors 
     85//      bool independent; 
    8686//      //! Indicate internal creation of mpdfs which must be destroyed 
    8787//      bool intermpdfs; 
    8888public: 
    89         /*!\brief Constructor from list of mFacs,  
     89        /*!\brief Constructor from list of mFacs, 
    9090        Additional parameter overlap is left for future use. Do not set to true for mprod. 
    9191        */ 
    92         mprod ( Array<mpdf*> mFacs, bool overlap=false );  
     92        mprod ( Array<mpdf*> mFacs, bool overlap=false ); 
    9393 
    9494        double evalpdflog ( const vec &val ) const { 
     
    122122                        set_subvector ( smp,rvinds ( i ), smpi ); 
    123123                        // add ith likelihood contribution 
    124                         ll+=epdfs(i)->evalpdflog(smpi); 
     124                        ll+=epdfs ( i )->evalpdflog ( smpi ); 
    125125                } 
    126126                return smp; 
    127127        } 
    128128        mat samplecond ( const vec &cond, vec &ll, int N ) { 
    129                 mat Smp(rv.count(),N); 
    130                 for(int i=0;i<N;i++){Smp.set_col(i,samplecond(cond,ll(i)));} 
     129                mat Smp ( rv.count(),N ); 
     130                for ( int i=0;i<N;i++ ) {Smp.set_col ( i,samplecond ( cond,ll ( i ) ) );} 
    131131                return Smp; 
    132132        } 
    133 //      vec mean() const { 
    134 //              vec tmp ( rv.count() ); 
    135 //              if ( independent ) { 
    136 //                      for ( int i=0;i<n;i++ ) { 
    137 //                              vec pom = epdfs ( i )->mean(); 
    138 //                              set_subvector ( tmp,rvinds ( i ), pom ); 
    139 //                      } 
    140 //              } 
    141 //              else { 
    142 //                      int N=50*rv.count(); 
    143 //                      it_warning ( "eprod.mean() computed by sampling" ); 
    144 //                      tmp = zeros ( rv.count() ); 
    145 //                      for ( int i=0;i<N;i++ ) { tmp += sample();} 
    146 //                      tmp /=N; 
    147 //              } 
    148 //              return tmp; 
    149 //      } 
    150133 
    151134        ~mprod() {}; 
    152135}; 
     136 
     137//! Product of independent epdfs. For dependent pdfs, use mprod. 
     138class eprod: public epdf { 
     139protected: 
     140        //! Components (epdfs) 
     141        Array<epdf*> epdfs; 
     142        //! Array of indeces 
     143        Array<ivec> rvinds; 
     144public: 
     145        eprod ( const Array<epdf*> epdfs0 ) : epdf ( RV() ),epdfs ( epdfs0 ),rvinds ( epdfs.length() ) { 
     146                bool independent=true; 
     147                for ( int i=0;i<epdfs.length();i++ ) { 
     148                        independent=rv.add ( epdfs ( i )->_rv() ); 
     149                        it_assert_debug ( independent==true, "eprod:: given components are not independent ." ); 
     150                        rvinds ( i ) = ( epdfs ( i )->_rv() ).dataind ( rv ); 
     151                } 
     152        } 
     153 
     154        vec mean() const { 
     155                vec tmp ( rv.count() ); 
     156                for ( int i=0;i<epdfs.length();i++ ) { 
     157                        vec pom = epdfs ( i )->mean(); 
     158                        set_subvector ( tmp,rvinds ( i ), pom ); 
     159                } 
     160                return tmp; 
     161        } 
     162        vec sample() const { 
     163                vec tmp ( rv.count() ); 
     164                for ( int i=0;i<epdfs.length();i++ ) { 
     165                        vec pom = epdfs ( i )->sample(); 
     166                        set_subvector ( tmp,rvinds ( i ), pom ); 
     167                } 
     168                return tmp; 
     169        } 
     170        double evalpdflog ( const vec &val ) const { 
     171                double tmp=0; 
     172                for ( int i=0;i<epdfs.length();i++ ) { 
     173                        tmp+=epdfs(i)->evalpdflog(val(rvinds(i))); 
     174                } 
     175                return tmp; 
     176        } 
     177}; 
     178 
    153179 
    154180/*! \brief Mixture of mpdfs with constant weights, all mpdfs are of equal type