93 | | <a name="l00124"></a><a class="code" href="classemix.html#44ae2b86c650c2ccb967969c1859d268">00124</a> mat <a class="code" href="classemix.html#44ae2b86c650c2ccb967969c1859d268" title="Auxiliary function that returns pdflog for each component.">evallog_M</a> ( <span class="keyword">const</span> mat &Val )<span class="keyword"> const </span>{ |
94 | | <a name="l00125"></a>00125 mat X ( <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>.length(), Val.cols() ); |
95 | | <a name="l00126"></a>00126 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>.length(); i++ ) { |
96 | | <a name="l00127"></a>00127 X.set_row ( i, <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a> ( i ) *exp ( <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i )-><a class="code" href="classemix.html#b3eb9e153e8bfdb6bb47adecc278cbca" title="Compute log-probability of multiple values argument val.">evallog_m</a> ( Val ) ) ); |
97 | | <a name="l00128"></a>00128 } |
98 | | <a name="l00129"></a>00129 <span class="keywordflow">return</span> X; |
99 | | <a name="l00130"></a>00130 }; |
100 | | <a name="l00131"></a>00131 |
101 | | <a name="l00132"></a>00132 <a class="code" href="classemix.html" title="Mixture of epdfs.">emix</a>* <a class="code" href="classemix.html#33afde698093d458ce71875f7ee7384a" 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="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ) <span class="keyword">const</span>; |
102 | | <a name="l00133"></a>00133 <a class="code" href="classmratio.html" title="Class representing ratio of two densities which arise e.g. by applying the Bayes...">mratio</a>* <a class="code" href="classemix.html#ebf50c387034f72040c83d38738549b3" 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="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ) <span class="keyword">const</span>; <span class="comment">//why not mratio!!</span> |
103 | | <a name="l00134"></a>00134 |
104 | | <a name="l00135"></a>00135 <span class="comment">//Access methods</span> |
105 | | <a name="l00137"></a><a class="code" href="classemix.html#35baf0f62307455cebfbf462144b4dd8">00137</a> <span class="comment"></span> vec& <a class="code" href="classemix.html#35baf0f62307455cebfbf462144b4dd8" title="returns a pointer to the internal mean value. Use with Care!">_w</a>() {<span class="keywordflow">return</span> <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>;} |
106 | | <a name="l00138"></a>00138 <span class="keyword">virtual</span> ~<a class="code" href="classemix.html" title="Mixture of epdfs.">emix</a>() {<span class="keywordflow">if</span> ( <a class="code" href="classemix.html#7d0d863e6066ee02947914ff06ac34e8" title="Flag if owning Coms.">destroyComs</a> ) {<span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a>.length();i++ ) {<span class="keyword">delete</span> <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i );}}} |
107 | | <a name="l00140"></a><a class="code" href="classemix.html#4d7baeb2a9e3fca1d8fd32a107df291d">00140</a> <span class="keywordtype">void</span> <a class="code" href="classemix.html#4d7baeb2a9e3fca1d8fd32a107df291d" title="Auxiliary function for taking ownership of the Coms().">ownComs</a>() {<a class="code" href="classemix.html#7d0d863e6066ee02947914ff06ac34e8" title="Flag if owning Coms.">destroyComs</a>=<span class="keyword">true</span>;} |
| 93 | <a name="l00123"></a><a class="code" href="classemix.html#b3eb9e153e8bfdb6bb47adecc278cbca">00123</a> vec <a class="code" href="classemix.html#b3eb9e153e8bfdb6bb47adecc278cbca" title="Compute log-probability of multiple values argument val.">evallog_m</a> ( <span class="keyword">const</span> mat &Val )<span class="keyword"> const </span>{ |
| 94 | <a name="l00124"></a>00124 vec x=zeros ( Val.cols() ); |
| 95 | <a name="l00125"></a>00125 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>.length(); i++ ) { |
| 96 | <a name="l00126"></a>00126 x+= <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a> ( i ) *exp ( <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i )-><a class="code" href="classemix.html#b3eb9e153e8bfdb6bb47adecc278cbca" title="Compute log-probability of multiple values argument val.">evallog_m</a> ( Val ) ); |
| 97 | <a name="l00127"></a>00127 } |
| 98 | <a name="l00128"></a>00128 <span class="keywordflow">return</span> log ( x ); |
| 99 | <a name="l00129"></a>00129 }; |
| 100 | <a name="l00131"></a><a class="code" href="classemix.html#44ae2b86c650c2ccb967969c1859d268">00131</a> mat <a class="code" href="classemix.html#44ae2b86c650c2ccb967969c1859d268" title="Auxiliary function that returns pdflog for each component.">evallog_M</a> ( <span class="keyword">const</span> mat &Val )<span class="keyword"> const </span>{ |
| 101 | <a name="l00132"></a>00132 mat X ( <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>.length(), Val.cols() ); |
| 102 | <a name="l00133"></a>00133 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>.length(); i++ ) { |
| 103 | <a name="l00134"></a>00134 X.set_row ( i, <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a> ( i ) *exp ( <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i )-><a class="code" href="classemix.html#b3eb9e153e8bfdb6bb47adecc278cbca" title="Compute log-probability of multiple values argument val.">evallog_m</a> ( Val ) ) ); |
| 104 | <a name="l00135"></a>00135 } |
| 105 | <a name="l00136"></a>00136 <span class="keywordflow">return</span> X; |
| 106 | <a name="l00137"></a>00137 }; |
| 107 | <a name="l00138"></a>00138 |
| 108 | <a name="l00139"></a>00139 <a class="code" href="classemix.html" title="Mixture of epdfs.">emix</a>* <a class="code" href="classemix.html#33afde698093d458ce71875f7ee7384a" 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="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ) <span class="keyword">const</span>; |
| 109 | <a name="l00140"></a>00140 <a class="code" href="classmratio.html" title="Class representing ratio of two densities which arise e.g. by applying the Bayes...">mratio</a>* <a class="code" href="classemix.html#ebf50c387034f72040c83d38738549b3" 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="classRV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ) <span class="keyword">const</span>; <span class="comment">//why not mratio!!</span> |
109 | | <a name="l00143"></a><a class="code" href="classemix.html#95d175b2daa1d896ceffd69b70e02efb">00143</a> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* <a class="code" href="classemix.html#95d175b2daa1d896ceffd69b70e02efb" title="access function">_Coms</a> ( <span class="keywordtype">int</span> i ) {<span class="keywordflow">return</span> <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i );} |
110 | | <a name="l00144"></a>00144 }; |
111 | | <a name="l00145"></a>00145 |
112 | | <a name="l00154"></a><a class="code" href="classmprod.html">00154</a> <span class="keyword">class </span><a class="code" href="classmprod.html" title="Chain rule decomposition of epdf.">mprod</a>: <span class="keyword">public</span> <a class="code" href="classcompositepdf.html" title="Abstract composition of pdfs, a base for specific classes this abstract class is...">compositepdf</a>, <span class="keyword">public</span> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { |
113 | | <a name="l00155"></a>00155 <span class="keyword">protected</span>: |
114 | | <a name="l00157"></a><a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e">00157</a> Array<epdf*> <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a>; |
115 | | <a name="l00159"></a><a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c">00159</a> Array<datalink_m2m*> <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a>; |
116 | | <a name="l00160"></a>00160 <span class="keyword">public</span>: |
117 | | <a name="l00163"></a><a class="code" href="classmprod.html#419b303581a91ad85200bdcb4b3186f4">00163</a> <a class="code" href="classmprod.html#419b303581a91ad85200bdcb4b3186f4" title="Constructor from list of mFacs,.">mprod</a> ( Array<mpdf*> mFacs ) : <a class="code" href="classcompositepdf.html" title="Abstract composition of pdfs, a base for specific classes this abstract class is...">compositepdf</a> ( mFacs ), <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( <a class="code" href="classcompositepdf.html#635d219fb3e32852400d6f98aa4bdc93" title="find common rv, flag">getrv</a> ( true ),<a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a>() ), <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> ), <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> ) { |
118 | | <a name="l00164"></a>00164 <a class="code" href="classcompositepdf.html#5a4479785c1fdb2cc351fbea07b899ac" title="common rvc of all mpdfs is written to rvc">setrvc</a> ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>,<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ); |
119 | | <a name="l00165"></a>00165 <span class="comment">// rv and rvc established = > we can link them with mpdfs</span> |
120 | | <a name="l00166"></a>00166 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a>;i++ ) { |
121 | | <a name="l00167"></a>00167 <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i ) = <span class="keyword">new</span> <a class="code" href="classdatalink__m2m.html">datalink_m2m</a> ( <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )-><a class="code" href="classmpdf.html#71256ffb5fbd08f41d650e606a5bd585" title="access function">_rv</a>(), <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )-><a class="code" href="classmpdf.html#15ef062183b1ccdf794732d5fa0b77cd" title="access function">_rvc</a>(), <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>, <a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ); |
122 | | <a name="l00168"></a>00168 } |
123 | | <a name="l00169"></a>00169 |
124 | | <a name="l00170"></a>00170 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<n;i++ ) { |
125 | | <a name="l00171"></a>00171 <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i ) =& ( <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->_epdf() ); |
126 | | <a name="l00172"></a>00172 } |
127 | | <a name="l00173"></a>00173 }; |
128 | | <a name="l00174"></a>00174 |
129 | | <a name="l00175"></a><a class="code" href="classmprod.html#f5e1075f133f203113d92084b4a47c28">00175</a> <span class="keywordtype">double</span> <a class="code" href="classmprod.html#f5e1075f133f203113d92084b4a47c28" 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 ) { |
130 | | <a name="l00176"></a>00176 <span class="keywordtype">int</span> i; |
131 | | <a name="l00177"></a>00177 <span class="keywordtype">double</span> res = 1.0; |
132 | | <a name="l00178"></a>00178 <span class="keywordflow">for</span> ( i = <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> - 1;i >= 0;i-- ) { |
133 | | <a name="l00179"></a>00179 <span class="comment">/* if ( mpdfs(i)->_rvc().count() >0) {</span> |
134 | | <a name="l00180"></a>00180 <span class="comment"> mpdfs ( i )->condition ( dls ( i )->get_cond ( val,cond ) );</span> |
135 | | <a name="l00181"></a>00181 <span class="comment"> }</span> |
136 | | <a name="l00182"></a>00182 <span class="comment"> // add logarithms</span> |
137 | | <a name="l00183"></a>00183 <span class="comment"> res += epdfs ( i )->evallog ( dls ( i )->get_val ( val ) );*/</span> |
138 | | <a name="l00184"></a>00184 res *= <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->evallogcond ( |
139 | | <a name="l00185"></a>00185 <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i )->get_val ( val ), |
140 | | <a name="l00186"></a>00186 <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i )->get_cond ( val, cond ) |
141 | | <a name="l00187"></a>00187 ); |
142 | | <a name="l00188"></a>00188 } |
143 | | <a name="l00189"></a>00189 <span class="keywordflow">return</span> res; |
144 | | <a name="l00190"></a>00190 } |
145 | | <a name="l00191"></a><a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68">00191</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 &cond, <span class="keywordtype">double</span> &ll ) { |
146 | | <a name="l00193"></a>00193 vec smp= std::numeric_limits<double>::infinity() * ones ( <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>() ); |
147 | | <a name="l00194"></a>00194 vec smpi; |
148 | | <a name="l00195"></a>00195 ll = 0; |
149 | | <a name="l00196"></a>00196 <span class="comment">// Hard assumption here!!! We are going backwards, to assure that samples that are needed from smp are already generated!</span> |
150 | | <a name="l00197"></a>00197 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = ( <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> - 1 );i >= 0;i-- ) { |
151 | | <a name="l00198"></a>00198 <span class="keywordflow">if</span> ( <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->_rvc().count() ) { |
152 | | <a name="l00199"></a>00199 <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->condition ( <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i )->get_cond ( smp ,cond ) ); <span class="comment">// smp is val here!!</span> |
153 | | <a name="l00200"></a>00200 } |
154 | | <a name="l00201"></a>00201 smpi = <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i )->sample(); |
155 | | <a name="l00202"></a>00202 <span class="comment">// copy contribution of this pdf into smp</span> |
156 | | <a name="l00203"></a>00203 <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i )->fill_val ( smp, smpi ); |
157 | | <a name="l00204"></a>00204 <span class="comment">// add ith likelihood contribution</span> |
158 | | <a name="l00205"></a>00205 ll+=<a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i )->evallog ( smpi ); |
159 | | <a name="l00206"></a>00206 } |
160 | | <a name="l00207"></a>00207 <span class="keywordflow">return</span> smp; |
161 | | <a name="l00208"></a>00208 } |
162 | | <a name="l00209"></a>00209 mat <a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68" title="Returns the required moment of the epdf.">samplecond</a> ( <span class="keyword">const</span> vec &cond, vec &ll, <span class="keywordtype">int</span> N ) { |
163 | | <a name="l00210"></a>00210 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 ); |
164 | | <a name="l00211"></a>00211 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<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 ) ) );} |
165 | | <a name="l00212"></a>00212 <span class="keywordflow">return</span> Smp; |
166 | | <a name="l00213"></a>00213 } |
167 | | <a name="l00214"></a>00214 |
168 | | <a name="l00215"></a>00215 ~<a class="code" href="classmprod.html" title="Chain rule decomposition of epdf.">mprod</a>() {}; |
169 | | <a name="l00216"></a>00216 }; |
170 | | <a name="l00217"></a>00217 |
171 | | <a name="l00219"></a><a class="code" href="classeprod.html">00219</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> { |
172 | | <a name="l00220"></a>00220 <span class="keyword">protected</span>: |
173 | | <a name="l00222"></a><a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357">00222</a> Array<const epdf*> <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>; |
174 | | <a name="l00224"></a><a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29">00224</a> Array<datalink_e2e*> <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a>; |
175 | | <a name="l00225"></a>00225 <span class="keyword">public</span>: |
176 | | <a name="l00226"></a>00226 <a class="code" href="classeprod.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="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#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length() ) { |
177 | | <a name="l00227"></a>00227 <span class="keywordtype">bool</span> independent=<span class="keyword">true</span>; |
178 | | <a name="l00228"></a>00228 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
179 | | <a name="l00229"></a>00229 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 )-><a class="code" href="classepdf.html#ca0d32aabb4cbba347e0c37fe8607562" title="access function, possibly dangerous!">_rv</a>() ); |
180 | | <a name="l00230"></a>00230 it_assert_debug ( independent==<span class="keyword">true</span>, <span class="stringliteral">"eprod:: given components are not independent ."</span> ); |
181 | | <a name="l00231"></a>00231 } |
182 | | <a name="l00232"></a>00232 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
183 | | <a name="l00233"></a>00233 <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i ) = <span class="keyword">new</span> <a class="code" href="classdatalink__e2e.html">datalink_e2e</a> ( <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )-><a class="code" href="classepdf.html#ca0d32aabb4cbba347e0c37fe8607562" title="access function, possibly dangerous!">_rv</a>() , <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ); |
184 | | <a name="l00234"></a>00234 } |
185 | | <a name="l00235"></a>00235 } |
186 | | <a name="l00236"></a>00236 |
187 | | <a name="l00237"></a><a class="code" href="classeprod.html#5752dd999e1f4638f9558b0cc35b64f7">00237</a> vec <a class="code" href="classeprod.html#5752dd999e1f4638f9558b0cc35b64f7" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
188 | | <a name="l00238"></a>00238 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>() ); |
| 111 | <a name="l00142"></a>00142 <span class="comment">//Access methods</span> |
| 112 | <a name="l00144"></a><a class="code" href="classemix.html#35baf0f62307455cebfbf462144b4dd8">00144</a> <span class="comment"></span> vec& <a class="code" href="classemix.html#35baf0f62307455cebfbf462144b4dd8" title="returns a pointer to the internal mean value. Use with Care!">_w</a>() {<span class="keywordflow">return</span> <a class="code" href="classemix.html#cdc8f4e2a5e43595ac5450d8a7f9d1ab" title="weights of the components">w</a>;} |
| 113 | <a name="l00145"></a>00145 <span class="keyword">virtual</span> ~<a class="code" href="classemix.html" title="Mixture of epdfs.">emix</a>() {<span class="keywordflow">if</span> ( <a class="code" href="classemix.html#7d0d863e6066ee02947914ff06ac34e8" title="Flag if owning Coms.">destroyComs</a> ) {<span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a>.length();i++ ) {<span class="keyword">delete</span> <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i );}}} |
| 114 | <a name="l00147"></a><a class="code" href="classemix.html#4d7baeb2a9e3fca1d8fd32a107df291d">00147</a> <span class="keywordtype">void</span> <a class="code" href="classemix.html#4d7baeb2a9e3fca1d8fd32a107df291d" title="Auxiliary function for taking ownership of the Coms().">ownComs</a>() {<a class="code" href="classemix.html#7d0d863e6066ee02947914ff06ac34e8" title="Flag if owning Coms.">destroyComs</a>=<span class="keyword">true</span>;} |
| 115 | <a name="l00148"></a>00148 |
| 116 | <a name="l00150"></a><a class="code" href="classemix.html#95d175b2daa1d896ceffd69b70e02efb">00150</a> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* <a class="code" href="classemix.html#95d175b2daa1d896ceffd69b70e02efb" title="access function">_Coms</a> ( <span class="keywordtype">int</span> i ) {<span class="keywordflow">return</span> <a class="code" href="classemix.html#7155d827417b53fb6aa5cff1459e6eb4" title="Component (epdfs).">Coms</a> ( i );} |
| 117 | <a name="l00151"></a>00151 }; |
| 118 | <a name="l00152"></a>00152 |
| 119 | <a name="l00161"></a><a class="code" href="classmprod.html">00161</a> <span class="keyword">class </span><a class="code" href="classmprod.html" title="Chain rule decomposition of epdf.">mprod</a>: <span class="keyword">public</span> <a class="code" href="classcompositepdf.html" title="Abstract composition of pdfs, a base for specific classes this abstract class is...">compositepdf</a>, <span class="keyword">public</span> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> { |
| 120 | <a name="l00162"></a>00162 <span class="keyword">protected</span>: |
| 121 | <a name="l00164"></a><a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e">00164</a> Array<epdf*> <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a>; |
| 122 | <a name="l00166"></a><a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c">00166</a> Array<datalink_m2m*> <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a>; |
| 123 | <a name="l00167"></a>00167 <span class="keyword">public</span>: |
| 124 | <a name="l00170"></a><a class="code" href="classmprod.html#419b303581a91ad85200bdcb4b3186f4">00170</a> <a class="code" href="classmprod.html#419b303581a91ad85200bdcb4b3186f4" title="Constructor from list of mFacs,.">mprod</a> ( Array<mpdf*> mFacs ) : <a class="code" href="classcompositepdf.html" title="Abstract composition of pdfs, a base for specific classes this abstract class is...">compositepdf</a> ( mFacs ), <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> ( <a class="code" href="classcompositepdf.html#635d219fb3e32852400d6f98aa4bdc93" title="find common rv, flag">getrv</a> ( true ),<a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a>() ), <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> ), <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> ) { |
| 125 | <a name="l00171"></a>00171 <a class="code" href="classcompositepdf.html#5a4479785c1fdb2cc351fbea07b899ac" title="common rvc of all mpdfs is written to rvc">setrvc</a> ( <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>,<a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ); |
| 126 | <a name="l00172"></a>00172 <span class="comment">// rv and rvc established = > we can link them with mpdfs</span> |
| 127 | <a name="l00173"></a>00173 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a>;i++ ) { |
| 128 | <a name="l00174"></a>00174 <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i ) = <span class="keyword">new</span> <a class="code" href="classdatalink__m2m.html">datalink_m2m</a> ( <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )-><a class="code" href="classmpdf.html#71256ffb5fbd08f41d650e606a5bd585" title="access function">_rv</a>(), <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )-><a class="code" href="classmpdf.html#15ef062183b1ccdf794732d5fa0b77cd" title="access function">_rvc</a>(), <a class="code" href="classmpdf.html#f6687c07ff07d47812dd565368ca59eb" title="modeled random variable">rv</a>, <a class="code" href="classmpdf.html#acb7dda792b3cd5576f39fa3129abbab" title="random variable in condition">rvc</a> ); |
| 129 | <a name="l00175"></a>00175 } |
| 130 | <a name="l00176"></a>00176 |
| 131 | <a name="l00177"></a>00177 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<n;i++ ) { |
| 132 | <a name="l00178"></a>00178 <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i ) =& ( <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->_epdf() ); |
| 133 | <a name="l00179"></a>00179 } |
| 134 | <a name="l00180"></a>00180 }; |
| 135 | <a name="l00181"></a>00181 |
| 136 | <a name="l00182"></a><a class="code" href="classmprod.html#f5e1075f133f203113d92084b4a47c28">00182</a> <span class="keywordtype">double</span> <a class="code" href="classmprod.html#f5e1075f133f203113d92084b4a47c28" 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 ) { |
| 137 | <a name="l00183"></a>00183 <span class="keywordtype">int</span> i; |
| 138 | <a name="l00184"></a>00184 <span class="keywordtype">double</span> res = 1.0; |
| 139 | <a name="l00185"></a>00185 <span class="keywordflow">for</span> ( i = <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> - 1;i >= 0;i-- ) { |
| 140 | <a name="l00186"></a>00186 <span class="comment">/* if ( mpdfs(i)->_rvc().count() >0) {</span> |
| 141 | <a name="l00187"></a>00187 <span class="comment"> mpdfs ( i )->condition ( dls ( i )->get_cond ( val,cond ) );</span> |
| 142 | <a name="l00188"></a>00188 <span class="comment"> }</span> |
| 143 | <a name="l00189"></a>00189 <span class="comment"> // add logarithms</span> |
| 144 | <a name="l00190"></a>00190 <span class="comment"> res += epdfs ( i )->evallog ( dls ( i )->get_val ( val ) );*/</span> |
| 145 | <a name="l00191"></a>00191 res *= <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->evallogcond ( |
| 146 | <a name="l00192"></a>00192 <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i )->get_val ( val ), |
| 147 | <a name="l00193"></a>00193 <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i )->get_cond ( val, cond ) |
| 148 | <a name="l00194"></a>00194 ); |
| 149 | <a name="l00195"></a>00195 } |
| 150 | <a name="l00196"></a>00196 <span class="keywordflow">return</span> res; |
| 151 | <a name="l00197"></a>00197 } |
| 152 | <a name="l00198"></a><a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68">00198</a> vec <a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68" 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 ) { |
| 153 | <a name="l00200"></a>00200 vec smp= std::numeric_limits<double>::infinity() * ones ( <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>() ); |
| 154 | <a name="l00201"></a>00201 vec smpi; |
| 155 | <a name="l00202"></a>00202 ll = 0; |
| 156 | <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> |
| 157 | <a name="l00204"></a>00204 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = ( <a class="code" href="classcompositepdf.html#c1646fe41ff5934d010e54ccaa46133f" title="Number of mpdfs in the composite.">n</a> - 1 );i >= 0;i-- ) { |
| 158 | <a name="l00205"></a>00205 <span class="keywordflow">if</span> ( <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->_rvc().count() ) { |
| 159 | <a name="l00206"></a>00206 <a class="code" href="classcompositepdf.html#637877061b917a16a0421bb5c4cd480d" title="Elements of composition.">mpdfs</a> ( i )->condition ( <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i )->get_cond ( smp ,cond ) ); <span class="comment">// smp is val here!!</span> |
| 160 | <a name="l00207"></a>00207 } |
| 161 | <a name="l00208"></a>00208 smpi = <a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i )->sample(); |
| 162 | <a name="l00209"></a>00209 <span class="comment">// copy contribution of this pdf into smp</span> |
| 163 | <a name="l00210"></a>00210 <a class="code" href="classmprod.html#5334777dda3dad9b9fa73e22e8d0f24c" title="Data link for each mpdfs.">dls</a> ( i )->fill_val ( smp, smpi ); |
| 164 | <a name="l00211"></a>00211 <span class="comment">// add ith likelihood contribution</span> |
| 165 | <a name="l00212"></a>00212 ll+=<a class="code" href="classmprod.html#0883ce383e8475546df138719918f70e" title="pointers to epdfs - shortcut to mpdfs()._epdf()">epdfs</a> ( i )->evallog ( smpi ); |
| 166 | <a name="l00213"></a>00213 } |
| 167 | <a name="l00214"></a>00214 <span class="keywordflow">return</span> smp; |
| 168 | <a name="l00215"></a>00215 } |
| 169 | <a name="l00216"></a>00216 mat <a class="code" href="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68" 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 ) { |
| 170 | <a name="l00217"></a>00217 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 ); |
| 171 | <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="classmprod.html#a48887eb8738a9e5550bfc38eb8e9d68" title="Returns a sample from the density conditioned on cond, .">samplecond</a> ( cond,ll ( i ) ) );} |
| 172 | <a name="l00219"></a>00219 <span class="keywordflow">return</span> Smp; |
| 173 | <a name="l00220"></a>00220 } |
| 174 | <a name="l00221"></a>00221 |
| 175 | <a name="l00222"></a>00222 ~<a class="code" href="classmprod.html" title="Chain rule decomposition of epdf.">mprod</a>() {}; |
| 176 | <a name="l00223"></a>00223 }; |
| 177 | <a name="l00224"></a>00224 |
| 178 | <a name="l00226"></a><a class="code" href="classeprod.html">00226</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> { |
| 179 | <a name="l00227"></a>00227 <span class="keyword">protected</span>: |
| 180 | <a name="l00229"></a><a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357">00229</a> Array<const epdf*> <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>; |
| 181 | <a name="l00231"></a><a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29">00231</a> Array<datalink_e2e*> <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a>; |
| 182 | <a name="l00232"></a>00232 <span class="keyword">public</span>: |
| 183 | <a name="l00233"></a>00233 <a class="code" href="classeprod.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="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#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length() ) { |
| 184 | <a name="l00234"></a>00234 <span class="keywordtype">bool</span> independent=<span class="keyword">true</span>; |
| 185 | <a name="l00235"></a>00235 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 186 | <a name="l00236"></a>00236 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 )-><a class="code" href="classepdf.html#ca0d32aabb4cbba347e0c37fe8607562" title="access function, possibly dangerous!">_rv</a>() ); |
| 187 | <a name="l00237"></a>00237 it_assert_debug ( independent==<span class="keyword">true</span>, <span class="stringliteral">"eprod:: given components are not independent ."</span> ); |
| 188 | <a name="l00238"></a>00238 } |
190 | | <a name="l00240"></a>00240 vec pom = <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->mean(); |
191 | | <a name="l00241"></a>00241 <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i )->fill_val ( tmp, pom ); |
192 | | <a name="l00242"></a>00242 } |
193 | | <a name="l00243"></a>00243 <span class="keywordflow">return</span> tmp; |
194 | | <a name="l00244"></a>00244 } |
195 | | <a name="l00245"></a><a class="code" href="classeprod.html#94a5b7c44056cf7f4e688d53ba6295b4">00245</a> vec <a class="code" href="classeprod.html#94a5b7c44056cf7f4e688d53ba6295b4" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
196 | | <a name="l00246"></a>00246 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>() ); |
197 | | <a name="l00247"></a>00247 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
198 | | <a name="l00248"></a>00248 vec pom = <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->sample(); |
199 | | <a name="l00249"></a>00249 <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i )->fill_val ( tmp, pom ); |
200 | | <a name="l00250"></a>00250 } |
201 | | <a name="l00251"></a>00251 <span class="keywordflow">return</span> tmp; |
202 | | <a name="l00252"></a>00252 } |
203 | | <a name="l00253"></a><a class="code" href="classeprod.html#0af49e491414d6f270dc347bcb054eb6">00253</a> <span class="keywordtype">double</span> <a class="code" href="classeprod.html#0af49e491414d6f270dc347bcb054eb6" title="Compute log-probability of argument val.">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
204 | | <a name="l00254"></a>00254 <span class="keywordtype">double</span> tmp=0; |
205 | | <a name="l00255"></a>00255 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
206 | | <a name="l00256"></a>00256 tmp+=<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->evallog ( <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i )->get_val ( val ) ); |
| 190 | <a name="l00240"></a>00240 <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i ) = <span class="keyword">new</span> <a class="code" href="classdatalink__e2e.html">datalink_e2e</a> ( <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )-><a class="code" href="classepdf.html#ca0d32aabb4cbba347e0c37fe8607562" title="access function, possibly dangerous!">_rv</a>() , <a class="code" href="classepdf.html#74da992e3f5d598da8850b646b79b9d9" title="Identified of the random variable.">rv</a> ); |
| 191 | <a name="l00241"></a>00241 } |
| 192 | <a name="l00242"></a>00242 } |
| 193 | <a name="l00243"></a>00243 |
| 194 | <a name="l00244"></a><a class="code" href="classeprod.html#5752dd999e1f4638f9558b0cc35b64f7">00244</a> vec <a class="code" href="classeprod.html#5752dd999e1f4638f9558b0cc35b64f7" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
| 195 | <a name="l00245"></a>00245 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>() ); |
| 196 | <a name="l00246"></a>00246 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 197 | <a name="l00247"></a>00247 vec pom = <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->mean(); |
| 198 | <a name="l00248"></a>00248 <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i )->fill_val ( tmp, pom ); |
| 199 | <a name="l00249"></a>00249 } |
| 200 | <a name="l00250"></a>00250 <span class="keywordflow">return</span> tmp; |
| 201 | <a name="l00251"></a>00251 } |
| 202 | <a name="l00252"></a><a class="code" href="classeprod.html#71d37aa4676dc41bb4ff6ceb4ccdc594">00252</a> vec <a class="code" href="classeprod.html#71d37aa4676dc41bb4ff6ceb4ccdc594" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
| 203 | <a name="l00253"></a>00253 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>() ); <span class="comment">//second moment</span> |
| 204 | <a name="l00254"></a>00254 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 205 | <a name="l00255"></a>00255 vec pom = <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->mean(); |
| 206 | <a name="l00256"></a>00256 <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i )->fill_val ( tmp, pow(pom,2) ); |
208 | | <a name="l00258"></a>00258 it_assert_debug(std::isfinite(tmp),<span class="stringliteral">"Infinite"</span>); |
209 | | <a name="l00259"></a>00259 <span class="keywordflow">return</span> tmp; |
210 | | <a name="l00260"></a>00260 } |
211 | | <a name="l00262"></a><a class="code" href="classeprod.html#c049331d8b1ec7e4c088cf0cc6d47f3f">00262</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<<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 );} |
212 | | <a name="l00263"></a>00263 |
213 | | <a name="l00265"></a><a class="code" href="classeprod.html#fe8cc34921cb43558654455007676f05">00265</a> <a class="code" href="classeprod.html#fe8cc34921cb43558654455007676f05" title="Destructor.">~eprod</a>() {<span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) {<span class="keyword">delete</span> <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i );}} |
214 | | <a name="l00266"></a>00266 }; |
215 | | <a name="l00267"></a>00267 |
216 | | <a name="l00268"></a>00268 |
217 | | <a name="l00272"></a><a class="code" href="classmmix.html">00272</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> { |
218 | | <a name="l00273"></a>00273 <span class="keyword">protected</span>: |
219 | | <a name="l00275"></a><a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f">00275</a> Array<mpdf*> <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a>; |
220 | | <a name="l00277"></a><a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914">00277</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>; |
221 | | <a name="l00278"></a>00278 <span class="keyword">public</span>: |
222 | | <a name="l00280"></a><a class="code" href="classmmix.html#6769a962f1f4d0ecc5b903b5f7d26ad3">00280</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> &<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> &<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> = &<a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>;}; |
223 | | <a name="l00282"></a><a class="code" href="classmmix.html#e7681490a5c5b2d0a43f4e5842e10a9d">00282</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 &w, <span class="keyword">const</span> Array<mpdf*> &<a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ) { |
224 | | <a name="l00283"></a>00283 Array<epdf*> Eps ( Coms.length() ); |
225 | | <a name="l00284"></a>00284 |
226 | | <a name="l00285"></a>00285 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < Coms.length();i++ ) { |
227 | | <a name="l00286"></a>00286 Eps ( i ) = & ( <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ( i )->_epdf() ); |
228 | | <a name="l00287"></a>00287 } |
229 | | <a name="l00288"></a>00288 <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>.<a class="code" href="classemix.html#d3789d50a3327a6de552db077af5e4c5">set_parameters</a> ( w, Eps ); |
230 | | <a name="l00289"></a>00289 }; |
231 | | <a name="l00290"></a>00290 |
232 | | <a name="l00291"></a><a class="code" href="classmmix.html#1a66629ec5c2b6f4740606cf737f0193">00291</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 &cond ) { |
233 | | <a name="l00292"></a>00292 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < <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 )->condition ( cond );} |
234 | | <a name="l00293"></a>00293 }; |
235 | | <a name="l00294"></a>00294 }; |
236 | | <a name="l00295"></a>00295 |
237 | | <a name="l00296"></a>00296 <span class="preprocessor">#endif //MX_H</span> |
| 208 | <a name="l00258"></a>00258 <span class="keywordflow">return</span> tmp-pow(<a class="code" href="classeprod.html#5752dd999e1f4638f9558b0cc35b64f7" title="return expected value">mean</a>(),2); |
| 209 | <a name="l00259"></a>00259 } |
| 210 | <a name="l00260"></a><a class="code" href="classeprod.html#94a5b7c44056cf7f4e688d53ba6295b4">00260</a> vec <a class="code" href="classeprod.html#94a5b7c44056cf7f4e688d53ba6295b4" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
| 211 | <a name="l00261"></a>00261 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>() ); |
| 212 | <a name="l00262"></a>00262 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 213 | <a name="l00263"></a>00263 vec pom = <a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->sample(); |
| 214 | <a name="l00264"></a>00264 <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i )->fill_val ( tmp, pom ); |
| 215 | <a name="l00265"></a>00265 } |
| 216 | <a name="l00266"></a>00266 <span class="keywordflow">return</span> tmp; |
| 217 | <a name="l00267"></a>00267 } |
| 218 | <a name="l00268"></a><a class="code" href="classeprod.html#0af49e491414d6f270dc347bcb054eb6">00268</a> <span class="keywordtype">double</span> <a class="code" href="classeprod.html#0af49e491414d6f270dc347bcb054eb6" title="Compute log-probability of argument val.">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
| 219 | <a name="l00269"></a>00269 <span class="keywordtype">double</span> tmp=0; |
| 220 | <a name="l00270"></a>00270 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) { |
| 221 | <a name="l00271"></a>00271 tmp+=<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a> ( i )->evallog ( <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i )->get_val ( val ) ); |
| 222 | <a name="l00272"></a>00272 } |
| 223 | <a name="l00273"></a>00273 it_assert_debug(std::isfinite(tmp),<span class="stringliteral">"Infinite"</span>); |
| 224 | <a name="l00274"></a>00274 <span class="keywordflow">return</span> tmp; |
| 225 | <a name="l00275"></a>00275 } |
| 226 | <a name="l00277"></a><a class="code" href="classeprod.html#c049331d8b1ec7e4c088cf0cc6d47f3f">00277</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<<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 );} |
| 227 | <a name="l00278"></a>00278 |
| 228 | <a name="l00280"></a><a class="code" href="classeprod.html#fe8cc34921cb43558654455007676f05">00280</a> <a class="code" href="classeprod.html#fe8cc34921cb43558654455007676f05" title="Destructor.">~eprod</a>() {<span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classeprod.html#63fc0db078542bce1c5dff94f9c3a357" title="Components (epdfs).">epdfs</a>.length();i++ ) {<span class="keyword">delete</span> <a class="code" href="classeprod.html#852a8e1b5b52a992f56cd2ab6c0b4a29" title="Array of indeces.">dls</a> ( i );}} |
| 229 | <a name="l00281"></a>00281 }; |
| 230 | <a name="l00282"></a>00282 |
| 231 | <a name="l00283"></a>00283 |
| 232 | <a name="l00287"></a><a class="code" href="classmmix.html">00287</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> { |
| 233 | <a name="l00288"></a>00288 <span class="keyword">protected</span>: |
| 234 | <a name="l00290"></a><a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f">00290</a> Array<mpdf*> <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a>; |
| 235 | <a name="l00292"></a><a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914">00292</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>; |
| 236 | <a name="l00293"></a>00293 <span class="keyword">public</span>: |
| 237 | <a name="l00295"></a><a class="code" href="classmmix.html#6769a962f1f4d0ecc5b903b5f7d26ad3">00295</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> &<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> &<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> = &<a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>;}; |
| 238 | <a name="l00297"></a><a class="code" href="classmmix.html#e7681490a5c5b2d0a43f4e5842e10a9d">00297</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 &w, <span class="keyword">const</span> Array<mpdf*> &<a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ) { |
| 239 | <a name="l00298"></a>00298 Array<epdf*> Eps ( Coms.length() ); |
| 240 | <a name="l00299"></a>00299 |
| 241 | <a name="l00300"></a>00300 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < Coms.length();i++ ) { |
| 242 | <a name="l00301"></a>00301 Eps ( i ) = & ( <a class="code" href="classmmix.html#460632c7a0afd41b7840902181a7d85f" title="Component (epdfs).">Coms</a> ( i )->_epdf() ); |
| 243 | <a name="l00302"></a>00302 } |
| 244 | <a name="l00303"></a>00303 <a class="code" href="classmmix.html#507a5e6df53e6e9a6a330f1271cf0914" title="Internal epdf.">Epdf</a>.<a class="code" href="classemix.html#d3789d50a3327a6de552db077af5e4c5">set_parameters</a> ( w, Eps ); |
| 245 | <a name="l00304"></a>00304 }; |
| 246 | <a name="l00305"></a>00305 |
| 247 | <a name="l00306"></a><a class="code" href="classmmix.html#1a66629ec5c2b6f4740606cf737f0193">00306</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 &cond ) { |
| 248 | <a name="l00307"></a>00307 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0;i < <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 )->condition ( cond );} |
| 249 | <a name="l00308"></a>00308 }; |
| 250 | <a name="l00309"></a>00309 }; |
| 251 | <a name="l00310"></a>00310 |
| 252 | <a name="l00311"></a>00311 <span class="preprocessor">#endif //MX_H</span> |