root/bdm/estim/mixef.h @ 180

Revision 180, 3.5 kB (checked in by smidl, 16 years ago)

Modifications of BDM to reflect changes in basics

Line 
1/*!
2  \file
3  \brief Bayesian Filtering for mixtures of exponential family (EF) members
4  \author Vaclav Smidl.
5
6  -----------------------------------
7  BDM++ - C++ library for Bayesian Decision Making under Uncertainty
8
9  Using IT++ for numerical operations
10  -----------------------------------
11*/
12
13#ifndef MEF_H
14#define MEF_H
15
16#include <itpp/itbase.h>
17#include "../stat/libFN.h"
18#include "../stat/libEF.h"
19#include "../stat/emix.h"
20
21using namespace itpp;
22
23/*!
24* \brief Mixture of Exponential Family Densities
25
26An approximate estimation method for models with latent discrete variable, such as
27mixture models of the following kind:
28\f[
29f(y_t|\psi_t, \Theta) = \sum_{i=1}^{n} w_i f(y_t|\psi_t, \theta_i)
30\f]
31where  \f$\psi\f$ is a known function of past outputs, \f$w=[w_1,\ldots,w_n]\f$ are component weights, and component parameters \f$\theta_i\f$ are assumed to be mutually independent. \f$\Theta\f$ is an aggregation af all component parameters and weights, i.e. \f$\Theta = [\theta_1,\ldots,\theta_n,w]\f$.
32
33The characteristic feature of this model is that if the exact values of the latent variable were known, estimation of the parameters can be handled by a single model. For example, for the case of mixture models, posterior density for each component parameters would be a BayesianModel from Exponential Family.
34
35This class uses EM-style type algorithms for estimation of its parameters. Under this simplification, the posterior density is a product of exponential family members, hence under EM-style approximate estimation this class itself belongs to the exponential family.
36
37TODO: Extend BM to use rvc.
38*/
39class MixEF: public BM {
40protected:
41        //!Number of components
42        int n;
43        //! Models for Components of \f$\theta_i\f$
44        Array<BMEF*> Coms;
45        //! Statistics for weights
46        multiBM weights;
47        //!Posterior on component parameters
48        eprod* est;
49        ////!Indeces of component rvc in common rvc
50       
51        //! Auxiliary function for use in constructors
52        void build_est() {
53                Array<const epdf*> epdfs ( n+1 );
54                for ( int i=0;i<Coms.length();i++ ) {
55//                      it_assert_debug(!x,"MixEF::MixEF : Incompatible components");
56                        epdfs ( i ) =& ( Coms ( i )->_epdf() );
57                }
58                // last in the product is the weight
59                epdfs ( n ) =& ( weights._epdf() );
60                est = new eprod ( epdfs );
61        }
62
63public:
64        //! Full constructor
65        MixEF ( const Array<BMEF*> &Coms0, const vec &alpha0 ) :
66                        BM ( RV() ), n ( Coms0.length() ), Coms ( n ),
67                        weights ( RV ( "{w }", vec_1 ( n ) ),alpha0 ) {
68        //      it_assert_debug ( n>0,"MixEF::MixEF : Empty Component list" );
69
70                for ( int i=0;i<n;i++ ) {Coms ( i ) = ( BMEF* ) Coms0 ( i )->_copy_();}
71                build_est();
72        };
73        MixEF () :
74                        BM ( RV() ), n ( 0 ), Coms ( 0 ),
75                        weights ( RV ( "{w }", vec_1 ( 0 ) ),vec ( 0 ) ) {build_est();}
76        //! Initializing the mixture by a random pick of centroids from data
77        //! \param Com0 Initial component - necessary to determine its type.
78        //! \param Data Data on which the initialization will be done
79        //! \param c Initial number of components, default=5
80        void init ( BMEF* Com0, const mat &Data, int c=5 );
81        //Destructor
82        ~MixEF() {
83                delete est;
84                for ( int i=0;i<n;i++ ) {delete Coms ( i );}
85        }
86        //! Recursive EM-like algorithm (QB-variant), see Karny et. al, 2006
87        void bayes ( const vec &dt );
88        //! EM algorithm
89        void bayes ( const mat &dt );
90        void bayesB ( const mat &dt );
91        double logpred ( const vec &dt ) const;
92        const epdf& _epdf() const {return *est;}
93        emix* predictor(const RV &rv);
94        //! Flatten the density as if it was not estimated from the data
95        void flatten(double sumw=1.0);
96};
97
98
99#endif // MEF_H
100
Note: See TracBrowser for help on using the browser.