[106] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
| 2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
---|
[261] | 3 | <title>mixpp: emix.h Source File</title> |
---|
[106] | 4 | <link href="doxygen.css" rel="stylesheet" type="text/css"> |
---|
| 5 | <link href="tabs.css" rel="stylesheet" type="text/css"> |
---|
| 6 | </head><body> |
---|
[139] | 7 | <!-- Generated by Doxygen 1.5.6 --> |
---|
[106] | 8 | <div class="navigation" id="top"> |
---|
| 9 | <div class="tabs"> |
---|
| 10 | <ul> |
---|
| 11 | <li><a href="index.html"><span>Main Page</span></a></li> |
---|
| 12 | <li><a href="pages.html"><span>Related Pages</span></a></li> |
---|
[219] | 13 | <li><a href="modules.html"><span>Modules</span></a></li> |
---|
[261] | 14 | <li><a href="namespaces.html"><span>Namespaces</span></a></li> |
---|
| 15 | <li><a href="classes.html"><span>Classes</span></a></li> |
---|
[106] | 16 | <li class="current"><a href="files.html"><span>Files</span></a></li> |
---|
| 17 | </ul> |
---|
| 18 | </div> |
---|
[261] | 19 | <h1>emix.h</h1><a href="emix_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 |
---|
[106] | 20 | <a name="l00013"></a>00013 <span class="preprocessor">#ifndef MX_H</span> |
---|
| 21 | <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define MX_H</span> |
---|
| 22 | <a name="l00015"></a>00015 <span class="preprocessor"></span> |
---|
| 23 | <a name="l00016"></a>00016 <span class="preprocessor">#include "<a class="code" href="libBM_8h.html" title="Bayesian Models (bm) that use Bayes rule to learn from observations.">libBM.h</a>"</span> |
---|
| 24 | <a name="l00017"></a>00017 <span class="preprocessor">#include "<a class="code" href="libEF_8h.html" title="Probability distributions for Exponential Family models.">libEF.h</a>"</span> |
---|
| 25 | <a name="l00018"></a>00018 <span class="comment">//#include <std></span> |
---|
| 26 | <a name="l00019"></a>00019 |
---|
[255] | 27 | <a name="l00020"></a>00020 <span class="keyword">namespace </span>bdm{ |
---|
[106] | 28 | <a name="l00021"></a>00021 |
---|
[210] | 29 | <a name="l00022"></a>00022 <span class="comment">//this comes first because it is used inside emix!</span> |
---|
| 30 | <a name="l00023"></a>00023 |
---|
[255] | 31 | <a name="l00036"></a><a class="code" href="classbdm_1_1mratio.html">00036</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mratio.html" title="Class representing ratio of two densities which arise e.g. by applying the Bayes...">mratio</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> { |
---|
[210] | 32 | <a name="l00037"></a>00037 <span class="keyword">protected</span>: |
---|
[255] | 33 | <a name="l00039"></a><a class="code" href="classbdm_1_1mratio.html#f31caba90a2aa10fbf7631832404fe54">00039</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_1mratio.html#f31caba90a2aa10fbf7631832404fe54" title="Nominator in the form of mpdf.">nom</a>; |
---|
| 34 | <a name="l00041"></a><a class="code" href="classbdm_1_1mratio.html#7daa5d02d3a3be9d15fd4156d886ed88">00041</a> <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_1mratio.html#7daa5d02d3a3be9d15fd4156d886ed88" title="Denominator in the form of epdf.">den</a>; |
---|
| 35 | <a name="l00043"></a><a class="code" href="classbdm_1_1mratio.html#51bfe6675e724f7fbeaaeacce5a9f9b8">00043</a> <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1mratio.html#51bfe6675e724f7fbeaaeacce5a9f9b8" title="flag for destructor">destroynom</a>; |
---|
| 36 | <a name="l00045"></a><a class="code" href="classbdm_1_1mratio.html#cda5bd23ba60146d69e1f804ff7710c7">00045</a> <a class="code" href="classbdm_1_1datalink__m2e.html" title="data link between">datalink_m2e</a> <a class="code" href="classbdm_1_1mratio.html#cda5bd23ba60146d69e1f804ff7710c7" title="datalink between conditional and nom">dl</a>; |
---|
[210] | 37 | <a name="l00046"></a>00046 <span class="keyword">public</span>: |
---|
[255] | 38 | <a name="l00049"></a><a class="code" href="classbdm_1_1mratio.html#0ff56d13f9515d7e5f23b7a4cc5529b4">00049</a> <a class="code" href="classbdm_1_1mratio.html#0ff56d13f9515d7e5f23b7a4cc5529b4">mratio</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>* nom0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classbdm_1_1mpdf.html#9bcfb45435d30983f436d41c298cbb51" title="modeled random variable">rv</a>, <span class="keywordtype">bool</span> copy=<span class="keyword">false</span> ) :<a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( rv,nom0-><a class="code" href="classbdm_1_1mpdf.html#222d5280e309c5a053ba73841e98c151" title="access function">_rv</a>().subt ( rv ) ), <a class="code" href="classbdm_1_1mratio.html#cda5bd23ba60146d69e1f804ff7710c7" title="datalink between conditional and nom">dl</a> ( rv,<a class="code" href="classbdm_1_1mpdf.html#5a5f08950daa08b85b01ddf4e1c36288" title="random variable in condition">rvc</a>,nom0-><a class="code" href="classbdm_1_1mpdf.html#222d5280e309c5a053ba73841e98c151" title="access function">_rv</a>() ) { |
---|
[210] | 39 | <a name="l00050"></a>00050 <span class="keywordflow">if</span> ( copy ) { |
---|
| 40 | <a name="l00051"></a>00051 <span class="comment">// nom = nom0->_copy_();</span> |
---|
| 41 | <a name="l00052"></a>00052 it_error ( <span class="stringliteral">"todo"</span> ); |
---|
[255] | 42 | <a name="l00053"></a>00053 <a class="code" href="classbdm_1_1mratio.html#51bfe6675e724f7fbeaaeacce5a9f9b8" title="flag for destructor">destroynom</a>=<span class="keyword">true</span>; |
---|
[210] | 43 | <a name="l00054"></a>00054 } |
---|
| 44 | <a name="l00055"></a>00055 <span class="keywordflow">else</span> { |
---|
[255] | 45 | <a name="l00056"></a>00056 <a class="code" href="classbdm_1_1mratio.html#f31caba90a2aa10fbf7631832404fe54" title="Nominator in the form of mpdf.">nom</a> = nom0; |
---|
| 46 | <a name="l00057"></a>00057 <a class="code" href="classbdm_1_1mratio.html#51bfe6675e724f7fbeaaeacce5a9f9b8" title="flag for destructor">destroynom</a> = <span class="keyword">false</span>; |
---|
[210] | 47 | <a name="l00058"></a>00058 } |
---|
[255] | 48 | <a name="l00059"></a>00059 it_assert_debug ( <a class="code" href="classbdm_1_1mpdf.html#5a5f08950daa08b85b01ddf4e1c36288" title="random variable in condition">rvc</a>.<a class="code" href="classbdm_1_1RV.html#e9ec8c3e756651ff352ab5e3d3acda4b" title="Return length (number of entries) of the RV.">length</a>() >0,<span class="stringliteral">"Makes no sense to use this object!"</span> ); |
---|
| 49 | <a name="l00060"></a>00060 <a class="code" href="classbdm_1_1mratio.html#7daa5d02d3a3be9d15fd4156d886ed88" title="Denominator in the form of epdf.">den</a> = <a class="code" href="classbdm_1_1mratio.html#f31caba90a2aa10fbf7631832404fe54" title="Nominator in the form of mpdf.">nom</a>-><a class="code" href="classbdm_1_1epdf.html#3fb2ece54f720b62ad325e61214fa0a1" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> ( <a class="code" href="classbdm_1_1mpdf.html#5a5f08950daa08b85b01ddf4e1c36288" title="random variable in condition">rvc</a> ); |
---|
[210] | 50 | <a name="l00061"></a>00061 }; |
---|
[255] | 51 | <a name="l00062"></a><a class="code" href="classbdm_1_1mratio.html#3a2cbce8c61ca9f592d9c2220f7c1204">00062</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mratio.html#3a2cbce8c61ca9f592d9c2220f7c1204" 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 ) { |
---|
[219] | 52 | <a name="l00063"></a>00063 <span class="keywordtype">double</span> tmp; |
---|
[255] | 53 | <a name="l00064"></a>00064 vec nom_val ( <a class="code" href="classbdm_1_1mpdf.html#9bcfb45435d30983f436d41c298cbb51" title="modeled random variable">rv</a>.<a class="code" href="classbdm_1_1RV.html#2174751a00ce19f941edd2c1a861be67" title="Return number of scalars in the RV.">count</a>() +<a class="code" href="classbdm_1_1mpdf.html#5a5f08950daa08b85b01ddf4e1c36288" title="random variable in condition">rvc</a>.<a class="code" href="classbdm_1_1RV.html#2174751a00ce19f941edd2c1a861be67" title="Return number of scalars in the RV.">count</a>() ); |
---|
| 54 | <a name="l00065"></a>00065 <a class="code" href="classbdm_1_1mratio.html#cda5bd23ba60146d69e1f804ff7710c7" title="datalink between conditional and nom">dl</a>.<a class="code" href="classbdm_1_1datalink__m2e.html#d6803ec2e8c9e844d54d99b6686b0701">fill_val_cond</a> ( nom_val,val,cond ); |
---|
| 55 | <a name="l00066"></a>00066 tmp = exp ( <a class="code" href="classbdm_1_1mratio.html#f31caba90a2aa10fbf7631832404fe54" title="Nominator in the form of mpdf.">nom</a>-><a class="code" href="classbdm_1_1epdf.html#a8e39e2ff5e5cf5471bc159530d3b2d3" title="Compute log-probability of argument val.">evallog</a> ( nom_val ) - <a class="code" href="classbdm_1_1mratio.html#7daa5d02d3a3be9d15fd4156d886ed88" title="Denominator in the form of epdf.">den</a>-><a class="code" href="classbdm_1_1epdf.html#a8e39e2ff5e5cf5471bc159530d3b2d3" title="Compute log-probability of argument val.">evallog</a> ( cond ) ); |
---|
[219] | 56 | <a name="l00067"></a>00067 it_assert_debug(std::isfinite(tmp),<span class="stringliteral">"Infinite value"</span>); |
---|
| 57 | <a name="l00068"></a>00068 <span class="keywordflow">return</span> tmp; |
---|
| 58 | <a name="l00069"></a>00069 } |
---|
[255] | 59 | <a name="l00071"></a><a class="code" href="classbdm_1_1mratio.html#c8b39fea586d4258bb3c881406edaf15">00071</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mratio.html#c8b39fea586d4258bb3c881406edaf15" title="Object takes ownership of nom and will destroy it.">ownnom</a>() {<a class="code" href="classbdm_1_1mratio.html#51bfe6675e724f7fbeaaeacce5a9f9b8" title="flag for destructor">destroynom</a>=<span class="keyword">true</span>;} |
---|
| 60 | <a name="l00073"></a><a class="code" href="classbdm_1_1mratio.html#c0cc0b25dbdc54751466616655454c5c">00073</a> <a class="code" href="classbdm_1_1mratio.html#c0cc0b25dbdc54751466616655454c5c" title="Default destructor.">~mratio</a>() {<span class="keyword">delete</span> <a class="code" href="classbdm_1_1mratio.html#7daa5d02d3a3be9d15fd4156d886ed88" title="Denominator in the form of epdf.">den</a>; <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1mratio.html#51bfe6675e724f7fbeaaeacce5a9f9b8" title="flag for destructor">destroynom</a> ) {<span class="keyword">delete</span> <a class="code" href="classbdm_1_1mratio.html#f31caba90a2aa10fbf7631832404fe54" title="Nominator in the form of mpdf.">nom</a>;}} |
---|
[219] | 61 | <a name="l00074"></a>00074 }; |
---|
| 62 | <a name="l00075"></a>00075 |
---|
[255] | 63 | <a name="l00086"></a><a class="code" href="classbdm_1_1emix.html">00086</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1emix.html" title="Mixture of epdfs.">emix</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> { |
---|
[219] | 64 | <a name="l00087"></a>00087 <span class="keyword">protected</span>: |
---|
[255] | 65 | <a name="l00089"></a><a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46">00089</a> vec <a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a>; |
---|
| 66 | <a name="l00091"></a><a class="code" href="classbdm_1_1emix.html#e2966a6a44b250e22e55bc9fb6af5c3e">00091</a> Array<epdf*> <a class="code" href="classbdm_1_1emix.html#e2966a6a44b250e22e55bc9fb6af5c3e" title="Component (epdfs).">Coms</a>; |
---|
| 67 | <a name="l00093"></a><a class="code" href="classbdm_1_1emix.html#47189df41a4616c2fed5972f015743f4">00093</a> <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1emix.html#47189df41a4616c2fed5972f015743f4" title="Flag if owning Coms.">destroyComs</a>; |
---|
[219] | 68 | <a name="l00094"></a>00094 <span class="keyword">public</span>: |
---|
[255] | 69 | <a name="l00096"></a><a class="code" href="classbdm_1_1emix.html#38649cee71ed9d8c32cfe8bb4b78a98b">00096</a> <a class="code" href="classbdm_1_1emix.html#38649cee71ed9d8c32cfe8bb4b78a98b" title="Default constructor.">emix</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Identified of the random variable.">rv</a> ) : <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( rv ) {}; |
---|
| 70 | <a name="l00099"></a>00099 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1emix.html#d8c1aefba8302759836b5f26999ce840">set_parameters</a> ( <span class="keyword">const</span> vec &<a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a>, <span class="keyword">const</span> Array<epdf*> &<a class="code" href="classbdm_1_1emix.html#e2966a6a44b250e22e55bc9fb6af5c3e" title="Component (epdfs).">Coms</a>, <span class="keywordtype">bool</span> copy=<span class="keyword">true</span> ); |
---|
[219] | 71 | <a name="l00100"></a>00100 |
---|
[255] | 72 | <a name="l00101"></a>00101 vec <a class="code" href="classbdm_1_1emix.html#e8839dbbb0d1276a8dbe957a67cfe0dc" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
---|
| 73 | <a name="l00102"></a><a class="code" href="classbdm_1_1emix.html#a3a5390bc56e81ef3b0debc0f185fa8a">00102</a> vec <a class="code" href="classbdm_1_1emix.html#a3a5390bc56e81ef3b0debc0f185fa8a" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
---|
| 74 | <a name="l00103"></a>00103 <span class="keywordtype">int</span> i; vec mu = zeros ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Identified of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#2174751a00ce19f941edd2c1a861be67" title="Return number of scalars in the RV.">count</a>() ); |
---|
| 75 | <a name="l00104"></a>00104 <span class="keywordflow">for</span> ( i = 0;i < <a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a>.length();i++ ) {mu += <a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a> ( i ) * <a class="code" href="classbdm_1_1emix.html#e2966a6a44b250e22e55bc9fb6af5c3e" title="Component (epdfs).">Coms</a> ( i )->mean(); } |
---|
[219] | 76 | <a name="l00105"></a>00105 <span class="keywordflow">return</span> mu; |
---|
| 77 | <a name="l00106"></a>00106 } |
---|
[255] | 78 | <a name="l00107"></a><a class="code" href="classbdm_1_1emix.html#e9a627023cdf90c9ffd8eef726595c86">00107</a> vec <a class="code" href="classbdm_1_1emix.html#e9a627023cdf90c9ffd8eef726595c86" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
---|
[234] | 79 | <a name="l00108"></a>00108 <span class="comment">//non-central moment</span> |
---|
[255] | 80 | <a name="l00109"></a>00109 vec mom2 = zeros(<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Identified of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#2174751a00ce19f941edd2c1a861be67" title="Return number of scalars in the RV.">count</a>()); |
---|
| 81 | <a name="l00110"></a>00110 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a>.length();i++ ) {mom2 += <a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a> ( i ) * pow(<a class="code" href="classbdm_1_1emix.html#e2966a6a44b250e22e55bc9fb6af5c3e" title="Component (epdfs).">Coms</a> ( i )-><a class="code" href="classbdm_1_1emix.html#a3a5390bc56e81ef3b0debc0f185fa8a" title="return expected value">mean</a>(),2); } |
---|
[234] | 82 | <a name="l00111"></a>00111 <span class="comment">//central moment</span> |
---|
[255] | 83 | <a name="l00112"></a>00112 <span class="keywordflow">return</span> mom2-pow(<a class="code" href="classbdm_1_1emix.html#a3a5390bc56e81ef3b0debc0f185fa8a" title="return expected value">mean</a>(),2); |
---|
[234] | 84 | <a name="l00113"></a>00113 } |
---|
[255] | 85 | <a name="l00114"></a><a class="code" href="classbdm_1_1emix.html#0f3db99f730bde6b7953931594537e8e">00114</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1emix.html#0f3db99f730bde6b7953931594537e8e" title="Compute log-probability of argument val.">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
---|
[234] | 86 | <a name="l00115"></a>00115 <span class="keywordtype">int</span> i; |
---|
| 87 | <a name="l00116"></a>00116 <span class="keywordtype">double</span> sum = 0.0; |
---|
[255] | 88 | <a name="l00117"></a>00117 <span class="keywordflow">for</span> ( i = 0;i < <a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a>.length();i++ ) {sum += <a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a> ( i ) * exp ( <a class="code" href="classbdm_1_1emix.html#e2966a6a44b250e22e55bc9fb6af5c3e" title="Component (epdfs).">Coms</a> ( i )-><a class="code" href="classbdm_1_1emix.html#0f3db99f730bde6b7953931594537e8e" title="Compute log-probability of argument val.">evallog</a> ( val ) );} |
---|
[234] | 89 | <a name="l00118"></a>00118 <span class="keywordflow">if</span> (sum==0.0){sum=std::numeric_limits<double>::epsilon();} |
---|
| 90 | <a name="l00119"></a>00119 <span class="keywordtype">double</span> tmp=log ( sum ); |
---|
| 91 | <a name="l00120"></a>00120 it_assert_debug(std::isfinite(tmp),<span class="stringliteral">"Infinite"</span>); |
---|
| 92 | <a name="l00121"></a>00121 <span class="keywordflow">return</span> tmp; |
---|
[219] | 93 | <a name="l00122"></a>00122 }; |
---|
[255] | 94 | <a name="l00123"></a><a class="code" href="classbdm_1_1emix.html#23af1986e2afcbc8c7e1c30f610e703b">00123</a> vec <a class="code" href="classbdm_1_1emix.html#23af1986e2afcbc8c7e1c30f610e703b" title="Compute log-probability of multiple values argument val.">evallog_m</a> ( <span class="keyword">const</span> mat &Val )<span class="keyword"> const </span>{ |
---|
[234] | 95 | <a name="l00124"></a>00124 vec x=zeros ( Val.cols() ); |
---|
[255] | 96 | <a name="l00125"></a>00125 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a>.length(); i++ ) { |
---|
| 97 | <a name="l00126"></a>00126 x+= <a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a> ( i ) *exp ( <a class="code" href="classbdm_1_1emix.html#e2966a6a44b250e22e55bc9fb6af5c3e" title="Component (epdfs).">Coms</a> ( i )-><a class="code" href="classbdm_1_1emix.html#23af1986e2afcbc8c7e1c30f610e703b" title="Compute log-probability of multiple values argument val.">evallog_m</a> ( Val ) ); |
---|
[234] | 98 | <a name="l00127"></a>00127 } |
---|
| 99 | <a name="l00128"></a>00128 <span class="keywordflow">return</span> log ( x ); |
---|
| 100 | <a name="l00129"></a>00129 }; |
---|
[255] | 101 | <a name="l00131"></a><a class="code" href="classbdm_1_1emix.html#e64c1d5a73f541e469792e23d4677af2">00131</a> mat <a class="code" href="classbdm_1_1emix.html#e64c1d5a73f541e469792e23d4677af2" title="Auxiliary function that returns pdflog for each component.">evallog_M</a> ( <span class="keyword">const</span> mat &Val )<span class="keyword"> const </span>{ |
---|
| 102 | <a name="l00132"></a>00132 mat X ( <a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a>.length(), Val.cols() ); |
---|
| 103 | <a name="l00133"></a>00133 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < <a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a>.length(); i++ ) { |
---|
| 104 | <a name="l00134"></a>00134 X.set_row ( i, <a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a> ( i ) *exp ( <a class="code" href="classbdm_1_1emix.html#e2966a6a44b250e22e55bc9fb6af5c3e" title="Component (epdfs).">Coms</a> ( i )-><a class="code" href="classbdm_1_1emix.html#23af1986e2afcbc8c7e1c30f610e703b" title="Compute log-probability of multiple values argument val.">evallog_m</a> ( Val ) ) ); |
---|
[234] | 105 | <a name="l00135"></a>00135 } |
---|
| 106 | <a name="l00136"></a>00136 <span class="keywordflow">return</span> X; |
---|
| 107 | <a name="l00137"></a>00137 }; |
---|
| 108 | <a name="l00138"></a>00138 |
---|
[255] | 109 | <a name="l00139"></a>00139 <a class="code" href="classbdm_1_1emix.html" title="Mixture of epdfs.">emix</a>* <a class="code" href="classbdm_1_1emix.html#f7165371cc4f7be9292024b9f5431646" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Identified of the random variable.">rv</a> ) <span class="keyword">const</span>; |
---|
| 110 | <a name="l00140"></a>00140 <a class="code" href="classbdm_1_1mratio.html" title="Class representing ratio of two densities which arise e.g. by applying the Bayes...">mratio</a>* <a class="code" href="classbdm_1_1emix.html#fc7772a2972959cf19ba26882feacecf" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">condition</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Identified of the random variable.">rv</a> ) <span class="keyword">const</span>; <span class="comment">//why not mratio!!</span> |
---|
[219] | 111 | <a name="l00141"></a>00141 |
---|
[234] | 112 | <a name="l00142"></a>00142 <span class="comment">//Access methods</span> |
---|
[255] | 113 | <a name="l00144"></a><a class="code" href="classbdm_1_1emix.html#d9b584cb5b2471a4250fb127757f28be">00144</a> <span class="comment"></span> vec& <a class="code" href="classbdm_1_1emix.html#d9b584cb5b2471a4250fb127757f28be" title="returns a pointer to the internal mean value. Use with Care!">_w</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1emix.html#bb7270345c76da627cd77ddf020bcf46" title="weights of the components">w</a>;} |
---|
| 114 | <a name="l00145"></a>00145 <span class="keyword">virtual</span> ~<a class="code" href="classbdm_1_1emix.html" title="Mixture of epdfs.">emix</a>() {<span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1emix.html#47189df41a4616c2fed5972f015743f4" title="Flag if owning Coms.">destroyComs</a> ) {<span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1emix.html#e2966a6a44b250e22e55bc9fb6af5c3e" title="Component (epdfs).">Coms</a>.length();i++ ) {<span class="keyword">delete</span> <a class="code" href="classbdm_1_1emix.html#e2966a6a44b250e22e55bc9fb6af5c3e" title="Component (epdfs).">Coms</a> ( i );}}} |
---|
| 115 | <a name="l00147"></a><a class="code" href="classbdm_1_1emix.html#965fb16669250a3d28bc62cf76276d8e">00147</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1emix.html#965fb16669250a3d28bc62cf76276d8e" title="Auxiliary function for taking ownership of the Coms().">ownComs</a>() {<a class="code" href="classbdm_1_1emix.html#47189df41a4616c2fed5972f015743f4" title="Flag if owning Coms.">destroyComs</a>=<span class="keyword">true</span>;} |
---|
[234] | 116 | <a name="l00148"></a>00148 |
---|
[255] | 117 | <a name="l00150"></a><a class="code" href="classbdm_1_1emix.html#578616445243674438257be99ba71612">00150</a> <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_1emix.html#578616445243674438257be99ba71612" title="access function">_Coms</a> ( <span class="keywordtype">int</span> i ) {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1emix.html#e2966a6a44b250e22e55bc9fb6af5c3e" title="Component (epdfs).">Coms</a> ( i );} |
---|
[234] | 118 | <a name="l00151"></a>00151 }; |
---|
| 119 | <a name="l00152"></a>00152 |
---|
[261] | 120 | <a name="l00161"></a><a class="code" href="classbdm_1_1mprod.html">00161</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mprod.html" title="Chain rule decomposition of epdf.">mprod</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1compositepdf.html" title="Abstract composition of pdfs, will be used for specific classes this abstract class...">compositepdf</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> { |
---|
[234] | 121 | <a name="l00162"></a>00162 <span class="keyword">protected</span>: |
---|
[255] | 122 | <a name="l00164"></a><a class="code" href="classbdm_1_1mprod.html#eca722ed1b219727c6c0f8cbc6bf1e51">00164</a> Array<epdf*> <a class="code" href="classbdm_1_1mprod.html#eca722ed1b219727c6c0f8cbc6bf1e51" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a>; |
---|
| 123 | <a name="l00166"></a><a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f">00166</a> Array<datalink_m2m*> <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a>; |
---|
[234] | 124 | <a name="l00167"></a>00167 <span class="keyword">public</span>: |
---|
[261] | 125 | <a name="l00170"></a><a class="code" href="classbdm_1_1mprod.html#680c3e2d95b116c7cfb227c7f2984525">00170</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_1compositepdf.html#c73d39acc4378eee6a63155c3517d3c9" title="find common rv, flag">getrv</a> ( true ),<a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a>() ), <a class="code" href="classbdm_1_1mprod.html#eca722ed1b219727c6c0f8cbc6bf1e51" title="pointers to epdfs - shortcut to mpdfs()._epdf()">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> ) { |
---|
[255] | 126 | <a name="l00171"></a>00171 <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#9bcfb45435d30983f436d41c298cbb51" title="modeled random variable">rv</a>,<a class="code" href="classbdm_1_1mpdf.html#5a5f08950daa08b85b01ddf4e1c36288" title="random variable in condition">rvc</a> ); |
---|
[234] | 127 | <a name="l00172"></a>00172 <span class="comment">// rv and rvc established = > we can link them with mpdfs</span> |
---|
[255] | 128 | <a name="l00173"></a>00173 <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++ ) { |
---|
| 129 | <a name="l00174"></a>00174 <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> ( <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )-><a class="code" href="classbdm_1_1mpdf.html#222d5280e309c5a053ba73841e98c151" title="access function">_rv</a>(), <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )-><a class="code" href="classbdm_1_1mpdf.html#b3aba7311038bf990d706a64cab60cf8" title="access function">_rvc</a>(), <a class="code" href="classbdm_1_1mpdf.html#9bcfb45435d30983f436d41c298cbb51" title="modeled random variable">rv</a>, <a class="code" href="classbdm_1_1mpdf.html#5a5f08950daa08b85b01ddf4e1c36288" title="random variable in condition">rvc</a> ); |
---|
[234] | 130 | <a name="l00175"></a>00175 } |
---|
| 131 | <a name="l00176"></a>00176 |
---|
| 132 | <a name="l00177"></a>00177 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<n;i++ ) { |
---|
[255] | 133 | <a name="l00178"></a>00178 <a class="code" href="classbdm_1_1mprod.html#eca722ed1b219727c6c0f8cbc6bf1e51" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i ) =& ( <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->_epdf() ); |
---|
[234] | 134 | <a name="l00179"></a>00179 } |
---|
| 135 | <a name="l00180"></a>00180 }; |
---|
| 136 | <a name="l00181"></a>00181 |
---|
[255] | 137 | <a name="l00182"></a><a class="code" href="classbdm_1_1mprod.html#800f21d94c919137608a2fd5c88719e2">00182</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 ) { |
---|
[234] | 138 | <a name="l00183"></a>00183 <span class="keywordtype">int</span> i; |
---|
| 139 | <a name="l00184"></a>00184 <span class="keywordtype">double</span> res = 1.0; |
---|
[255] | 140 | <a name="l00185"></a>00185 <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-- ) { |
---|
[234] | 141 | <a name="l00186"></a>00186 <span class="comment">/* if ( mpdfs(i)->_rvc().count() >0) {</span> |
---|
| 142 | <a name="l00187"></a>00187 <span class="comment"> mpdfs ( i )->condition ( dls ( i )->get_cond ( val,cond ) );</span> |
---|
| 143 | <a name="l00188"></a>00188 <span class="comment"> }</span> |
---|
| 144 | <a name="l00189"></a>00189 <span class="comment"> // add logarithms</span> |
---|
| 145 | <a name="l00190"></a>00190 <span class="comment"> res += epdfs ( i )->evallog ( dls ( i )->get_val ( val ) );*/</span> |
---|
[255] | 146 | <a name="l00191"></a>00191 res *= <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->evallogcond ( |
---|
| 147 | <a name="l00192"></a>00192 <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( i )->get_val ( val ), |
---|
| 148 | <a name="l00193"></a>00193 <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( i )->get_cond ( val, cond ) |
---|
[234] | 149 | <a name="l00194"></a>00194 ); |
---|
| 150 | <a name="l00195"></a>00195 } |
---|
| 151 | <a name="l00196"></a>00196 <span class="keywordflow">return</span> res; |
---|
| 152 | <a name="l00197"></a>00197 } |
---|
[255] | 153 | <a name="l00198"></a><a class="code" href="classbdm_1_1mprod.html#1a37c2aaba8bde7fce5351c39b6e1168">00198</a> vec <a class="code" href="classbdm_1_1mprod.html#1a37c2aaba8bde7fce5351c39b6e1168" title="Returns a sample from the density conditioned on cond, .">samplecond</a> ( <span class="keyword">const</span> vec &cond, <span class="keywordtype">double</span> &ll ) { |
---|
| 154 | <a name="l00200"></a>00200 vec smp= std::numeric_limits<double>::infinity() * ones ( <a class="code" href="classbdm_1_1mpdf.html#9bcfb45435d30983f436d41c298cbb51" title="modeled random variable">rv</a>.<a class="code" href="classbdm_1_1RV.html#2174751a00ce19f941edd2c1a861be67" title="Return number of scalars in the RV.">count</a>() ); |
---|
[234] | 155 | <a name="l00201"></a>00201 vec smpi; |
---|
| 156 | <a name="l00202"></a>00202 ll = 0; |
---|
| 157 | <a name="l00203"></a>00203 <span class="comment">// Hard assumption here!!! We are going backwards, to assure that samples that are needed from smp are already generated!</span> |
---|
[255] | 158 | <a name="l00204"></a>00204 <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-- ) { |
---|
| 159 | <a name="l00205"></a>00205 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1compositepdf.html#23faf2debc4dde10836393b8c665914a" title="Elements of composition.">mpdfs</a> ( i )->_rvc().count() ) { |
---|
| 160 | <a name="l00206"></a>00206 <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> |
---|
[234] | 161 | <a name="l00207"></a>00207 } |
---|
[255] | 162 | <a name="l00208"></a>00208 smpi = <a class="code" href="classbdm_1_1mprod.html#eca722ed1b219727c6c0f8cbc6bf1e51" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i )->sample(); |
---|
[234] | 163 | <a name="l00209"></a>00209 <span class="comment">// copy contribution of this pdf into smp</span> |
---|
[255] | 164 | <a name="l00210"></a>00210 <a class="code" href="classbdm_1_1mprod.html#acf679b3b1d48629c5a042d9ac0d973f" title="Data link for each mpdfs.">dls</a> ( i )->fill_val ( smp, smpi ); |
---|
[234] | 165 | <a name="l00211"></a>00211 <span class="comment">// add ith likelihood contribution</span> |
---|
[255] | 166 | <a name="l00212"></a>00212 ll+=<a class="code" href="classbdm_1_1mprod.html#eca722ed1b219727c6c0f8cbc6bf1e51" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i )->evallog ( smpi ); |
---|
[234] | 167 | <a name="l00213"></a>00213 } |
---|
| 168 | <a name="l00214"></a>00214 <span class="keywordflow">return</span> smp; |
---|
| 169 | <a name="l00215"></a>00215 } |
---|
[255] | 170 | <a name="l00216"></a>00216 mat <a class="code" href="classbdm_1_1mprod.html#1a37c2aaba8bde7fce5351c39b6e1168" title="Returns a sample from the density conditioned on cond, .">samplecond</a> ( <span class="keyword">const</span> vec &cond, vec &ll, <span class="keywordtype">int</span> N ) { |
---|
| 171 | <a name="l00217"></a>00217 mat Smp ( <a class="code" href="classbdm_1_1mpdf.html#9bcfb45435d30983f436d41c298cbb51" title="modeled random variable">rv</a>.<a class="code" href="classbdm_1_1RV.html#2174751a00ce19f941edd2c1a861be67" title="Return number of scalars in the RV.">count</a>(),N ); |
---|
| 172 | <a name="l00218"></a>00218 <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#1a37c2aaba8bde7fce5351c39b6e1168" title="Returns a sample from the density conditioned on cond, .">samplecond</a> ( cond,ll ( i ) ) );} |
---|
[234] | 173 | <a name="l00219"></a>00219 <span class="keywordflow">return</span> Smp; |
---|
| 174 | <a name="l00220"></a>00220 } |
---|
| 175 | <a name="l00221"></a>00221 |
---|
[255] | 176 | <a name="l00222"></a>00222 ~<a class="code" href="classbdm_1_1mprod.html#680c3e2d95b116c7cfb227c7f2984525" title="Constructor from list of mFacs,.">mprod</a>() {}; |
---|
[234] | 177 | <a name="l00223"></a>00223 }; |
---|
| 178 | <a name="l00224"></a>00224 |
---|
[255] | 179 | <a name="l00226"></a><a class="code" href="classbdm_1_1eprod.html">00226</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> { |
---|
[234] | 180 | <a name="l00227"></a>00227 <span class="keyword">protected</span>: |
---|
[255] | 181 | <a name="l00229"></a><a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391">00229</a> Array<const epdf*> <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>; |
---|
| 182 | <a name="l00231"></a><a class="code" href="classbdm_1_1eprod.html#a42b1820428ac06eecb6d938cb6896ff">00231</a> Array<datalink_e2e*> <a class="code" href="classbdm_1_1eprod.html#a42b1820428ac06eecb6d938cb6896ff" title="Array of indeces.">dls</a>; |
---|
[234] | 183 | <a name="l00232"></a>00232 <span class="keyword">public</span>: |
---|
[255] | 184 | <a name="l00233"></a>00233 <a class="code" href="classbdm_1_1eprod.html" title="Product of independent epdfs. For dependent pdfs, use mprod.">eprod</a> ( <span class="keyword">const</span> Array<const epdf*> epdfs0 ) : <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_1RV.html" title="Class representing variables, most often random variables.">RV</a>() ),<a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( epdfs0 ),<a class="code" href="classbdm_1_1eprod.html#a42b1820428ac06eecb6d938cb6896ff" title="Array of indeces.">dls</a> ( <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a>.length() ) { |
---|
[234] | 185 | <a name="l00234"></a>00234 <span class="keywordtype">bool</span> independent=<span class="keyword">true</span>; |
---|
[255] | 186 | <a name="l00235"></a>00235 <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++ ) { |
---|
| 187 | <a name="l00236"></a>00236 independent=<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Identified 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="access function, possibly dangerous!">_rv</a>() ); |
---|
[234] | 188 | <a name="l00237"></a>00237 it_assert_debug ( independent==<span class="keyword">true</span>, <span class="stringliteral">"eprod:: given components are not independent ."</span> ); |
---|
| 189 | <a name="l00238"></a>00238 } |
---|
[255] | 190 | <a name="l00239"></a>00239 <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++ ) { |
---|
[261] | 191 | <a name="l00240"></a>00240 <a class="code" href="classbdm_1_1eprod.html#a42b1820428ac06eecb6d938cb6896ff" title="Array of indeces.">dls</a> ( i ) = <span class="keyword">new</span> <a class="code" href="classbdm_1_1datalink__e2e.html" title="DataLink is a connection between two data vectors Up and Down.">datalink_e2e</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="access function, possibly dangerous!">_rv</a>() , <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Identified of the random variable.">rv</a> ); |
---|
[234] | 192 | <a name="l00241"></a>00241 } |
---|
| 193 | <a name="l00242"></a>00242 } |
---|
| 194 | <a name="l00243"></a>00243 |
---|
[255] | 195 | <a name="l00244"></a><a class="code" href="classbdm_1_1eprod.html#1d494351e7e385ad3382387c96915d24">00244</a> vec <a class="code" href="classbdm_1_1eprod.html#1d494351e7e385ad3382387c96915d24" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
---|
| 196 | <a name="l00245"></a>00245 vec tmp ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Identified of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#2174751a00ce19f941edd2c1a861be67" title="Return number of scalars in the RV.">count</a>() ); |
---|
| 197 | <a name="l00246"></a>00246 <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++ ) { |
---|
| 198 | <a name="l00247"></a>00247 vec pom = <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->mean(); |
---|
| 199 | <a name="l00248"></a>00248 <a class="code" href="classbdm_1_1eprod.html#a42b1820428ac06eecb6d938cb6896ff" title="Array of indeces.">dls</a> ( i )->fill_val ( tmp, pom ); |
---|
[234] | 200 | <a name="l00249"></a>00249 } |
---|
| 201 | <a name="l00250"></a>00250 <span class="keywordflow">return</span> tmp; |
---|
| 202 | <a name="l00251"></a>00251 } |
---|
[255] | 203 | <a name="l00252"></a><a class="code" href="classbdm_1_1eprod.html#cc53a151f5ac5dfba68d425acc3a5615">00252</a> vec <a class="code" href="classbdm_1_1eprod.html#cc53a151f5ac5dfba68d425acc3a5615" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
---|
| 204 | <a name="l00253"></a>00253 vec tmp ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Identified of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#2174751a00ce19f941edd2c1a861be67" title="Return number of scalars in the RV.">count</a>() ); <span class="comment">//second moment</span> |
---|
| 205 | <a name="l00254"></a>00254 <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++ ) { |
---|
| 206 | <a name="l00255"></a>00255 vec pom = <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->mean(); |
---|
| 207 | <a name="l00256"></a>00256 <a class="code" href="classbdm_1_1eprod.html#a42b1820428ac06eecb6d938cb6896ff" title="Array of indeces.">dls</a> ( i )->fill_val ( tmp, pow(pom,2) ); |
---|
[219] | 208 | <a name="l00257"></a>00257 } |
---|
[255] | 209 | <a name="l00258"></a>00258 <span class="keywordflow">return</span> tmp-pow(<a class="code" href="classbdm_1_1eprod.html#1d494351e7e385ad3382387c96915d24" title="return expected value">mean</a>(),2); |
---|
[234] | 210 | <a name="l00259"></a>00259 } |
---|
[255] | 211 | <a name="l00260"></a><a class="code" href="classbdm_1_1eprod.html#af48debea25d3473bcb71b6a77fac741">00260</a> vec <a class="code" href="classbdm_1_1eprod.html#af48debea25d3473bcb71b6a77fac741" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
---|
| 212 | <a name="l00261"></a>00261 vec tmp ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Identified of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#2174751a00ce19f941edd2c1a861be67" title="Return number of scalars in the RV.">count</a>() ); |
---|
| 213 | <a name="l00262"></a>00262 <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++ ) { |
---|
| 214 | <a name="l00263"></a>00263 vec pom = <a class="code" href="classbdm_1_1eprod.html#fa0b0981730f0a8339b9ff3e29d78391" title="Components (epdfs).">epdfs</a> ( i )->sample(); |
---|
| 215 | <a name="l00264"></a>00264 <a class="code" href="classbdm_1_1eprod.html#a42b1820428ac06eecb6d938cb6896ff" title="Array of indeces.">dls</a> ( i )->fill_val ( tmp, pom ); |
---|
[234] | 216 | <a name="l00265"></a>00265 } |
---|
| 217 | <a name="l00266"></a>00266 <span class="keywordflow">return</span> tmp; |
---|
| 218 | <a name="l00267"></a>00267 } |
---|
[255] | 219 | <a name="l00268"></a><a class="code" href="classbdm_1_1eprod.html#a5a91e67d2f74ff2b0b8eecde2fa42e2">00268</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>{ |
---|
[234] | 220 | <a name="l00269"></a>00269 <span class="keywordtype">double</span> tmp=0; |
---|
[255] | 221 | <a name="l00270"></a>00270 <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++ ) { |
---|
| 222 | <a name="l00271"></a>00271 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#a42b1820428ac06eecb6d938cb6896ff" title="Array of indeces.">dls</a> ( i )->get_val ( val ) ); |
---|
[234] | 223 | <a name="l00272"></a>00272 } |
---|
| 224 | <a name="l00273"></a>00273 it_assert_debug(std::isfinite(tmp),<span class="stringliteral">"Infinite"</span>); |
---|
| 225 | <a name="l00274"></a>00274 <span class="keywordflow">return</span> tmp; |
---|
| 226 | <a name="l00275"></a>00275 } |
---|
[255] | 227 | <a name="l00277"></a><a class="code" href="classbdm_1_1eprod.html#5194b47dd05a5886e0745250b6704953">00277</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 );} |
---|
[234] | 228 | <a name="l00278"></a>00278 |
---|
[255] | 229 | <a name="l00280"></a><a class="code" href="classbdm_1_1eprod.html#708b37971aab3667f20e325c358632cf">00280</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#a42b1820428ac06eecb6d938cb6896ff" title="Array of indeces.">dls</a> ( i );}} |
---|
[234] | 230 | <a name="l00281"></a>00281 }; |
---|
| 231 | <a name="l00282"></a>00282 |
---|
| 232 | <a name="l00283"></a>00283 |
---|
[255] | 233 | <a name="l00287"></a><a class="code" href="classbdm_1_1mmix.html">00287</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> { |
---|
[234] | 234 | <a name="l00288"></a>00288 <span class="keyword">protected</span>: |
---|
[255] | 235 | <a name="l00290"></a><a class="code" href="classbdm_1_1mmix.html#52e0bcc70d5b26babeba08097579da9c">00290</a> Array<mpdf*> <a class="code" href="classbdm_1_1mmix.html#52e0bcc70d5b26babeba08097579da9c" title="Component (epdfs).">Coms</a>; |
---|
| 236 | <a name="l00292"></a><a class="code" href="classbdm_1_1mmix.html#0c4dd6ca6556ddd8ae3c5f3257c04b60">00292</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>; |
---|
[234] | 237 | <a name="l00293"></a>00293 <span class="keyword">public</span>: |
---|
[255] | 238 | <a name="l00295"></a><a class="code" href="classbdm_1_1mmix.html#580a05ae61b179de3fccfcb60f11efd9">00295</a> <a class="code" href="classbdm_1_1mmix.html#580a05ae61b179de3fccfcb60f11efd9" title="Default constructor.">mmix</a> ( <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classbdm_1_1mpdf.html#9bcfb45435d30983f436d41c298cbb51" title="modeled random variable">rv</a>, <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classbdm_1_1mpdf.html#5a5f08950daa08b85b01ddf4e1c36288" title="random variable in condition">rvc</a> ) : <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( rv, rvc ), <a class="code" href="classbdm_1_1mmix.html#0c4dd6ca6556ddd8ae3c5f3257c04b60" title="Internal epdf.">Epdf</a> ( rv ) {<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>;}; |
---|
| 239 | <a name="l00297"></a><a class="code" href="classbdm_1_1mmix.html#ad8d9df36cb0ca093a29af0eca12da32">00297</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> ) { |
---|
[234] | 240 | <a name="l00298"></a>00298 Array<epdf*> Eps ( Coms.length() ); |
---|
| 241 | <a name="l00299"></a>00299 |
---|
| 242 | <a name="l00300"></a>00300 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < Coms.length();i++ ) { |
---|
[255] | 243 | <a name="l00301"></a>00301 Eps ( i ) = & ( <a class="code" href="classbdm_1_1mmix.html#52e0bcc70d5b26babeba08097579da9c" title="Component (epdfs).">Coms</a> ( i )->_epdf() ); |
---|
[234] | 244 | <a name="l00302"></a>00302 } |
---|
[255] | 245 | <a name="l00303"></a>00303 <a class="code" href="classbdm_1_1mmix.html#0c4dd6ca6556ddd8ae3c5f3257c04b60" title="Internal epdf.">Epdf</a>.<a class="code" href="classbdm_1_1emix.html#d8c1aefba8302759836b5f26999ce840">set_parameters</a> ( w, Eps ); |
---|
[234] | 246 | <a name="l00304"></a>00304 }; |
---|
| 247 | <a name="l00305"></a>00305 |
---|
[255] | 248 | <a name="l00306"></a><a class="code" href="classbdm_1_1mmix.html#0a5241ecc9911e816b00b92d5c7c8df0">00306</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 ) { |
---|
| 249 | <a name="l00307"></a>00307 <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 );} |
---|
[234] | 250 | <a name="l00308"></a>00308 }; |
---|
| 251 | <a name="l00309"></a>00309 }; |
---|
| 252 | <a name="l00310"></a>00310 |
---|
[255] | 253 | <a name="l00311"></a>00311 } |
---|
| 254 | <a name="l00312"></a>00312 <span class="preprocessor">#endif //MX_H</span> |
---|
[106] | 255 | </pre></div></div> |
---|
[261] | 256 | <hr size="1"><address style="text-align: right;"><small>Generated on Fri Feb 6 15:29:44 2009 for mixpp by |
---|
[106] | 257 | <a href="http://www.doxygen.org/index.html"> |
---|
[139] | 258 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address> |
---|
[106] | 259 | </body> |
---|
| 260 | </html> |
---|