Revision 115, 1.5 kB
(checked in by smidl, 16 years ago)
|
zmena mmix_triv na mepdf
|
-
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 | |
---|
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 { |
---|
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 | */ |
---|
66 | class eprod: public epdf { |
---|
67 | protected: |
---|
68 | Array<epdf*> epdfs; |
---|
69 | Array<mpdf*> mpdfs; |
---|
70 | public: |
---|
71 | |
---|
72 | |
---|
73 | }; |
---|
74 | |
---|
75 | #endif //MX_H |
---|