Revision 141, 477 bytes
(checked in by smidl, 16 years ago)
|
Opraveny warningy
|
-
Property svn:eol-style set to
native
|
Line | |
---|
1 | #include "emix.h" |
---|
2 | |
---|
3 | using namespace itpp; |
---|
4 | |
---|
5 | void emix::set_parameters ( const vec &w0, const Array<epdf*> &Coms0 ) { |
---|
6 | w = 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 | Coms = Coms0; |
---|
12 | } |
---|
13 | |
---|
14 | vec emix::sample() const { |
---|
15 | //Sample which component |
---|
16 | vec cumDist = cumsum ( w ); |
---|
17 | double u0 = UniRNG.sample(); |
---|
18 | |
---|
19 | int i=0; |
---|
20 | while ( ( w ( i ) <u0 ) && ( i< ( w.length()-1 ) ) ) {i++;} |
---|
21 | |
---|
22 | return Coms ( i )->sample(); |
---|
23 | } |
---|