219 | | <a name="l00236"></a><a class="code" href="classbdm_1_1mprod.html#680c3e2d95b116c7cfb227c7f2984525">00236</a> <a class="code" href="classbdm_1_1mprod.html#680c3e2d95b116c7cfb227c7f2984525" title="Constructor from list of mFacs,.">mprod</a> ( Array<mpdf*> mFacs ) : <a class="code" href="classbdm_1_1compositepdf.html" title="Abstract composition of pdfs, will be used for specific classes this abstract class...">compositepdf</a> ( mFacs ), <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> (), <a class="code" href="classbdm_1_1mprod.html#eca722ed1b219727c6c0f8cbc6bf1e51" title="pointers to epdfs - shortcut to mpdfs().posterior()">epdfs</a> ( <a class="code" href="classbdm_1_1compositepdf.html#7ca3cd8ed92a7154f5b9ff13b1e9d52a" title="Number of mpdfs in the composite.">n</a> ), <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( <a class="code" href="classbdm_1_1compositepdf.html#7ca3cd8ed92a7154f5b9ff13b1e9d52a" title="Number of mpdfs in the composite.">n</a> ) { |
220 | | <a name="l00237"></a>00237 <a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1mprod.html#e3fe66c257e5eca9de1031ef44907677" title="dummy ep">dummy</a>; |
221 | | <a name="l00238"></a>00238 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rv=<a class="code" href="classbdm_1_1compositepdf.html#c73d39acc4378eee6a63155c3517d3c9" title="find common rv, flag">getrv</a> ( <span class="keyword">true</span> ); |
222 | | <a name="l00239"></a>00239 set_rv ( rv );<a class="code" href="classbdm_1_1mprod.html#e3fe66c257e5eca9de1031ef44907677" title="dummy ep">dummy</a>.<a class="code" href="classbdm_1_1epdf.html#840de94aa33cf4f2ebd2427f45a165d8">set_parameters</a> ( rv.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>() ); |
223 | | <a name="l00240"></a>00240 <a class="code" href="classbdm_1_1compositepdf.html#c71fc2c51f49d797e61f479f543c75ce" title="common rvc of all mpdfs is written to rvc">setrvc</a> ( <a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>-><a class="code" href="classbdm_1_1epdf.html#a4ab378d5e004c3ff3e2d4e64f7bba21" title="Return name (fails when isnamed is false).">_rv</a>(),<a class="code" href="classbdm_1_1mpdf.html#5a5f08950daa08b85b01ddf4e1c36288" title="random variable in condition">rvc</a> ); |
224 | | <a name="l00241"></a>00241 <span class="comment">// rv and rvc established = > we can link them with mpdfs</span> |
225 | | <a name="l00242"></a>00242 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1compositepdf.html#7ca3cd8ed92a7154f5b9ff13b1e9d52a" title="Number of mpdfs in the composite.">n</a>;i++ ) { |
226 | | <a name="l00243"></a>00243 <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( i ) = <span class="keyword">new</span> <a class="code" href="classbdm_1_1datalink__m2m.html">datalink_m2m</a>; |
227 | | <a name="l00244"></a>00244 <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a>(i)->set_connection( <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->_rv(), <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->_rvc(), _rv(), _rvc() ); |
228 | | <a name="l00245"></a>00245 } |
229 | | <a name="l00246"></a>00246 |
230 | | <a name="l00247"></a>00247 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<n;i++ ) { |
231 | | <a name="l00248"></a>00248 <a class="code" href="classbdm_1_1mprod.html#eca722ed1b219727c6c0f8cbc6bf1e51" title="pointers to epdfs - shortcut to mpdfs().posterior()">epdfs</a> ( i ) =& ( <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->_epdf() ); |
232 | | <a name="l00249"></a>00249 } |
233 | | <a name="l00250"></a>00250 }; |
| 219 | <a name="l00236"></a><a class="code" href="classbdm_1_1mprod.html#fed864cdd0e724d9133e6c6bfcacf94b">00236</a> <a class="code" href="classbdm_1_1mprod.html#fed864cdd0e724d9133e6c6bfcacf94b" title="Constructor from list of mFacs,.">mprod</a> (){}; |
| 220 | <a name="l00237"></a>00237 <a class="code" href="classbdm_1_1mprod.html#fed864cdd0e724d9133e6c6bfcacf94b" title="Constructor from list of mFacs,.">mprod</a> (Array<mpdf*> mFacs ){set_elements( mFacs );}; |
| 221 | <a name="l00238"></a>00238 <span class="keywordtype">void</span> set_elements(Array<mpdf*> mFacs ) { |
| 222 | <a name="l00239"></a>00239 |
| 223 | <a name="l00240"></a>00240 set_elements(mFacs); |
| 224 | <a name="l00241"></a>00241 |
| 225 | <a name="l00242"></a>00242 <a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1mprod.html#e3fe66c257e5eca9de1031ef44907677" title="dummy ep">dummy</a>; |
| 226 | <a name="l00243"></a>00243 RV rv=<a class="code" href="classbdm_1_1compositepdf.html#c73d39acc4378eee6a63155c3517d3c9" title="find common rv, flag">getrv</a> ( <span class="keyword">true</span> ); |
| 227 | <a name="l00244"></a>00244 set_rv ( rv );<a class="code" href="classbdm_1_1mprod.html#e3fe66c257e5eca9de1031ef44907677" title="dummy ep">dummy</a>.set_parameters ( rv._dsize() ); |
| 228 | <a name="l00245"></a>00245 <a class="code" href="classbdm_1_1compositepdf.html#c71fc2c51f49d797e61f479f543c75ce" title="common rvc of all mpdfs is written to rvc">setrvc</a> ( <a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>->_rv(),<a class="code" href="classbdm_1_1mpdf.html#5a5f08950daa08b85b01ddf4e1c36288" title="random variable in condition">rvc</a> ); |
| 229 | <a name="l00246"></a>00246 <span class="comment">// rv and rvc established = > we can link them with mpdfs</span> |
| 230 | <a name="l00247"></a>00247 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length(); i++ ) { |
| 231 | <a name="l00248"></a>00248 <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( i ) = <span class="keyword">new</span> datalink_m2m; |
| 232 | <a name="l00249"></a>00249 <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a>(i)->set_connection( <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->_rv(), <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->_rvc(), _rv(), _rvc() ); |
| 233 | <a name="l00250"></a>00250 } |
235 | | <a name="l00252"></a><a class="code" href="classbdm_1_1mprod.html#800f21d94c919137608a2fd5c88719e2">00252</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mprod.html#800f21d94c919137608a2fd5c88719e2" title="Shortcut for conditioning and evaluation of the internal epdf. In some cases, this...">evallogcond</a> ( <span class="keyword">const</span> vec &val, <span class="keyword">const</span> vec &cond ) { |
236 | | <a name="l00253"></a>00253 <span class="keywordtype">int</span> i; |
237 | | <a name="l00254"></a>00254 <span class="keywordtype">double</span> res = 0.0; |
238 | | <a name="l00255"></a>00255 <span class="keywordflow">for</span> ( i = <a class="code" href="classbdm_1_1compositepdf.html#7ca3cd8ed92a7154f5b9ff13b1e9d52a" title="Number of mpdfs in the composite.">n</a> - 1;i >= 0;i-- ) { |
239 | | <a name="l00256"></a>00256 <span class="comment">/* if ( mpdfs(i)->_rvc().count() >0) {</span> |
240 | | <a name="l00257"></a>00257 <span class="comment"> mpdfs ( i )->condition ( dls ( i )->get_cond ( val,cond ) );</span> |
241 | | <a name="l00258"></a>00258 <span class="comment"> }</span> |
242 | | <a name="l00259"></a>00259 <span class="comment"> // add logarithms</span> |
243 | | <a name="l00260"></a>00260 <span class="comment"> res += epdfs ( i )->evallog ( dls ( i )->pushdown ( val ) );*/</span> |
244 | | <a name="l00261"></a>00261 res += <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->evallogcond ( |
245 | | <a name="l00262"></a>00262 <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( i )->pushdown ( val ), |
246 | | <a name="l00263"></a>00263 <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( i )->get_cond ( val, cond ) |
247 | | <a name="l00264"></a>00264 ); |
248 | | <a name="l00265"></a>00265 } |
249 | | <a name="l00266"></a>00266 <span class="keywordflow">return</span> res; |
250 | | <a name="l00267"></a>00267 } |
251 | | <a name="l00268"></a>00268 <span class="comment">//TODO smarter...</span> |
252 | | <a name="l00269"></a><a class="code" href="classbdm_1_1mprod.html#ee715a8013acf9892f6cb489db595555">00269</a> vec <a class="code" href="classbdm_1_1mprod.html#ee715a8013acf9892f6cb489db595555" title="Returns a sample from the density conditioned on cond, .">samplecond</a> ( <span class="keyword">const</span> vec &cond ) { |
253 | | <a name="l00271"></a>00271 vec smp= std::numeric_limits<double>::infinity() * ones ( <a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>-><a class="code" href="classbdm_1_1epdf.html#7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>() ); |
254 | | <a name="l00272"></a>00272 vec smpi; |
255 | | <a name="l00273"></a>00273 <span class="comment">// Hard assumption here!!! We are going backwards, to assure that samples that are needed from smp are already generated!</span> |
256 | | <a name="l00274"></a>00274 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = ( <a class="code" href="classbdm_1_1compositepdf.html#7ca3cd8ed92a7154f5b9ff13b1e9d52a" title="Number of mpdfs in the composite.">n</a> - 1 );i >= 0;i-- ) { |
257 | | <a name="l00275"></a>00275 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->dimensionc() ) { |
258 | | <a name="l00276"></a>00276 <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->condition ( <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( i )->get_cond ( smp ,cond ) ); <span class="comment">// smp is val here!!</span> |
259 | | <a name="l00277"></a>00277 } |
260 | | <a name="l00278"></a>00278 smpi = <a class="code" href="classbdm_1_1mprod.html#eca722ed1b219727c6c0f8cbc6bf1e51" title="pointers to epdfs - shortcut to mpdfs().posterior()">epdfs</a> ( i )->sample(); |
261 | | <a name="l00279"></a>00279 <span class="comment">// copy contribution of this pdf into smp</span> |
262 | | <a name="l00280"></a>00280 <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( i )->pushup ( smp, smpi ); |
263 | | <a name="l00281"></a>00281 <span class="comment">// add ith likelihood contribution</span> |
264 | | <a name="l00282"></a>00282 } |
265 | | <a name="l00283"></a>00283 <span class="keywordflow">return</span> smp; |
266 | | <a name="l00284"></a>00284 } |
267 | | <a name="l00285"></a>00285 mat <a class="code" href="classbdm_1_1mprod.html#ee715a8013acf9892f6cb489db595555" title="Returns a sample from the density conditioned on cond, .">samplecond</a> ( <span class="keyword">const</span> vec &cond, <span class="keywordtype">int</span> N ) { |
268 | | <a name="l00286"></a>00286 mat Smp ( dimension(),N ); |
269 | | <a name="l00287"></a>00287 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<N;i++ ) {Smp.set_col ( i,<a class="code" href="classbdm_1_1mprod.html#ee715a8013acf9892f6cb489db595555" title="Returns a sample from the density conditioned on cond, .">samplecond</a> ( cond ) );} |
270 | | <a name="l00288"></a>00288 <span class="keywordflow">return</span> Smp; |
| 235 | <a name="l00252"></a>00252 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0; i<<a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length(); i++ ) { |
| 236 | <a name="l00253"></a>00253 <a class="code" href="classbdm_1_1mprod.html#eca722ed1b219727c6c0f8cbc6bf1e51" title="pointers to epdfs - shortcut to mpdfs().posterior()">epdfs</a> ( i ) =& ( <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->_epdf() ); |
| 237 | <a name="l00254"></a>00254 } |
| 238 | <a name="l00255"></a>00255 }; |
| 239 | <a name="l00256"></a>00256 |
| 240 | <a name="l00257"></a><a class="code" href="classbdm_1_1mprod.html#800f21d94c919137608a2fd5c88719e2">00257</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mprod.html#800f21d94c919137608a2fd5c88719e2" title="Shortcut for conditioning and evaluation of the internal epdf. In some cases, this...">evallogcond</a> ( <span class="keyword">const</span> vec &val, <span class="keyword">const</span> vec &cond ) { |
| 241 | <a name="l00258"></a>00258 <span class="keywordtype">int</span> i; |
| 242 | <a name="l00259"></a>00259 <span class="keywordtype">double</span> res = 0.0; |
| 243 | <a name="l00260"></a>00260 <span class="keywordflow">for</span> ( i = <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length() - 1;i >= 0;i-- ) { |
| 244 | <a name="l00261"></a>00261 <span class="comment">/* if ( mpdfs(i)->_rvc().count() >0) {</span> |
| 245 | <a name="l00262"></a>00262 <span class="comment"> mpdfs ( i )->condition ( dls ( i )->get_cond ( val,cond ) );</span> |
| 246 | <a name="l00263"></a>00263 <span class="comment"> }</span> |
| 247 | <a name="l00264"></a>00264 <span class="comment"> // add logarithms</span> |
| 248 | <a name="l00265"></a>00265 <span class="comment"> res += epdfs ( i )->evallog ( dls ( i )->pushdown ( val ) );*/</span> |
| 249 | <a name="l00266"></a>00266 res += <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->evallogcond ( |
| 250 | <a name="l00267"></a>00267 <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( i )->pushdown ( val ), |
| 251 | <a name="l00268"></a>00268 <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( i )->get_cond ( val, cond ) |
| 252 | <a name="l00269"></a>00269 ); |
| 253 | <a name="l00270"></a>00270 } |
| 254 | <a name="l00271"></a>00271 <span class="keywordflow">return</span> res; |
| 255 | <a name="l00272"></a>00272 } |
| 256 | <a name="l00273"></a>00273 <span class="comment">//TODO smarter...</span> |
| 257 | <a name="l00274"></a><a class="code" href="classbdm_1_1mprod.html#ee715a8013acf9892f6cb489db595555">00274</a> vec <a class="code" href="classbdm_1_1mprod.html#ee715a8013acf9892f6cb489db595555" title="Returns a sample from the density conditioned on cond, .">samplecond</a> ( <span class="keyword">const</span> vec &cond ) { |
| 258 | <a name="l00276"></a>00276 vec smp= std::numeric_limits<double>::infinity() * ones ( <a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>-><a class="code" href="classbdm_1_1epdf.html#7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>() ); |
| 259 | <a name="l00277"></a>00277 vec smpi; |
| 260 | <a name="l00278"></a>00278 <span class="comment">// Hard assumption here!!! We are going backwards, to assure that samples that are needed from smp are already generated!</span> |
| 261 | <a name="l00279"></a>00279 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = ( <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a>.length() - 1 );i >= 0;i-- ) { |
| 262 | <a name="l00280"></a>00280 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->dimensionc() ) { |
| 263 | <a name="l00281"></a>00281 <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->condition ( <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( i )->get_cond ( smp ,cond ) ); <span class="comment">// smp is val here!!</span> |
| 264 | <a name="l00282"></a>00282 } |
| 265 | <a name="l00283"></a>00283 smpi = <a class="code" href="classbdm_1_1mprod.html#eca722ed1b219727c6c0f8cbc6bf1e51" title="pointers to epdfs - shortcut to mpdfs().posterior()">epdfs</a> ( i )->sample(); |
| 266 | <a name="l00284"></a>00284 <span class="comment">// copy contribution of this pdf into smp</span> |
| 267 | <a name="l00285"></a>00285 <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( i )->pushup ( smp, smpi ); |
| 268 | <a name="l00286"></a>00286 <span class="comment">// add ith likelihood contribution</span> |
| 269 | <a name="l00287"></a>00287 } |
| 270 | <a name="l00288"></a>00288 <span class="keywordflow">return</span> smp; |
272 | | <a name="l00290"></a>00290 |
273 | | <a name="l00291"></a>00291 ~<a class="code" href="classbdm_1_1mprod.html#680c3e2d95b116c7cfb227c7f2984525" title="Constructor from list of mFacs,.">mprod</a>() {}; |
274 | | <a name="l00292"></a>00292 }; |
275 | | <a name="l00293"></a>00293 |
276 | | <a name="l00295"></a><a class="code" href="classbdm_1_1eprod.html">00295</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eprod.html" title="Product of independent epdfs. For dependent pdfs, use mprod.">eprod</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { |
277 | | <a name="l00296"></a>00296 <span class="keyword">protected</span>: |
278 | | <a name="l00298"></a><a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391">00298</a> Array<const epdf*> <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>; |
279 | | <a name="l00300"></a><a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43">00300</a> Array<datalink*> <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a>; |
280 | | <a name="l00301"></a>00301 <span class="keyword">public</span>: |
281 | | <a name="l00302"></a>00302 <a class="code" href="classbdm_1_1eprod.html" title="Product of independent epdfs. For dependent pdfs, use mprod.">eprod</a> () : <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( 0 ),<a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( 0 ) {}; |
282 | | <a name="l00303"></a>00303 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> Array<const epdf*> &epdfs0, <span class="keywordtype">bool</span> named=<span class="keyword">true</span> ) { |
283 | | <a name="l00304"></a>00304 <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>=epdfs0;<span class="comment">//.set_length ( epdfs0.length() );</span> |
284 | | <a name="l00305"></a>00305 <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a>.set_length ( <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length() ); |
285 | | <a name="l00306"></a>00306 |
286 | | <a name="l00307"></a>00307 <span class="keywordtype">bool</span> independent=<span class="keyword">true</span>; |
287 | | <a name="l00308"></a>00308 <span class="keywordflow">if</span> ( named ) { |
288 | | <a name="l00309"></a>00309 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
289 | | <a name="l00310"></a>00310 independent=<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#87841b5ee43997b79789c0c22047e224" title="Add (concat) another variable to the current one,.">add</a> ( <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )-><a class="code" href="classbdm_1_1epdf.html#a4ab378d5e004c3ff3e2d4e64f7bba21" title="Return name (fails when isnamed is false).">_rv</a>() ); |
290 | | <a name="l00311"></a>00311 it_assert_debug ( independent==<span class="keyword">true</span>, <span class="stringliteral">"eprod:: given components are not independent."</span> ); |
291 | | <a name="l00312"></a>00312 } |
292 | | <a name="l00313"></a>00313 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>=<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>._dsize(); |
293 | | <a name="l00314"></a>00314 } |
294 | | <a name="l00315"></a>00315 <span class="keywordflow">else</span> { |
295 | | <a name="l00316"></a>00316 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> =0; <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
296 | | <a name="l00317"></a>00317 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>+=<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->dimension(); |
297 | | <a name="l00318"></a>00318 } |
| 272 | <a name="l00290"></a>00290 mat <a class="code" href="classbdm_1_1mprod.html#ee715a8013acf9892f6cb489db595555" title="Returns a sample from the density conditioned on cond, .">samplecond</a> ( <span class="keyword">const</span> vec &cond, <span class="keywordtype">int</span> N ) { |
| 273 | <a name="l00291"></a>00291 mat Smp ( dimension(),N ); |
| 274 | <a name="l00292"></a>00292 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<N;i++ ) {Smp.set_col ( i,<a class="code" href="classbdm_1_1mprod.html#ee715a8013acf9892f6cb489db595555" title="Returns a sample from the density conditioned on cond, .">samplecond</a> ( cond ) );} |
| 275 | <a name="l00293"></a>00293 <span class="keywordflow">return</span> Smp; |
| 276 | <a name="l00294"></a>00294 } |
| 277 | <a name="l00295"></a>00295 |
| 278 | <a name="l00296"></a>00296 ~<a class="code" href="classbdm_1_1mprod.html#fed864cdd0e724d9133e6c6bfcacf94b" title="Constructor from list of mFacs,.">mprod</a>() {}; |
| 279 | <a name="l00297"></a>00297 }; |
| 280 | <a name="l00298"></a>00298 |
| 281 | <a name="l00300"></a><a class="code" href="classbdm_1_1eprod.html">00300</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eprod.html" title="Product of independent epdfs. For dependent pdfs, use mprod.">eprod</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { |
| 282 | <a name="l00301"></a>00301 <span class="keyword">protected</span>: |
| 283 | <a name="l00303"></a><a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391">00303</a> Array<const epdf*> <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>; |
| 284 | <a name="l00305"></a><a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43">00305</a> Array<datalink*> <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a>; |
| 285 | <a name="l00306"></a>00306 <span class="keyword">public</span>: |
| 286 | <a name="l00307"></a>00307 <a class="code" href="classbdm_1_1eprod.html" title="Product of independent epdfs. For dependent pdfs, use mprod.">eprod</a> () : <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( 0 ),<a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( 0 ) {}; |
| 287 | <a name="l00308"></a>00308 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> Array<const epdf*> &epdfs0, <span class="keywordtype">bool</span> named=<span class="keyword">true</span> ) { |
| 288 | <a name="l00309"></a>00309 <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>=epdfs0;<span class="comment">//.set_length ( epdfs0.length() );</span> |
| 289 | <a name="l00310"></a>00310 <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a>.set_length ( <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length() ); |
| 290 | <a name="l00311"></a>00311 |
| 291 | <a name="l00312"></a>00312 <span class="keywordtype">bool</span> independent=<span class="keyword">true</span>; |
| 292 | <a name="l00313"></a>00313 <span class="keywordflow">if</span> ( named ) { |
| 293 | <a name="l00314"></a>00314 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 294 | <a name="l00315"></a>00315 independent=rv.add ( <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )-><a class="code" href="classbdm_1_1epdf.html#a4ab378d5e004c3ff3e2d4e64f7bba21" title="Return name (fails when isnamed is false).">_rv</a>() ); |
| 295 | <a name="l00316"></a>00316 it_assert_debug ( independent==<span class="keyword">true</span>, <span class="stringliteral">"eprod:: given components are not independent."</span> ); |
| 296 | <a name="l00317"></a>00317 } |
| 297 | <a name="l00318"></a>00318 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>=rv._dsize(); |
299 | | <a name="l00320"></a>00320 <span class="comment">//</span> |
300 | | <a name="l00321"></a>00321 <span class="keywordtype">int</span> cumdim=0; |
301 | | <a name="l00322"></a>00322 <span class="keywordtype">int</span> dimi=0; |
302 | | <a name="l00323"></a>00323 <span class="keywordtype">int</span> i; |
303 | | <a name="l00324"></a>00324 <span class="keywordflow">for</span> ( i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
304 | | <a name="l00325"></a>00325 <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i ) = <span class="keyword">new</span> datalink; |
305 | | <a name="l00326"></a>00326 <span class="keywordflow">if</span> ( named ) {<a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i )->set_connection ( <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )-><a class="code" href="classbdm_1_1epdf.html#a4ab378d5e004c3ff3e2d4e64f7bba21" title="Return name (fails when isnamed is false).">_rv</a>() , <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> );} |
306 | | <a name="l00327"></a>00327 <span class="keywordflow">else</span> { |
307 | | <a name="l00328"></a>00328 dimi = <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->dimension(); |
308 | | <a name="l00329"></a>00329 <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i )->set_connection ( dimi, <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, linspace ( cumdim,cumdim+dimi-1 ) ); |
309 | | <a name="l00330"></a>00330 cumdim+=dimi; |
310 | | <a name="l00331"></a>00331 } |
311 | | <a name="l00332"></a>00332 } |
312 | | <a name="l00333"></a>00333 } |
313 | | <a name="l00334"></a>00334 |
314 | | <a name="l00335"></a><a class="code" href="classbdm_1_1eprod.html#1d494351e7e385ad3382387c96915d24">00335</a> vec <a class="code" href="classbdm_1_1eprod.html#1d494351e7e385ad3382387c96915d24" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
315 | | <a name="l00336"></a>00336 vec tmp ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
316 | | <a name="l00337"></a>00337 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
317 | | <a name="l00338"></a>00338 vec pom = <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->mean(); |
318 | | <a name="l00339"></a>00339 <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i )->pushup ( tmp, pom ); |
319 | | <a name="l00340"></a>00340 } |
320 | | <a name="l00341"></a>00341 <span class="keywordflow">return</span> tmp; |
321 | | <a name="l00342"></a>00342 } |
322 | | <a name="l00343"></a><a class="code" href="classbdm_1_1eprod.html#cc53a151f5ac5dfba68d425acc3a5615">00343</a> vec <a class="code" href="classbdm_1_1eprod.html#cc53a151f5ac5dfba68d425acc3a5615" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
323 | | <a name="l00344"></a>00344 vec tmp ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); <span class="comment">//second moment</span> |
324 | | <a name="l00345"></a>00345 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
325 | | <a name="l00346"></a>00346 vec pom = <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->mean(); |
326 | | <a name="l00347"></a>00347 <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i )->pushup ( tmp, pow ( pom,2 ) ); |
327 | | <a name="l00348"></a>00348 } |
328 | | <a name="l00349"></a>00349 <span class="keywordflow">return</span> tmp-pow ( <a class="code" href="classbdm_1_1eprod.html#1d494351e7e385ad3382387c96915d24" title="return expected value">mean</a>(),2 ); |
329 | | <a name="l00350"></a>00350 } |
330 | | <a name="l00351"></a><a class="code" href="classbdm_1_1eprod.html#af48debea25d3473bcb71b6a77fac741">00351</a> vec <a class="code" href="classbdm_1_1eprod.html#af48debea25d3473bcb71b6a77fac741" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
331 | | <a name="l00352"></a>00352 vec tmp ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
332 | | <a name="l00353"></a>00353 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
333 | | <a name="l00354"></a>00354 vec pom = <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->sample(); |
334 | | <a name="l00355"></a>00355 <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i )->pushup ( tmp, pom ); |
335 | | <a name="l00356"></a>00356 } |
336 | | <a name="l00357"></a>00357 <span class="keywordflow">return</span> tmp; |
337 | | <a name="l00358"></a>00358 } |
338 | | <a name="l00359"></a><a class="code" href="classbdm_1_1eprod.html#a5a91e67d2f74ff2b0b8eecde2fa42e2">00359</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eprod.html#a5a91e67d2f74ff2b0b8eecde2fa42e2" title="Compute log-probability of argument val.">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
339 | | <a name="l00360"></a>00360 <span class="keywordtype">double</span> tmp=0; |
340 | | <a name="l00361"></a>00361 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
341 | | <a name="l00362"></a>00362 tmp+=<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->evallog ( <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i )->pushdown ( val ) ); |
342 | | <a name="l00363"></a>00363 } |
343 | | <a name="l00364"></a>00364 it_assert_debug ( std::isfinite ( tmp ),<span class="stringliteral">"Infinite"</span> ); |
344 | | <a name="l00365"></a>00365 <span class="keywordflow">return</span> tmp; |
345 | | <a name="l00366"></a>00366 } |
346 | | <a name="l00368"></a><a class="code" href="classbdm_1_1eprod.html#5194b47dd05a5886e0745250b6704953">00368</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* <a class="code" href="classbdm_1_1eprod.html#5194b47dd05a5886e0745250b6704953" title="access function">operator () </a>( <span class="keywordtype">int</span> i )<span class="keyword"> const </span>{it_assert_debug ( i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length(),<span class="stringliteral">"wrong index"</span> );<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i );} |
347 | | <a name="l00369"></a>00369 |
348 | | <a name="l00371"></a><a class="code" href="classbdm_1_1eprod.html#708b37971aab3667f20e325c358632cf">00371</a> <a class="code" href="classbdm_1_1eprod.html#708b37971aab3667f20e325c358632cf" title="Destructor.">~eprod</a>() {<span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) {<span class="keyword">delete</span> <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i );}} |
349 | | <a name="l00372"></a>00372 }; |
350 | | <a name="l00373"></a>00373 |
| 299 | <a name="l00320"></a>00320 <span class="keywordflow">else</span> { |
| 300 | <a name="l00321"></a>00321 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> =0; <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 301 | <a name="l00322"></a>00322 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>+=<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->dimension(); |
| 302 | <a name="l00323"></a>00323 } |
| 303 | <a name="l00324"></a>00324 } |
| 304 | <a name="l00325"></a>00325 <span class="comment">//</span> |
| 305 | <a name="l00326"></a>00326 <span class="keywordtype">int</span> cumdim=0; |
| 306 | <a name="l00327"></a>00327 <span class="keywordtype">int</span> dimi=0; |
| 307 | <a name="l00328"></a>00328 <span class="keywordtype">int</span> i; |
| 308 | <a name="l00329"></a>00329 <span class="keywordflow">for</span> ( i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 309 | <a name="l00330"></a>00330 <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i ) = <span class="keyword">new</span> datalink; |
| 310 | <a name="l00331"></a>00331 <span class="keywordflow">if</span> ( named ) {<a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i )->set_connection ( <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )-><a class="code" href="classbdm_1_1epdf.html#a4ab378d5e004c3ff3e2d4e64f7bba21" title="Return name (fails when isnamed is false).">_rv</a>() , rv );} |
| 311 | <a name="l00332"></a>00332 <span class="keywordflow">else</span> { |
| 312 | <a name="l00333"></a>00333 dimi = <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->dimension(); |
| 313 | <a name="l00334"></a>00334 <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i )->set_connection ( dimi, <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, linspace ( cumdim,cumdim+dimi-1 ) ); |
| 314 | <a name="l00335"></a>00335 cumdim+=dimi; |
| 315 | <a name="l00336"></a>00336 } |
| 316 | <a name="l00337"></a>00337 } |
| 317 | <a name="l00338"></a>00338 } |
| 318 | <a name="l00339"></a>00339 |
| 319 | <a name="l00340"></a><a class="code" href="classbdm_1_1eprod.html#1d494351e7e385ad3382387c96915d24">00340</a> vec <a class="code" href="classbdm_1_1eprod.html#1d494351e7e385ad3382387c96915d24" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
| 320 | <a name="l00341"></a>00341 vec tmp ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
| 321 | <a name="l00342"></a>00342 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 322 | <a name="l00343"></a>00343 vec pom = <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->mean(); |
| 323 | <a name="l00344"></a>00344 <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i )->pushup ( tmp, pom ); |
| 324 | <a name="l00345"></a>00345 } |
| 325 | <a name="l00346"></a>00346 <span class="keywordflow">return</span> tmp; |
| 326 | <a name="l00347"></a>00347 } |
| 327 | <a name="l00348"></a><a class="code" href="classbdm_1_1eprod.html#cc53a151f5ac5dfba68d425acc3a5615">00348</a> vec <a class="code" href="classbdm_1_1eprod.html#cc53a151f5ac5dfba68d425acc3a5615" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
| 328 | <a name="l00349"></a>00349 vec tmp ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); <span class="comment">//second moment</span> |
| 329 | <a name="l00350"></a>00350 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 330 | <a name="l00351"></a>00351 vec pom = <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->mean(); |
| 331 | <a name="l00352"></a>00352 <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i )->pushup ( tmp, pow ( pom,2 ) ); |
| 332 | <a name="l00353"></a>00353 } |
| 333 | <a name="l00354"></a>00354 <span class="keywordflow">return</span> tmp-pow ( <a class="code" href="classbdm_1_1eprod.html#1d494351e7e385ad3382387c96915d24" title="return expected value">mean</a>(),2 ); |
| 334 | <a name="l00355"></a>00355 } |
| 335 | <a name="l00356"></a><a class="code" href="classbdm_1_1eprod.html#af48debea25d3473bcb71b6a77fac741">00356</a> vec <a class="code" href="classbdm_1_1eprod.html#af48debea25d3473bcb71b6a77fac741" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
| 336 | <a name="l00357"></a>00357 vec tmp ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
| 337 | <a name="l00358"></a>00358 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 338 | <a name="l00359"></a>00359 vec pom = <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->sample(); |
| 339 | <a name="l00360"></a>00360 <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i )->pushup ( tmp, pom ); |
| 340 | <a name="l00361"></a>00361 } |
| 341 | <a name="l00362"></a>00362 <span class="keywordflow">return</span> tmp; |
| 342 | <a name="l00363"></a>00363 } |
| 343 | <a name="l00364"></a><a class="code" href="classbdm_1_1eprod.html#a5a91e67d2f74ff2b0b8eecde2fa42e2">00364</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eprod.html#a5a91e67d2f74ff2b0b8eecde2fa42e2" title="Compute log-probability of argument val.">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
| 344 | <a name="l00365"></a>00365 <span class="keywordtype">double</span> tmp=0; |
| 345 | <a name="l00366"></a>00366 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 346 | <a name="l00367"></a>00367 tmp+=<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->evallog ( <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i )->pushdown ( val ) ); |
| 347 | <a name="l00368"></a>00368 } |
| 348 | <a name="l00369"></a>00369 it_assert_debug ( std::isfinite ( tmp ),<span class="stringliteral">"Infinite"</span> ); |
| 349 | <a name="l00370"></a>00370 <span class="keywordflow">return</span> tmp; |
| 350 | <a name="l00371"></a>00371 } |
| 351 | <a name="l00373"></a><a class="code" href="classbdm_1_1eprod.html#5194b47dd05a5886e0745250b6704953">00373</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* <a class="code" href="classbdm_1_1eprod.html#5194b47dd05a5886e0745250b6704953" title="access function">operator () </a>( <span class="keywordtype">int</span> i )<span class="keyword"> const </span>{it_assert_debug ( i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length(),<span class="stringliteral">"wrong index"</span> );<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i );} |
352 | | <a name="l00378"></a><a class="code" href="classbdm_1_1mmix.html">00378</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mmix.html" title="Mixture of mpdfs with constant weights, all mpdfs are of equal type.">mmix</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { |
353 | | <a name="l00379"></a>00379 <span class="keyword">protected</span>: |
354 | | <a name="l00381"></a><a class="code" href="classbdm_1_1mmix.html#52e0bcc70d5b26babeba08097579da9c">00381</a> Array<mpdf*> <a class="code" href="classbdm_1_1mmix.html#52e0bcc70d5b26babeba08097579da9c" title="Component (epdfs).">Coms</a>; |
355 | | <a name="l00383"></a><a class="code" href="classbdm_1_1mmix.html#0c4dd6ca6556ddd8ae3c5f3257c04b60">00383</a> <a class="code" href="classbdm_1_1emix.html" title="Mixture of epdfs.">emix</a> <a class="code" href="classbdm_1_1mmix.html#0c4dd6ca6556ddd8ae3c5f3257c04b60" title="Internal epdf.">Epdf</a>; |
356 | | <a name="l00384"></a>00384 <span class="keyword">public</span>: |
357 | | <a name="l00386"></a><a class="code" href="classbdm_1_1mmix.html#a0cf51b7daeb6751103e94e6b96213fb">00386</a> <a class="code" href="classbdm_1_1mmix.html#a0cf51b7daeb6751103e94e6b96213fb" title="Default constructor.">mmix</a> ( ) : <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( ), <a class="code" href="classbdm_1_1mmix.html#0c4dd6ca6556ddd8ae3c5f3257c04b60" title="Internal epdf.">Epdf</a> () {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a> = &<a class="code" href="classbdm_1_1mmix.html#0c4dd6ca6556ddd8ae3c5f3257c04b60" title="Internal epdf.">Epdf</a>;}; |
358 | | <a name="l00388"></a><a class="code" href="classbdm_1_1mmix.html#ad8d9df36cb0ca093a29af0eca12da32">00388</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mmix.html#ad8d9df36cb0ca093a29af0eca12da32" title="Set weights w and components R.">set_parameters</a> ( <span class="keyword">const</span> vec &w, <span class="keyword">const</span> Array<mpdf*> &<a class="code" href="classbdm_1_1mmix.html#52e0bcc70d5b26babeba08097579da9c" title="Component (epdfs).">Coms</a> ) { |
359 | | <a name="l00389"></a>00389 Array<epdf*> Eps ( Coms.length() ); |
360 | | <a name="l00390"></a>00390 |
361 | | <a name="l00391"></a>00391 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < Coms.length();i++ ) { |
362 | | <a name="l00392"></a>00392 Eps ( i ) = & ( <a class="code" href="classbdm_1_1mmix.html#52e0bcc70d5b26babeba08097579da9c" title="Component (epdfs).">Coms</a> ( i )->_epdf() ); |
363 | | <a name="l00393"></a>00393 } |
364 | | <a name="l00394"></a>00394 <a class="code" href="classbdm_1_1mmix.html#0c4dd6ca6556ddd8ae3c5f3257c04b60" title="Internal epdf.">Epdf</a>.<a class="code" href="classbdm_1_1emix.html#3a107a6b808a081389ef17af951c234a">set_parameters</a> ( w, Eps ); |
365 | | <a name="l00395"></a>00395 }; |
366 | | <a name="l00396"></a>00396 |
367 | | <a name="l00397"></a><a class="code" href="classbdm_1_1mmix.html#0a5241ecc9911e816b00b92d5c7c8df0">00397</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mmix.html#0a5241ecc9911e816b00b92d5c7c8df0" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &cond ) { |
368 | | <a name="l00398"></a>00398 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1mmix.html#52e0bcc70d5b26babeba08097579da9c" title="Component (epdfs).">Coms</a>.length();i++ ) {<a class="code" href="classbdm_1_1mmix.html#52e0bcc70d5b26babeba08097579da9c" title="Component (epdfs).">Coms</a> ( i )->condition ( cond );} |
369 | | <a name="l00399"></a>00399 }; |
370 | | <a name="l00400"></a>00400 }; |
| 353 | <a name="l00376"></a><a class="code" href="classbdm_1_1eprod.html#708b37971aab3667f20e325c358632cf">00376</a> <a class="code" href="classbdm_1_1eprod.html#708b37971aab3667f20e325c358632cf" title="Destructor.">~eprod</a>() {<span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length();i++ ) {<span class="keyword">delete</span> <a class="code" href="classbdm_1_1eprod.html#6b5a9be71a644f6009e7beda6c762a43" title="Array of indeces.">dls</a> ( i );}} |
| 354 | <a name="l00377"></a>00377 }; |
| 355 | <a name="l00378"></a>00378 |
| 356 | <a name="l00379"></a>00379 |
| 357 | <a name="l00383"></a><a class="code" href="classbdm_1_1mmix.html">00383</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mmix.html" title="Mixture of mpdfs with constant weights, all mpdfs are of equal type.">mmix</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { |
| 358 | <a name="l00384"></a>00384 <span class="keyword">protected</span>: |
| 359 | <a name="l00386"></a><a class="code" href="classbdm_1_1mmix.html#52e0bcc70d5b26babeba08097579da9c">00386</a> Array<mpdf*> <a class="code" href="classbdm_1_1mmix.html#52e0bcc70d5b26babeba08097579da9c" title="Component (epdfs).">Coms</a>; |
| 360 | <a name="l00388"></a><a class="code" href="classbdm_1_1mmix.html#0c4dd6ca6556ddd8ae3c5f3257c04b60">00388</a> <a class="code" href="classbdm_1_1emix.html" title="Mixture of epdfs.">emix</a> <a class="code" href="classbdm_1_1mmix.html#0c4dd6ca6556ddd8ae3c5f3257c04b60" title="Internal epdf.">Epdf</a>; |
| 361 | <a name="l00389"></a>00389 <span class="keyword">public</span>: |
| 362 | <a name="l00391"></a><a class="code" href="classbdm_1_1mmix.html#a0cf51b7daeb6751103e94e6b96213fb">00391</a> <a class="code" href="classbdm_1_1mmix.html#a0cf51b7daeb6751103e94e6b96213fb" title="Default constructor.">mmix</a> ( ) : <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( ), <a class="code" href="classbdm_1_1mmix.html#0c4dd6ca6556ddd8ae3c5f3257c04b60" title="Internal epdf.">Epdf</a> () {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a> = &<a class="code" href="classbdm_1_1mmix.html#0c4dd6ca6556ddd8ae3c5f3257c04b60" title="Internal epdf.">Epdf</a>;}; |
| 363 | <a name="l00393"></a><a class="code" href="classbdm_1_1mmix.html#ad8d9df36cb0ca093a29af0eca12da32">00393</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mmix.html#ad8d9df36cb0ca093a29af0eca12da32" title="Set weights w and components R.">set_parameters</a> ( <span class="keyword">const</span> vec &w, <span class="keyword">const</span> Array<mpdf*> &<a class="code" href="classbdm_1_1mmix.html#52e0bcc70d5b26babeba08097579da9c" title="Component (epdfs).">Coms</a> ) { |
| 364 | <a name="l00394"></a>00394 Array<epdf*> Eps ( Coms.length() ); |
| 365 | <a name="l00395"></a>00395 |
| 366 | <a name="l00396"></a>00396 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < Coms.length();i++ ) { |
| 367 | <a name="l00397"></a>00397 Eps ( i ) = & ( <a class="code" href="classbdm_1_1mmix.html#52e0bcc70d5b26babeba08097579da9c" title="Component (epdfs).">Coms</a> ( i )->_epdf() ); |
| 368 | <a name="l00398"></a>00398 } |
| 369 | <a name="l00399"></a>00399 <a class="code" href="classbdm_1_1mmix.html#0c4dd6ca6556ddd8ae3c5f3257c04b60" title="Internal epdf.">Epdf</a>.<a class="code" href="classbdm_1_1emix.html#3a107a6b808a081389ef17af951c234a">set_parameters</a> ( w, Eps ); |
| 370 | <a name="l00400"></a>00400 }; |