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 ); |
| 32 | class emix : public epdf |
| 33 | { |
| 34 | protected: |
| 35 | //! weights of the components |
| 36 | vec w; |
| 37 | //! Component (epdfs) |
| 38 | Array<epdf*> Coms; |
| 39 | public: |
| 40 | //!Default constructor |
| 41 | emix ( RV &rv ) : epdf ( rv ) {}; |
| 42 | //! Set weights \c w and components \c R |
| 43 | void set_parameters ( const vec &w, const Array<epdf*> &Coms ); |
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 | | }; |
| 45 | vec sample() const; |
| 46 | vec mean() const |
| 47 | { |
| 48 | int i; vec mu=zeros ( rv.count() ); |
| 49 | for ( i=0;i<w.length();i++ ) {mu+=w ( i ) *Coms ( i )->mean(); } |
| 50 | return mu; |
| 51 | } |
| 52 | double evalpdflog ( const vec &val ) const |
| 53 | { |
| 54 | int i; |
| 55 | double sum=0.0; |
| 56 | for ( i=0;i<w.length();i++ ) {sum+=w ( i ) *Coms ( i )->evalpdflog ( val );} |
| 57 | return log ( sum ); |
| 58 | }; |
78 | | class mmix : public mpdf { |
79 | | protected: |
80 | | //! Component (epdfs) |
81 | | Array<mpdf*> Coms; |
82 | | //!Internal epdf |
83 | | emix Epdf; |
84 | | public: |
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()); |
| 82 | class mmix : public mpdf |
| 83 | { |
| 84 | protected: |
| 85 | //! Component (epdfs) |
| 86 | Array<mpdf*> Coms; |
| 87 | //!Internal epdf |
| 88 | emix Epdf; |
| 89 | public: |
| 90 | //!Default constructor |
| 91 | mmix ( RV &rv, RV &rvc ) : mpdf ( rv, rvc ), Epdf ( rv ) {ep=&Epdf;}; |
| 92 | //! Set weights \c w and components \c R |
| 93 | void set_parameters ( const vec &w, const Array<mpdf*> &Coms ) |
| 94 | { |
| 95 | Array<epdf*> Eps ( Coms.length() ); |