root/bdm/stat/emix.cpp @ 178

Revision 178, 1.8 kB (checked in by smidl, 16 years ago)

Changes in basic structures! new methods

  • 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
33// mprod::mprod ( Array<mpdf*> mFacs, bool overlap) : mpdf ( RV(), RV() ), n ( mFacs.length() ), epdfs ( n ), mpdfs ( mFacs ), rvinds ( n ), rvcinrv ( n ), rvcinds ( n ) {
34//              int i;
35//              bool rvaddok;
36//              // Create rv
37//              for ( i = 0;i < n;i++ ) {
38//                      rvaddok=rv.add ( mpdfs ( i )->_rv() ); //add rv to common rvs.
39//                      // If rvaddok==false, mpdfs overlap => assert error.
40//                      it_assert_debug(rvaddok||overlap,"mprod::mprod() input mpdfs overlap in rv!");
41//                      epdfs ( i ) = & ( mpdfs ( i )->_epdf() ); // add pointer to epdf
42//              };
43//              // Create rvc
44//              for ( i = 0;i < n;i++ ) {
45//                      rvc.add ( mpdfs ( i )->_rvc().subt ( rv ) ); //add rv to common rvs.
46//              };
47//
48// //           independent = true;
49//              //test rvc of mpdfs and fill rvinds
50//              for ( i = 0;i < n;i++ ) {
51//                      // find ith rv in common rv
52//                      rvsinrv ( i ) = mpdfs ( i )->_rv().dataind ( rv );
53//                      // find ith rvc in common rv
54//                      rvcinrv ( i ) = mpdfs ( i )->_rvc().dataind ( rv );
55//                      // find ith rvc in common rv
56//                      rvcinds ( i ) = mpdfs ( i )->_rvc().dataind ( rvc );
57//                      //
58// /*                   if ( rvcinrv ( i ).length() >0 ) {independent = false;}
59//                      if ( rvcinds ( i ).length() >0 ) {independent = false;}*/
60//              }
61//      };
Note: See TracBrowser for help on using the browser.