- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

# mixef.h

Go to the documentation of this file.

    00001
    00013 #ifndef MEF_H
    00014 #define MEF_H
    00015
    00016
    00017 #include "../stat/libFN.h"
    00018 #include "../stat/libEF.h"
    00019 #include "../stat/emix.h"
    00020
    00021 namespace bdm {
    00022
    00023 enum MixEF_METHOD { EM = 0, QB = 1};
    00024
    00041 class MixEF: public BMEF {
    00042 protected:
    00044         int n;
    00046         Array<BMEF*> Coms;
    00048         multiBM weights;
    00050         eprod* est;
    00052
    00054         MixEF_METHOD method;
    00055
    00057         void build_est() {
    00058                 est = new eprod;
    00059                 if ( n>0 ) {
    00060                         Array<const epdf*> epdfs ( n+1 );
    00061                         for ( int i=0;i<Coms.length();i++ ) {
    00062 //                      it_assert_debug(!x,"MixEF::MixEF : Incompatible components");
    00063                                 epdfs ( i ) =& ( Coms ( i )->posterior() );
    00064                         }
    00065                         // last in the product is the weight
    00066                         epdfs ( n ) =& ( weights.posterior() );
    00067                         est->set_parameters ( epdfs, false );
    00068                 }
    00069         }
    00070
    00071 public:
    00073         MixEF ( const Array<BMEF*> &Coms0, const vec &alpha0 ) :
    00074                         BMEF ( ), n ( Coms0.length() ), Coms ( n ),
    00075                         weights (), method ( QB ) {
    00076                 //      it_assert_debug ( n>0,"MixEF::MixEF : Empty Component list" );
    00077
    00078                 for ( int i=0;i<n;i++ ) {Coms ( i ) = ( BMEF* ) Coms0 ( i )->_copy_();}
    00079                 build_est();
    00080         };
    00082         MixEF () :
    00083                         BMEF ( ), n ( 0 ), Coms ( 0 ),
    00084                         weights (),method ( QB ) {build_est();}
    00086         MixEF ( const MixEF &M2 ) : BMEF ( ), n ( M2.n ), Coms ( n ),
    00087                         weights ( M2.weights ), method ( M2.method ) {
    00088                 //      it_assert_debug ( n>0,"MixEF::MixEF : Empty Component list" );
    00089
    00090                 for ( int i=0;i<n;i++ ) {Coms ( i ) = M2.Coms ( i )->_copy_();}
    00091                 build_est();
    00092         }
    00097         void init ( BMEF* Com0, const mat &Data, int c=5 );
    00098         //Destructor
    00099         ~MixEF() {
    00100                 delete est;
    00101                 for ( int i=0;i<n;i++ ) {delete Coms ( i );}
    00102         }
    00104         void bayes ( const vec &dt );
    00106         void bayes ( const mat &dt );
    00107         void bayesB ( const mat &dt, const vec &wData );
    00108         double logpred ( const vec &dt ) const;
    00109         const epdf& posterior() const {return *est;}
    00110         const eprod* _e() const {return est;}
    00111         emix* epredictor() const;
    00113         void flatten ( const BMEF* M2 );
    00115         BMEF* _Coms ( int i ) {return Coms ( i );}
    00116
    00118         void set_method ( MixEF_METHOD M ) {method=M;}
    00119 };
    00120
    00121 }
    00122 #endif // MEF_H
    00123
    00124