Changeset 886 for library/bdm/estim

Show
Ignore:
Timestamp:
03/29/10 23:01:49 (14 years ago)
Author:
smidl
Message:

epdf and emix now have _base classes

Location:
library/bdm/estim
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/estim/mixtures.cpp

    r780 r886  
    3535        } 
    3636 
    37         //est already exists - must be deleted before build_est() can be used 
    38         delete est; 
    39         build_est(); 
    4037} 
    4138 
  • library/bdm/estim/mixtures.h

    r766 r886  
    4848        //! Statistics for weights 
    4949        multiBM weights; 
     50        //aux 
     51        friend class eprod_mix; 
    5052        //!Posterior on component parameters 
    51         eprod* est; 
     53        class eprod_mix: public eprod_base { 
     54                protected: 
     55                const MixEF &mix; // pointer to parent.n 
     56                public: 
     57                eprod_mix(const MixEF &m):mix(m){} 
     58                const epdf* factor(int i) const {return (i==(mix.n-1)) ? &mix.weights.posterior() : &mix.Coms(i)->posterior();} 
     59                const int no_factors()const {return mix.n+1;} 
     60        } est; 
    5261        ////!Indeces of component rvc in common rvc 
    5362 
     
    5564        MixEF_METHOD method; 
    5665 
    57         //! Auxiliary function for use in constructors 
    58         void build_est() { 
    59                 est = new eprod; 
    60                 if ( n > 0 ) { 
    61                         Array<const epdf*> epdfs ( n + 1 ); 
    62                         for ( int i = 0; i < Coms.length(); i++ ) { 
    63                                 epdfs ( i ) = & ( Coms ( i )->posterior() ); 
    64                         } 
    65                         // last in the product is the weight 
    66                         epdfs ( n ) = & ( weights.posterior() ); 
    67                         est->set_parameters ( epdfs, false ); 
    68                 } 
    69         } 
    70  
    7166public: 
    7267        //! Full constructor 
    7368        MixEF ( const Array<BMEF*> &Coms0, const vec &alpha0 ) : 
    7469                        BMEF ( ), n ( Coms0.length() ), Coms ( n ), 
    75                         weights (), method ( QB ) { 
     70                        weights (), est(*this), method ( QB ) { 
    7671                for ( int i = 0; i < n; i++ ) { 
    7772                        Coms ( i ) = ( BMEF* ) Coms0 ( i )->_copy(); 
     
    7974                weights.set_parameters(alpha0); 
    8075                weights.validate(); 
    81                 build_est(); 
    8276        } 
    8377 
     
    8579        MixEF () : 
    8680                        BMEF ( ), n ( 0 ), Coms ( 0 ), 
    87                         weights (), method ( QB ) { 
    88                 build_est(); 
     81                        weights (), est(*this), method ( QB ) { 
    8982        } 
    9083        //! Copy constructor 
    9184        MixEF ( const MixEF &M2 ) : BMEF ( ), n ( M2.n ), Coms ( n ), 
    92                         weights ( M2.weights ), method ( M2.method ) { 
     85                        weights ( M2.weights ), est(*this), method ( M2.method ) { 
    9386                for ( int i = 0; i < n; i++ ) { 
    9487                        Coms ( i ) = (BMEF*) M2.Coms ( i )->_copy(); 
    9588                } 
    96                 build_est(); 
    9789        } 
    9890 
     
    10395        void init ( BMEF* Com0, const mat &Data, const int c = 5 ); 
    10496        //Destructor 
    105         ~MixEF() { 
    106                 delete est; 
    107                 for ( int i = 0; i < n; i++ ) { 
    108                         delete Coms ( i ); 
    109                 } 
    110         } 
    11197        //! Recursive EM-like algorithm (QB-variant), see Karny et. al, 2006 
    11298        void bayes ( const vec &yt, const vec &cond ); 
     
    117103        double logpred ( const vec &yt ) const; 
    118104        //! return correctly typed posterior (covariant return) 
    119         const eprod& posterior() const { 
    120                 return *est; 
     105        const eprod_mix& posterior() const { 
     106                return est; 
    121107        } 
    122108