Show
Ignore:
Timestamp:
09/24/08 13:08:07 (16 years ago)
Author:
smidl
Message:

New documentation

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • doc/html/emix_8h-source.html

    r162 r171  
    3333<a name="l00042"></a>00042         <span class="keywordtype">void</span> <a class="code" href="classemix.html#6ce82b24d7fe540ddbf44b472a005555" title="Set weights w and components R.">set_parameters</a> ( <span class="keyword">const</span> vec &amp;<a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>, <span class="keyword">const</span> Array&lt;epdf*&gt; &amp;<a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ); 
    3434<a name="l00043"></a>00043  
    35 <a name="l00044"></a>00044         vec <a class="code" href="classemix.html#0650601f24e633e0ab09aa1e46c14483" title="Returns the required moment of the epdf.">sample</a>() <span class="keyword">const</span>; 
     35<a name="l00044"></a>00044         vec <a class="code" href="classemix.html#0650601f24e633e0ab09aa1e46c14483" title="Returns a sample,  from density .">sample</a>() <span class="keyword">const</span>; 
    3636<a name="l00045"></a><a class="code" href="classemix.html#b662a51d042b062020460e64bff4e9e8">00045</a>         vec <a class="code" href="classemix.html#b662a51d042b062020460e64bff4e9e8" title="return expected value">mean</a>()<span class="keyword"> const </span>{ 
    3737<a name="l00046"></a>00046                 <span class="keywordtype">int</span> i; vec mu = zeros ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); 
     
    6161<a name="l00081"></a><a class="code" href="classmprod.html#1725c7b497a27ab3c4889b846666b516">00081</a>         Array&lt;ivec&gt; <a class="code" href="classmprod.html#1725c7b497a27ab3c4889b846666b516" title="Indeces of rvc in common rv.">rvcinrv</a>; 
    6262<a name="l00083"></a><a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6">00083</a>         Array&lt;ivec&gt; <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a>; 
    63 <a name="l00085"></a><a class="code" href="classmprod.html#5f6431dc5f5ce8a817e0b2049f2a9eda">00085</a>         <span class="keywordtype">bool</span> <a class="code" href="classmprod.html#5f6431dc5f5ce8a817e0b2049f2a9eda" title="Indicate independence of its factors.">independent</a>; 
     63<a name="l00084"></a>00084 <span class="comment">//      //! Indicate independence of its factors</span> 
     64<a name="l00085"></a>00085 <span class="comment">//      bool independent;</span> 
    6465<a name="l00086"></a>00086 <span class="comment">//      //! Indicate internal creation of mpdfs which must be destroyed</span> 
    6566<a name="l00087"></a>00087 <span class="comment">//      bool intermpdfs;</span> 
    6667<a name="l00088"></a>00088 <span class="keyword">public</span>: 
    67 <a name="l00090"></a><a class="code" href="classmprod.html#419b303581a91ad85200bdcb4b3186f4">00090</a>         <a class="code" href="classmprod.html#419b303581a91ad85200bdcb4b3186f4" title="Constructor from list of eFacs or list of mFacs.">mprod</a> ( Array&lt;mpdf*&gt; mFacs ) : <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a>(), <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a>() ), n ( mFacs.length() ), epdfs ( n ), mpdfs ( mFacs ), <a class="code" href="classmprod.html#c8f78fbcdb4e38ecd3197d2958082497" title="Indeces of rvs in common rv.">rvinds</a> ( n ), <a class="code" href="classmprod.html#1725c7b497a27ab3c4889b846666b516" title="Indeces of rvc in common rv.">rvcinrv</a> ( n ), <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( n ) { 
    68 <a name="l00091"></a>00091                 <span class="keywordtype">int</span> i; 
    69 <a name="l00092"></a>00092                 <span class="comment">// Create rv</span> 
    70 <a name="l00093"></a>00093                 <span class="keywordflow">for</span> ( i = 0;i &lt; n;i++ ) { 
    71 <a name="l00094"></a>00094                         <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>.<a class="code" href="classRV.html#935790526b630dec4ffefa9ec0c2b6fb" title="Add (concat) another variable to the current one,.">add</a> ( mpdfs ( i )-&gt;<a class="code" href="classmpdf.html#1e71ad4c66d5884c82d4a3b06b42fe32" title="access function">_rv</a>() ); <span class="comment">//add rv to common rvs.</span> 
    72 <a name="l00095"></a>00095                         epdfs ( i ) = &amp; ( mpdfs ( i )-&gt;_epdf() ); <span class="comment">// add pointer to epdf</span> 
    73 <a name="l00096"></a>00096                 }; 
    74 <a name="l00097"></a>00097                 <span class="comment">// Create rvc</span> 
    75 <a name="l00098"></a>00098                 <span class="keywordflow">for</span> ( i = 0;i &lt; n;i++ ) { 
    76 <a name="l00099"></a>00099                         <a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a>.<a class="code" href="classRV.html#935790526b630dec4ffefa9ec0c2b6fb" title="Add (concat) another variable to the current one,.">add</a> ( mpdfs ( i )-&gt;<a class="code" href="classmpdf.html#1e71ad4c66d5884c82d4a3b06b42fe32" title="access function">_rv</a>().subt ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a> ) ); <span class="comment">//add rv to common rvs.</span> 
    77 <a name="l00100"></a>00100                 }; 
    78 <a name="l00101"></a>00101  
    79 <a name="l00102"></a>00102                 <a class="code" href="classmprod.html#5f6431dc5f5ce8a817e0b2049f2a9eda" title="Indicate independence of its factors.">independent</a> = <span class="keyword">true</span>; 
    80 <a name="l00103"></a>00103                 <span class="comment">//test rvc of mpdfs and fill rvinds</span> 
    81 <a name="l00104"></a>00104                 <span class="keywordflow">for</span> ( i = 0;i &lt; n;i++ ) { 
    82 <a name="l00105"></a>00105                         <span class="comment">// find ith rv in common rv</span> 
    83 <a name="l00106"></a>00106                         <a class="code" href="classmprod.html#c8f78fbcdb4e38ecd3197d2958082497" title="Indeces of rvs in common rv.">rvinds</a> ( i ) = mpdfs ( i )-&gt;_rv().dataind ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a> ); 
    84 <a name="l00107"></a>00107                         <span class="comment">// find ith rvc in common rv</span> 
    85 <a name="l00108"></a>00108                         <a class="code" href="classmprod.html#1725c7b497a27ab3c4889b846666b516" title="Indeces of rvc in common rv.">rvcinrv</a> ( i ) = mpdfs ( i )-&gt;_rvc().dataind ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a> ); 
    86 <a name="l00109"></a>00109                         <span class="comment">// find ith rvc in common rv</span> 
    87 <a name="l00110"></a>00110                         <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ) = mpdfs ( i )-&gt;_rvc().dataind ( <a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ); 
    88 <a name="l00111"></a>00111                         <span class="comment">//</span> 
    89 <a name="l00112"></a>00112                         <span class="keywordflow">if</span> ( <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ).length() &gt;0 ) {<a class="code" href="classmprod.html#5f6431dc5f5ce8a817e0b2049f2a9eda" title="Indicate independence of its factors.">independent</a> = <span class="keyword">false</span>;} 
    90 <a name="l00113"></a>00113                         <span class="keywordflow">if</span> ( <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ).length() &gt;0 ) {<a class="code" href="classmprod.html#5f6431dc5f5ce8a817e0b2049f2a9eda" title="Indicate independence of its factors.">independent</a> = <span class="keyword">false</span>;} 
    91 <a name="l00114"></a>00114                 } 
    92 <a name="l00115"></a>00115         }; 
    93 <a name="l00116"></a>00116  
    94 <a name="l00117"></a>00117         <span class="keywordtype">double</span> evalpdflog ( <span class="keyword">const</span> vec &amp;val )<span class="keyword"> const </span>{ 
    95 <a name="l00118"></a>00118                 <span class="keywordtype">int</span> i; 
    96 <a name="l00119"></a>00119                 <span class="keywordtype">double</span> res = 0.0; 
    97 <a name="l00120"></a>00120                 <span class="keywordflow">for</span> ( i = n - 1;i &gt; 0;i++ ) { 
    98 <a name="l00121"></a>00121                         <span class="keywordflow">if</span> ( <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ).length() &gt; 0 ) 
    99 <a name="l00122"></a>00122                                 {mpdfs ( i )-&gt;condition ( val ( <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ) ) );} 
    100 <a name="l00123"></a>00123                         <span class="comment">// add logarithms</span> 
    101 <a name="l00124"></a>00124                         res += epdfs ( i )-&gt;evalpdflog ( val ( <a class="code" href="classmprod.html#c8f78fbcdb4e38ecd3197d2958082497" title="Indeces of rvs in common rv.">rvinds</a> ( i ) ) ); 
     68<a name="l00092"></a>00092         <a class="code" href="classmprod.html#37f028561c45ce5fd3a1351a911e31dc" title="Constructor from list of mFacs, Additional parameter overlap is left for future use...">mprod</a> ( Array&lt;mpdf*&gt; mFacs, <span class="keywordtype">bool</span> overlap=<span class="keyword">false</span> ); 
     69<a name="l00093"></a>00093  
     70<a name="l00094"></a>00094         <span class="keywordtype">double</span> evalpdflog ( <span class="keyword">const</span> vec &amp;val )<span class="keyword"> const </span>{ 
     71<a name="l00095"></a>00095                 <span class="keywordtype">int</span> i; 
     72<a name="l00096"></a>00096                 <span class="keywordtype">double</span> res = 0.0; 
     73<a name="l00097"></a>00097                 <span class="keywordflow">for</span> ( i = n - 1;i &gt; 0;i++ ) { 
     74<a name="l00098"></a>00098                         <span class="keywordflow">if</span> ( <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ).length() &gt; 0 ) 
     75<a name="l00099"></a>00099                                 {mpdfs ( i )-&gt;condition ( val ( <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ) ) );} 
     76<a name="l00100"></a>00100                         <span class="comment">// add logarithms</span> 
     77<a name="l00101"></a>00101                         res += epdfs ( i )-&gt;evalpdflog ( val ( <a class="code" href="classmprod.html#c8f78fbcdb4e38ecd3197d2958082497" title="Indeces of rvs in common rv.">rvinds</a> ( i ) ) ); 
     78<a name="l00102"></a>00102                 } 
     79<a name="l00103"></a>00103                 <span class="keywordflow">return</span> res; 
     80<a name="l00104"></a>00104         } 
     81<a name="l00105"></a><a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68">00105</a>         vec <a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68" title="Returns the required moment of the epdf.">samplecond</a> ( <span class="keyword">const</span> vec &amp;cond, <span class="keywordtype">double</span> &amp;ll ) { 
     82<a name="l00106"></a>00106                 vec smp=zeros ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); 
     83<a name="l00107"></a>00107                 vec condi; 
     84<a name="l00108"></a>00108                 vec smpi; 
     85<a name="l00109"></a>00109                 ll = 0; 
     86<a name="l00110"></a>00110                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = ( n - 1 );i &gt;= 0;i-- ) { 
     87<a name="l00111"></a>00111                         <span class="keywordflow">if</span> ( <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ).length() &gt; 0 ) { 
     88<a name="l00112"></a>00112                                 condi = zeros ( <a class="code" href="classmprod.html#1725c7b497a27ab3c4889b846666b516" title="Indeces of rvc in common rv.">rvcinrv</a>.length() + <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a>.length() ); 
     89<a name="l00113"></a>00113                                 <span class="comment">// copy data in condition</span> 
     90<a name="l00114"></a>00114                                 set_subvector ( condi,<a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ), cond ); 
     91<a name="l00115"></a>00115                                 <span class="comment">// copy data in already generated sample</span> 
     92<a name="l00116"></a>00116                                 set_subvector ( condi,<a class="code" href="classmprod.html#1725c7b497a27ab3c4889b846666b516" title="Indeces of rvc in common rv.">rvcinrv</a> ( i ), smp ); 
     93<a name="l00117"></a>00117  
     94<a name="l00118"></a>00118                                 mpdfs ( i )-&gt;condition ( condi ); 
     95<a name="l00119"></a>00119                         } 
     96<a name="l00120"></a>00120                         smpi = epdfs ( i )-&gt;sample(); 
     97<a name="l00121"></a>00121                         <span class="comment">// copy contribution of this pdf into smp</span> 
     98<a name="l00122"></a>00122                         set_subvector ( smp,<a class="code" href="classmprod.html#c8f78fbcdb4e38ecd3197d2958082497" title="Indeces of rvs in common rv.">rvinds</a> ( i ), smpi ); 
     99<a name="l00123"></a>00123                         <span class="comment">// add ith likelihood contribution</span> 
     100<a name="l00124"></a>00124                         ll+=epdfs ( i )-&gt;evalpdflog ( smpi ); 
    102101<a name="l00125"></a>00125                 } 
    103 <a name="l00126"></a>00126                 <span class="keywordflow">return</span> res; 
     102<a name="l00126"></a>00126                 <span class="keywordflow">return</span> smp; 
    104103<a name="l00127"></a>00127         } 
    105 <a name="l00128"></a>00128         vec samplecond ( <span class="keyword">const</span> vec &amp;cond, vec &amp;ll )<span class="keyword"> const </span>{ 
    106 <a name="l00129"></a>00129                 vec smp=zeros ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); 
    107 <a name="l00130"></a>00130                 vec condi; 
    108 <a name="l00131"></a>00131                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = ( n - 1 );i &gt;= 0;i-- ) { 
    109 <a name="l00132"></a>00132                         <span class="keywordflow">if</span> ( <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ).length() &gt; 0 ) { 
    110 <a name="l00133"></a>00133                                 condi = zeros ( <a class="code" href="classmprod.html#1725c7b497a27ab3c4889b846666b516" title="Indeces of rvc in common rv.">rvcinrv</a>.length() + <a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a>.length() ); 
    111 <a name="l00134"></a>00134                                 <span class="comment">// copy data in condition</span> 
    112 <a name="l00135"></a>00135                                 set_subvector ( condi,<a class="code" href="classmprod.html#cc85192d8abc01832937ed8b62e363a6" title="Indeces of rvc in common rvc.">rvcinds</a> ( i ), cond ); 
    113 <a name="l00136"></a>00136                                 <span class="comment">// copy data in already generated sample</span> 
    114 <a name="l00137"></a>00137                                 set_subvector ( condi,<a class="code" href="classmprod.html#1725c7b497a27ab3c4889b846666b516" title="Indeces of rvc in common rv.">rvcinrv</a> ( i ), smp ); 
    115 <a name="l00138"></a>00138  
    116 <a name="l00139"></a>00139                                 mpdfs ( i )-&gt;condition ( condi ); 
    117 <a name="l00140"></a>00140                         } 
    118 <a name="l00141"></a>00141                         <span class="comment">// copy contribution of this pdf into smp</span> 
    119 <a name="l00142"></a>00142                         set_subvector ( smp,<a class="code" href="classmprod.html#c8f78fbcdb4e38ecd3197d2958082497" title="Indeces of rvs in common rv.">rvinds</a> ( i ), epdfs ( i )-&gt;sample() ); 
    120 <a name="l00143"></a>00143                 } 
    121 <a name="l00144"></a>00144                 <span class="keywordflow">return</span> smp; 
    122 <a name="l00145"></a>00145         } 
    123 <a name="l00146"></a>00146 <span class="comment">//      vec mean() const {</span> 
    124 <a name="l00147"></a>00147 <span class="comment">//              vec tmp ( rv.count() );</span> 
    125 <a name="l00148"></a>00148 <span class="comment">//              if ( independent ) {</span> 
    126 <a name="l00149"></a>00149 <span class="comment">//                      for ( int i=0;i&lt;n;i++ ) {</span> 
    127 <a name="l00150"></a>00150 <span class="comment">//                              vec pom = epdfs ( i )-&gt;mean();</span> 
    128 <a name="l00151"></a>00151 <span class="comment">//                              set_subvector ( tmp,rvinds ( i ), pom );</span> 
    129 <a name="l00152"></a>00152 <span class="comment">//                      }</span> 
    130 <a name="l00153"></a>00153 <span class="comment">//              }</span> 
    131 <a name="l00154"></a>00154 <span class="comment">//              else {</span> 
    132 <a name="l00155"></a>00155 <span class="comment">//                      int N=50*rv.count();</span> 
    133 <a name="l00156"></a>00156 <span class="comment">//                      it_warning ( "eprod.mean() computed by sampling" );</span> 
    134 <a name="l00157"></a>00157 <span class="comment">//                      tmp = zeros ( rv.count() );</span> 
    135 <a name="l00158"></a>00158 <span class="comment">//                      for ( int i=0;i&lt;N;i++ ) { tmp += sample();}</span> 
    136 <a name="l00159"></a>00159 <span class="comment">//                      tmp /=N;</span> 
    137 <a name="l00160"></a>00160 <span class="comment">//              }</span> 
    138 <a name="l00161"></a>00161 <span class="comment">//              return tmp;</span> 
    139 <a name="l00162"></a>00162 <span class="comment">//      }</span> 
    140 <a name="l00163"></a>00163  
    141 <a name="l00164"></a>00164         ~<a class="code" href="classmprod.html" title="Chain rule decomposition of epdf.">mprod</a>() {}; 
    142 <a name="l00165"></a>00165 }; 
    143 <a name="l00166"></a>00166  
    144 <a name="l00170"></a><a class="code" href="classmmix.html">00170</a> <span class="keyword">class </span><a class="code" href="classmmix.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="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { 
    145 <a name="l00171"></a>00171 <span class="keyword">protected</span>: 
    146 <a name="l00173"></a><a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f">00173</a>         Array&lt;mpdf*&gt; <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a>; 
    147 <a name="l00175"></a><a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914">00175</a>         <a class="code" href="classemix.html" title="Mixture of epdfs.">emix</a> <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>; 
    148 <a name="l00176"></a>00176 <span class="keyword">public</span>: 
    149 <a name="l00178"></a><a class="code" href="classmmix.html#6769a962f1f4d0ecc5b903b5f7d26ad3">00178</a>         <a class="code" href="classmmix.html#6769a962f1f4d0ecc5b903b5f7d26ad3" title="Default constructor.">mmix</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;<a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>, <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ) : <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( rv, rvc ), <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a> ( rv ) {<a class="code" href="classmpdf.html#7aa894208a32f3487827df6d5054424c" title="pointer to internal epdf">ep</a> = &amp;<a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>;}; 
    150 <a name="l00180"></a><a class="code" href="classmmix.html#e7681490a5c5b2d0a43f4e5842e10a9d">00180</a>         <span class="keywordtype">void</span> <a class="code" href="classmmix.html#e7681490a5c5b2d0a43f4e5842e10a9d" title="Set weights w and components R.">set_parameters</a> ( <span class="keyword">const</span> vec &amp;w, <span class="keyword">const</span> Array&lt;mpdf*&gt; &amp;<a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ) { 
    151 <a name="l00181"></a>00181                 Array&lt;epdf*&gt; Eps ( Coms.length() ); 
    152 <a name="l00182"></a>00182  
    153 <a name="l00183"></a>00183                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i &lt; Coms.length();i++ ) { 
    154 <a name="l00184"></a>00184                         Eps ( i ) = &amp; ( <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ( i )-&gt;_epdf() ); 
    155 <a name="l00185"></a>00185                 } 
    156 <a name="l00186"></a>00186                 <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>.<a class="code" href="classemix.html#6ce82b24d7fe540ddbf44b472a005555" title="Set weights w and components R.">set_parameters</a> ( w, Eps ); 
    157 <a name="l00187"></a>00187         }; 
    158 <a name="l00188"></a>00188  
    159 <a name="l00189"></a><a class="code" href="classmmix.html#1a66629ec5c2b6f4740606cf737f0193">00189</a>         <span class="keywordtype">void</span> <a class="code" href="classmmix.html#1a66629ec5c2b6f4740606cf737f0193" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &amp;cond ) { 
    160 <a name="l00190"></a>00190                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i &lt; <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a>.length();i++ ) {<a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ( i )-&gt;condition ( cond );} 
    161 <a name="l00191"></a>00191         }; 
    162 <a name="l00192"></a>00192 }; 
    163 <a name="l00193"></a>00193 <span class="preprocessor">#endif //MX_H</span> 
     104<a name="l00128"></a><a class="code" href="classmprod.html#e171c40e210539c2af01d6237785620b">00128</a>         mat <a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68" title="Returns the required moment of the epdf.">samplecond</a> ( <span class="keyword">const</span> vec &amp;cond, vec &amp;ll, <span class="keywordtype">int</span> N ) { 
     105<a name="l00129"></a>00129                 mat Smp ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>(),N ); 
     106<a name="l00130"></a>00130                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i&lt;N;i++ ) {Smp.set_col ( i,<a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68" title="Returns the required moment of the epdf.">samplecond</a> ( cond,ll ( i ) ) );} 
     107<a name="l00131"></a>00131                 <span class="keywordflow">return</span> Smp; 
     108<a name="l00132"></a>00132         } 
     109<a name="l00133"></a>00133  
     110<a name="l00134"></a>00134         ~<a class="code" href="classmprod.html" title="Chain rule decomposition of epdf.">mprod</a>() {}; 
     111<a name="l00135"></a>00135 }; 
     112<a name="l00136"></a>00136  
     113<a name="l00138"></a><a class="code" href="classeprod.html">00138</a> <span class="keyword">class </span><a class="code" href="classeprod.html" title="Product of independent epdfs. For dependent pdfs, use mprod.">eprod</a>: <span class="keyword">public</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { 
     114<a name="l00139"></a>00139 <span class="keyword">protected</span>: 
     115<a name="l00141"></a><a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357">00141</a>         Array&lt;const epdf*&gt; <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>; 
     116<a name="l00143"></a><a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3">00143</a>         Array&lt;ivec&gt; <a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a>; 
     117<a name="l00144"></a>00144 <span class="keyword">public</span>: 
     118<a name="l00145"></a>00145         <a class="code" href="classeprod.html" title="Product of independent epdfs. For dependent pdfs, use mprod.">eprod</a> ( <span class="keyword">const</span> Array&lt;const epdf*&gt; epdfs0 ) : <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a>() ),<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( epdfs0 ),<a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a> ( <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length() ) { 
     119<a name="l00146"></a>00146                 <span class="keywordtype">bool</span> independent=<span class="keyword">true</span>; 
     120<a name="l00147"></a>00147                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i&lt;<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { 
     121<a name="l00148"></a>00148                         independent=<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#935790526b630dec4ffefa9ec0c2b6fb" title="Add (concat) another variable to the current one,.">add</a> ( <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )-&gt;<a class="code" href="classepdf.html#ca0d32aabb4cbba347e0c37fe8607562" title="access function, possibly dangerous!">_rv</a>() ); 
     122<a name="l00149"></a>00149                         it_assert_debug ( independent==<span class="keyword">true</span>, <span class="stringliteral">"eprod:: given components are not independent ."</span> ); 
     123<a name="l00150"></a>00150                         <a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a> ( i ) = ( <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )-&gt;_rv() ).dataind ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ); 
     124<a name="l00151"></a>00151                 } 
     125<a name="l00152"></a>00152         } 
     126<a name="l00153"></a>00153  
     127<a name="l00154"></a><a class="code" href="classeprod.html#5752dd999e1f4638f9558b0cc35b64f7">00154</a>         vec <a class="code" href="classeprod.html#5752dd999e1f4638f9558b0cc35b64f7" title="return expected value">mean</a>()<span class="keyword"> const </span>{ 
     128<a name="l00155"></a>00155                 vec tmp ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); 
     129<a name="l00156"></a>00156                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i&lt;<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { 
     130<a name="l00157"></a>00157                         vec pom = <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )-&gt;mean(); 
     131<a name="l00158"></a>00158                         set_subvector ( tmp,<a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a> ( i ), pom ); 
     132<a name="l00159"></a>00159                 } 
     133<a name="l00160"></a>00160                 <span class="keywordflow">return</span> tmp; 
     134<a name="l00161"></a>00161         } 
     135<a name="l00162"></a><a class="code" href="classeprod.html#94a5b7c44056cf7f4e688d53ba6295b4">00162</a>         vec <a class="code" href="classeprod.html#94a5b7c44056cf7f4e688d53ba6295b4" title="Returns a sample,  from density .">sample</a>()<span class="keyword"> const </span>{ 
     136<a name="l00163"></a>00163                 vec tmp ( <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a>.<a class="code" href="classRV.html#f5c7b8bd589eef09ccdf3329a0addea0" title="Return number of scalars in the RV.">count</a>() ); 
     137<a name="l00164"></a>00164                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i&lt;<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { 
     138<a name="l00165"></a>00165                         vec pom = <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )-&gt;sample(); 
     139<a name="l00166"></a>00166                         set_subvector ( tmp,<a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a> ( i ), pom ); 
     140<a name="l00167"></a>00167                 } 
     141<a name="l00168"></a>00168                 <span class="keywordflow">return</span> tmp; 
     142<a name="l00169"></a>00169         } 
     143<a name="l00170"></a><a class="code" href="classeprod.html#5adef154e3655a872c284b02635b8b35">00170</a>         <span class="keywordtype">double</span> <a class="code" href="classeprod.html#5adef154e3655a872c284b02635b8b35" title="Compute log-probability of argument val.">evalpdflog</a> ( <span class="keyword">const</span> vec &amp;val )<span class="keyword"> const </span>{ 
     144<a name="l00171"></a>00171                 <span class="keywordtype">double</span> tmp=0; 
     145<a name="l00172"></a>00172                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i&lt;<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { 
     146<a name="l00173"></a>00173                         tmp+=<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>(i)-&gt;evalpdflog(val(<a class="code" href="classeprod.html#a471987de1115dc639eccff65f3b9aa3" title="Array of indeces.">rvinds</a>(i))); 
     147<a name="l00174"></a>00174                 } 
     148<a name="l00175"></a>00175                 <span class="keywordflow">return</span> tmp; 
     149<a name="l00176"></a>00176         } 
     150<a name="l00178"></a><a class="code" href="classeprod.html#c049331d8b1ec7e4c088cf0cc6d47f3f">00178</a>         <span class="keyword">const</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* <a class="code" href="classeprod.html#c049331d8b1ec7e4c088cf0cc6d47f3f" title="access function">operator () </a>(<span class="keywordtype">int</span> i)<span class="keyword"> const </span>{it_assert_debug(i&lt;<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length(),<span class="stringliteral">"wrong index"</span>);<span class="keywordflow">return</span> <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>(i);} 
     151<a name="l00179"></a>00179 }; 
     152<a name="l00180"></a>00180  
     153<a name="l00181"></a>00181  
     154<a name="l00185"></a><a class="code" href="classmmix.html">00185</a> <span class="keyword">class </span><a class="code" href="classmmix.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="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { 
     155<a name="l00186"></a>00186 <span class="keyword">protected</span>: 
     156<a name="l00188"></a><a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f">00188</a>         Array&lt;mpdf*&gt; <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a>; 
     157<a name="l00190"></a><a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914">00190</a>         <a class="code" href="classemix.html" title="Mixture of epdfs.">emix</a> <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>; 
     158<a name="l00191"></a>00191 <span class="keyword">public</span>: 
     159<a name="l00193"></a><a class="code" href="classmmix.html#6769a962f1f4d0ecc5b903b5f7d26ad3">00193</a>         <a class="code" href="classmmix.html#6769a962f1f4d0ecc5b903b5f7d26ad3" title="Default constructor.">mmix</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;<a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>, <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &amp;<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ) : <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( rv, rvc ), <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a> ( rv ) {<a class="code" href="classmpdf.html#7aa894208a32f3487827df6d5054424c" title="pointer to internal epdf">ep</a> = &amp;<a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>;}; 
     160<a name="l00195"></a><a class="code" href="classmmix.html#e7681490a5c5b2d0a43f4e5842e10a9d">00195</a>         <span class="keywordtype">void</span> <a class="code" href="classmmix.html#e7681490a5c5b2d0a43f4e5842e10a9d" title="Set weights w and components R.">set_parameters</a> ( <span class="keyword">const</span> vec &amp;w, <span class="keyword">const</span> Array&lt;mpdf*&gt; &amp;<a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ) { 
     161<a name="l00196"></a>00196                 Array&lt;epdf*&gt; Eps ( Coms.length() ); 
     162<a name="l00197"></a>00197  
     163<a name="l00198"></a>00198                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i &lt; Coms.length();i++ ) { 
     164<a name="l00199"></a>00199                         Eps ( i ) = &amp; ( <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ( i )-&gt;_epdf() ); 
     165<a name="l00200"></a>00200                 } 
     166<a name="l00201"></a>00201                 <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>.<a class="code" href="classemix.html#6ce82b24d7fe540ddbf44b472a005555" title="Set weights w and components R.">set_parameters</a> ( w, Eps ); 
     167<a name="l00202"></a>00202         }; 
     168<a name="l00203"></a>00203  
     169<a name="l00204"></a><a class="code" href="classmmix.html#1a66629ec5c2b6f4740606cf737f0193">00204</a>         <span class="keywordtype">void</span> <a class="code" href="classmmix.html#1a66629ec5c2b6f4740606cf737f0193" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &amp;cond ) { 
     170<a name="l00205"></a>00205                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i &lt; <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a>.length();i++ ) {<a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ( i )-&gt;condition ( cond );} 
     171<a name="l00206"></a>00206         }; 
     172<a name="l00207"></a>00207 }; 
     173<a name="l00208"></a>00208 <span class="preprocessor">#endif //MX_H</span> 
    164174</pre></div></div> 
    165 <hr size="1"><address style="text-align: right;"><small>Generated on Thu Sep 4 19:28:00 2008 for mixpp by&nbsp; 
     175<hr size="1"><address style="text-align: right;"><small>Generated on Tue Sep 23 16:00:45 2008 for mixpp by&nbsp; 
    166176<a href="http://www.doxygen.org/index.html"> 
    167177<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>