Changeset 175 for bdm/stat/emix.h

Show
Ignore:
Timestamp:
10/09/08 11:32:11 (16 years ago)
Author:
smidl
Message:

mprod is now based on compositepdf

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/emix.h

    r170 r175  
    6868Note that 
    6969*/ 
    70 class mprod: public mpdf { 
    71 protected: 
    72         // 
    73         int n; 
     70class mprod: public compositepdf, public mpdf { 
     71protected: 
    7472        // pointers to epdfs 
    7573        Array<epdf*> epdfs; 
    76         Array<mpdf*> mpdfs; 
    77         // 
    78         //! Indeces of rvs in common rv 
    79         Array<ivec> rvinds; 
    80         //! Indeces of rvc in common rv 
    81         Array<ivec> rvcinrv; 
    8274        //! Indeces of rvc in common rvc 
    8375        Array<ivec> rvcinds; 
    84 //      //! Indicate independence of its factors 
    85 //      bool independent; 
    86 //      //! Indicate internal creation of mpdfs which must be destroyed 
    87 //      bool intermpdfs; 
    8876public: 
    8977        /*!\brief Constructor from list of mFacs, 
    9078        Additional parameter overlap is left for future use. Do not set to true for mprod. 
    9179        */ 
    92         mprod ( Array<mpdf*> mFacs, bool overlap=false ); 
     80        mprod ( Array<mpdf*> mFacs): compositepdf(mFacs), mpdf(getrv(true),RV()), rvcinds(n), epdfs(n) 
     81        {       setrvc(rv,rvc); 
     82                setrvcinrv(rvc,rvcinds); 
     83                setindices(rv);  
     84        for(int i=0;i<n;i++){epdfs(i)=&(mpdfs(i)->_epdf());} 
     85        }; 
    9386 
    9487        double evalpdflog ( const vec &val ) const { 
     
    9992                                {mpdfs ( i )->condition ( val ( rvcinds ( i ) ) );} 
    10093                        // add logarithms 
    101                         res += epdfs ( i )->evalpdflog ( val ( rvinds ( i ) ) ); 
     94                        res += epdfs ( i )->evalpdflog ( val ( rvsinrv ( i ) ) ); 
    10295                } 
    10396                return res; 
     
    110103                for ( int i = ( n - 1 );i >= 0;i-- ) { 
    111104                        if ( rvcinds ( i ).length() > 0 ) { 
    112                                 condi = zeros ( rvcinrv.length() + rvcinds.length() ); 
     105                                condi = zeros ( rvcsinrv.length() + rvcinds.length() ); 
    113106                                // copy data in condition 
    114107                                set_subvector ( condi,rvcinds ( i ), cond ); 
    115108                                // copy data in already generated sample 
    116                                 set_subvector ( condi,rvcinrv ( i ), smp ); 
     109                                set_subvector ( condi,rvcsinrv ( i ), smp ); 
    117110 
    118111                                mpdfs ( i )->condition ( condi ); 
     
    120113                        smpi = epdfs ( i )->sample(); 
    121114                        // copy contribution of this pdf into smp 
    122                         set_subvector ( smp,rvinds ( i ), smpi ); 
     115                        set_subvector ( smp,rvsinrv ( i ), smpi ); 
    123116                        // add ith likelihood contribution 
    124117                        ll+=epdfs ( i )->evalpdflog ( smpi );