root/bdm/stat/emix.h @ 124

Revision 124, 2.1 kB (checked in by smidl, 16 years ago)

zmeny v mmix

  • Property svn:eol-style set to native
Line 
1/*!
2  \file
3  \brief Probability distributions for Mixtures of pdfs
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 MX_H
14#define MX_H
15
16#include "libBM.h"
17#include "libEF.h"
18//#include <std>
19
20using namespace itpp;
21
22/*!
23* \brief Mixture of epdfs
24
25Density function:
26\f[
27f(x) = \sum_{i=1}^{n} w_{i} f_i(x), \quad \sum_{i=1}^n w_i = 1.
28\f]
29where \f$f_i(x)\f$ is any density on random variable \f$x\f$, called \a component,
30
31*/
32class emix : public epdf {
33protected:
34        //! weights of the components
35        vec w;
36        //! Component (epdfs)
37        Array<epdf*> Coms;
38public:
39        //!Default constructor
40        emix ( RV &rv ) : epdf ( rv ) {};
41        //! Set weights \c w and components \c R
42        void set_parameters ( const vec &w, const Array<epdf*> &Coms );
43
44        vec sample() const;
45        vec mean() const {
46                int i; vec mu=zeros ( rv.count() );
47                for ( i=0;i<w.length();i++ ) {mu+=w ( i ) *Coms ( i )->mean(); }
48                return mu;
49        }
50        double evalpdflog ( const vec &val ) const {
51                int i;
52                double sum=0.0;
53                for ( i=0;i<w.length();i++ ) {sum+=w ( i ) *Coms ( i )->evalpdflog ( val );}
54                return log ( sum );
55        };
56
57//Access methods
58        //! returns a pointer to the internal mean value. Use with Care!
59        vec& _w() {return w;}
60};
61
62/*! \brief Chain rule decomposition of epdf
63
64
65*/
66class eprod: public epdf {
67protected:
68        Array<epdf*> epdfs;
69        Array<mpdf*> mpdfs;
70public:
71
72
73};
74
75/*! \brief Mixture of mpdfs with constant weights
76
77*/
78class mmix : public mpdf {
79protected:
80        //! Component (epdfs)
81        Array<mpdf*> Coms;
82        //!Internal epdf
83        emix Epdf;
84public:
85        //!Default constructor
86        mmix ( RV &rv, RV &rvc ) : mpdf ( rv, rvc ), Epdf ( rv ) {ep=&Epdf;};
87        //! Set weights \c w and components \c R
88        void set_parameters ( const vec &w, const Array<mpdf*> &Coms ) {
89                Array<epdf*> Eps ( Coms.length());
90
91                for ( int i=0;i<Coms.length();i++ ) {mpdf* Ci=Coms(i);
92                 Eps ( i ) =& ( Coms ( i )->_epdf() );}
93                Epdf.set_parameters ( w,Eps );
94        };
95
96        void condition ( const vec &cond ) {
97                for ( int i=0;i<Coms.length();i++ ) {Coms ( i )->condition ( cond );}
98        };
99};
100#endif //MX_H
Note: See TracBrowser for help on using the browser.