root/bdm/stat/emix.cpp @ 182

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

compilation error!

  • Property svn:eol-style set to native
Line 
1#include "emix.h"
2
3using namespace itpp;
4
5void emix::set_parameters ( const vec &w0, const Array<epdf*> &Coms0, bool copy ) {
6        w = w0/sum ( w0 );
7        int i;
8        for ( i=0;i<w.length();i++ ) {
9                it_assert_debug ( rv.equal ( Coms0 ( i )->_rv() ),"RVs do not match!" );
10        }
11        if ( copy ) {
12                Coms.set_length(Coms0.length());
13                for ( i=0;i<w.length();i++ ) {*Coms ( i ) =*Coms0 ( i );}
14                destroyComs=true;
15        }
16        else {
17                Coms = Coms0;
18                destroyComs=false;
19        }
20}
21
22vec emix::sample() const {
23        //Sample which component
24        vec cumDist = cumsum ( w );
25        double u0 = UniRNG.sample();
26
27        int i=0;
28        while ( ( cumDist ( i ) <u0 ) && ( i< ( w.length()-1 ) ) ) {i++;}
29
30        return Coms ( i )->sample();
31}
32
33emix* emix::marginal(const RV &rv) const{
34        Array<epdf*> Cn(Coms.length());
35        for(int i=0;i<Coms.length();i++){Cn(i)=Coms(i)->marginal(rv);}
36        emix* tmp = new emix(rv);
37        tmp->set_parameters(w,Coms,false);
38        tmp->ownComs();
39        return tmp;
40}
41
42mratio* emix::condition(const RV &rv) const{
43        return new mratio(this,rv);
44};
45
46// mprod::mprod ( Array<mpdf*> mFacs, bool overlap) : mpdf ( RV(), RV() ), n ( mFacs.length() ), epdfs ( n ), mpdfs ( mFacs ), rvinds ( n ), rvcinrv ( n ), irvcs_rvc ( n ) {
47//              int i;
48//              bool rvaddok;
49//              // Create rv
50//              for ( i = 0;i < n;i++ ) {
51//                      rvaddok=rv.add ( mpdfs ( i )->_rv() ); //add rv to common rvs.
52//                      // If rvaddok==false, mpdfs overlap => assert error.
53//                      it_assert_debug(rvaddok||overlap,"mprod::mprod() input mpdfs overlap in rv!");
54//                      epdfs ( i ) = & ( mpdfs ( i )->_epdf() ); // add pointer to epdf
55//              };
56//              // Create rvc
57//              for ( i = 0;i < n;i++ ) {
58//                      rvc.add ( mpdfs ( i )->_rvc().subt ( rv ) ); //add rv to common rvs.
59//              };
60//
61// //           independent = true;
62//              //test rvc of mpdfs and fill rvinds
63//              for ( i = 0;i < n;i++ ) {
64//                      // find ith rv in common rv
65//                      rvsinrv ( i ) = mpdfs ( i )->_rv().dataind ( rv );
66//                      // find ith rvc in common rv
67//                      rvcinrv ( i ) = mpdfs ( i )->_rvc().dataind ( rv );
68//                      // find ith rvc in common rv
69//                      irvcs_rvc ( i ) = mpdfs ( i )->_rvc().dataind ( rvc );
70//                      //
71// /*                   if ( rvcinrv ( i ).length() >0 ) {independent = false;}
72//                      if ( irvcs_rvc ( i ).length() >0 ) {independent = false;}*/
73//              }
74//      };
Note: See TracBrowser for help on using the browser.