- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# mixtures.h

Go to the documentation of this file.

    00001
    00013 #ifndef MIXTURES_H
    00014 #define MIXTURES_H
    00015
    00016
    00017 #include "../math/functions.h"
    00018 #include "../stat/exp_family.h"
    00019 #include "../stat/emix.h"
    00020
    00021 namespace bdm {
    00022
    00024 enum MixEF_METHOD { EM = 0, QB = 1};
    00025
    00042 class MixEF: public BMEF {
    00043 protected:
    00045         int n;
    00047         Array<BMEF*> Coms;
    00049         multiBM weights;
    00051         eprod* est;
    00053
    00055         MixEF_METHOD method;
    00056
    00058         void build_est() {
    00059                 est = new eprod;
    00060                 if ( n > 0 ) {
    00061                         Array<const epdf*> epdfs ( n + 1 );
    00062                         for ( int i = 0; i < Coms.length(); i++ ) {
    00063 //                      it_assert_debug(!x,"MixEF::MixEF : Incompatible components");
    00064                                 epdfs ( i ) = & ( Coms ( i )->posterior() );
    00065                         }
    00066                         // last in the product is the weight
    00067                         epdfs ( n ) = & ( weights.posterior() );
    00068                         est->set_parameters ( epdfs, false );
    00069                 }
    00070         }
    00071
    00072 public:
    00074         MixEF ( const Array<BMEF*> &Coms0, const vec &alpha0 ) :
    00075                         BMEF ( ), n ( Coms0.length() ), Coms ( n ),
    00076                         weights (), method ( QB ) {
    00077                 //      it_assert_debug ( n>0,"MixEF::MixEF : Empty Component list" );
    00078
    00079                 for ( int i = 0; i < n; i++ ) {
    00080                         Coms ( i ) = ( BMEF* ) Coms0 ( i )->_copy_();
    00081                 }
    00082                 build_est();
    00083         };
    00085         MixEF () :
    00086                         BMEF ( ), n ( 0 ), Coms ( 0 ),
    00087                         weights (), method ( QB ) {
    00088                 build_est();
    00089         }
    00091         MixEF ( const MixEF &M2 ) : BMEF ( ), n ( M2.n ), Coms ( n ),
    00092                         weights ( M2.weights ), method ( M2.method ) {
    00093                 //      it_assert_debug ( n>0,"MixEF::MixEF : Empty Component list" );
    00094
    00095                 for ( int i = 0; i < n; i++ ) {
    00096                         Coms ( i ) = M2.Coms ( i )->_copy_();
    00097                 }
    00098                 build_est();
    00099         }
    00104         void init ( BMEF* Com0, const mat &Data, int c = 5 );
    00105         //Destructor
    00106         ~MixEF() {
    00107                 delete est;
    00108                 for ( int i = 0; i < n; i++ ) {
    00109                         delete Coms ( i );
    00110                 }
    00111         }
    00113         void bayes ( const vec &dt );
    00115         void bayes ( const mat &dt );
    00116         void bayesB ( const mat &dt, const vec &wData );
    00117         double logpred ( const vec &dt ) const;
    00118         const epdf& posterior() const {
    00119                 return *est;
    00120         }
    00121         emix* epredictor() const;
    00123         void flatten ( const BMEF* M2 );
    00125         BMEF* _Coms ( int i ) {
    00126                 return Coms ( i );
    00127         }
    00128
    00130         void set_method ( MixEF_METHOD M ) {
    00131                 method = M;
    00132         }
    00133 };
    00134
    00135 }
    00136 #endif // MIXTURES_H
    00137
    00138