- 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                                 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                 for ( int i = 0; i < n; i++ ) {
    00077                         Coms ( i ) = ( BMEF* ) Coms0 ( i )->_copy_();
    00078                 }
    00079                 build_est();
    00080         }
    00081
    00083         MixEF () :
    00084                         BMEF ( ), n ( 0 ), Coms ( 0 ),
    00085                         weights (), method ( QB ) {
    00086                 build_est();
    00087         }
    00089         MixEF ( const MixEF &M2 ) : BMEF ( ), n ( M2.n ), Coms ( n ),
    00090                         weights ( M2.weights ), method ( M2.method ) {
    00091                 for ( int i = 0; i < n; i++ ) {
    00092                         Coms ( i ) = M2.Coms ( i )->_copy_();
    00093                 }
    00094                 build_est();
    00095         }
    00096
    00101         void init ( BMEF* Com0, const mat &Data, int c = 5 );
    00102         //Destructor
    00103         ~MixEF() {
    00104                 delete est;
    00105                 for ( int i = 0; i < n; i++ ) {
    00106                         delete Coms ( i );
    00107                 }
    00108         }
    00110         void bayes ( const vec &dt );
    00112         void bayes ( const mat &dt );
    00113         void bayesB ( const mat &dt, const vec &wData );
    00114         double logpred ( const vec &dt ) const;
    00115         const epdf& posterior() const {
    00116                 return *est;
    00117         }
    00118         emix* epredictor() const;
    00120         void flatten ( const BMEF* M2 );
    00122         BMEF* _Coms ( int i ) {
    00123                 return Coms ( i );
    00124         }
    00125
    00127         void set_method ( MixEF_METHOD M ) {
    00128                 method = M;
    00129         }
    00130 };
    00131
    00132 }
    00133 #endif // MIXTURES_H
    00134
    00135