root/bdm/stat/emix.cpp @ 192

Revision 192, 2.2 kB (checked in by smidl, 16 years ago)

modification of datalinks and switch mprod and merger to use them

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