Revision 107, 1.5 kB
(checked in by smidl, 17 years ago)
|
new classes for mixture of epdf
|
-
Property svn:eol-style set to
native
|
Rev | Line | |
---|
[107] | 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 | |
---|
| 20 | using namespace itpp; |
---|
| 21 | |
---|
| 22 | /*! |
---|
| 23 | * \brief Mixture of epdfs |
---|
| 24 | |
---|
| 25 | Density function: |
---|
| 26 | \f[ |
---|
| 27 | f(x) = \sum_{i=1}^{n} w_{i} f_i(x), \quad \sum_{i=1}^n w_i = 1. |
---|
| 28 | \f] |
---|
| 29 | where \f$f_i(x)\f$ is any density on random variable \f$x\f$, called \a component, |
---|
| 30 | |
---|
| 31 | */ |
---|
| 32 | class emix : public epdf { |
---|
| 33 | protected: |
---|
| 34 | //! weights of the components |
---|
| 35 | vec w; |
---|
| 36 | //! Component (epdfs) |
---|
| 37 | Array<epdf*> Coms; |
---|
| 38 | public: |
---|
| 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 {int i; double sum=0.0; for ( i=0;i<w.length();i++ ) {sum+=w ( i ) *Coms ( i )->evalpdflog ( val );} return log ( sum );}; |
---|
| 51 | |
---|
| 52 | //Access methods |
---|
| 53 | //! returns a pointer to the internal mean value. Use with Care! |
---|
| 54 | vec& _w() {return w;} |
---|
| 55 | }; |
---|
| 56 | |
---|
| 57 | class mmix_triv : public mpdf { |
---|
| 58 | public: |
---|
| 59 | //!Default constructor |
---|
| 60 | mmix_triv ( const RV &rv, const RV &rvc, emix* em ) :mpdf ( rv,rvc ) {ep=em;}; |
---|
| 61 | }; |
---|
| 62 | |
---|
| 63 | #endif //MX_H |
---|