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

# work/git/mixpp/bdm/estim/mixef.h

Go to the documentation of this file.

    00001
    00013 #ifndef MEF_H
    00014 #define MEF_H
    00015
    00016 #include <itpp/itbase.h>
    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                 Array<const epdf*> epdfs ( n+1 );
    00059                 for ( int i=0;i<Coms.length();i++ ) {
    00060 //                      it_assert_debug(!x,"MixEF::MixEF : Incompatible components");
    00061                         epdfs ( i ) =& ( Coms ( i )->_epdf() );
    00062                 }
    00063                 // last in the product is the weight
    00064                 epdfs ( n ) =& ( weights._epdf() );
    00065                 est = new eprod ( epdfs );
    00066         }
    00067
    00068 public:
    00070         MixEF ( const Array<BMEF*> &Coms0, const vec &alpha0 ) :
    00071                         BMEF ( RV() ), n ( Coms0.length() ), Coms ( n ),
    00072                         weights ( RV ( "{w }", vec_1 ( n ) ),alpha0 ), method(QB) {
    00073         //      it_assert_debug ( n>0,"MixEF::MixEF : Empty Component list" );
    00074
    00075                 for ( int i=0;i<n;i++ ) {Coms ( i ) = ( BMEF* ) Coms0 ( i )->_copy_();}
    00076                 build_est();
    00077         };
    00079         MixEF () :
    00080                         BMEF ( RV() ), n ( 0 ), Coms ( 0 ),
    00081                         weights ( RV ( "{w }", vec_1 ( 0 ) ),vec ( 0 ) ),method(QB) {build_est();}
    00083         MixEF(const MixEF &M2): BMEF ( RV() ), n ( M2.n ), Coms ( n ),
    00084                    weights ( M2.weights ), method(M2.method) {
    00085         //      it_assert_debug ( n>0,"MixEF::MixEF : Empty Component list" );
    00086
    00087                            for ( int i=0;i<n;i++ ) {Coms ( i ) = M2.Coms ( i )->_copy_();}
    00088                            build_est();
    00089                    }
    00094         void init ( BMEF* Com0, const mat &Data, int c=5 );
    00095         //Destructor
    00096         ~MixEF() {
    00097                 delete est;
    00098                 for ( int i=0;i<n;i++ ) {delete Coms ( i );}
    00099         }
    00101         void bayes ( const vec &dt );
    00103         void bayes ( const mat &dt );
    00104         void bayesB ( const mat &dt, const vec &wData );
    00105         double logpred ( const vec &dt ) const;
    00106         const epdf& _epdf() const {return *est;}
    00107         const eprod* _e() const {return est;}
    00108         emix* predictor(const RV &rv) const;
    00110         void flatten(const BMEF* M2);
    00112         BMEF* _Coms(int i){return Coms(i);}
    00113
    00115         void set_method(MixEF_METHOD M){method=M;}
    00116 };
    00117
    00118 }
    00119 #endif // MEF_H
    00120
    00121