139 | | <a name="l00128"></a>00128 |
140 | | <a name="l00131"></a>00131 |
141 | | <a name="l00133"></a>00133 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2" title="dupdate in exponential form (not really handy)">dupdate</a> ( mat &v,<span class="keywordtype">double</span> nu=1.0 ); |
142 | | <a name="l00134"></a>00134 |
143 | | <a name="l00135"></a>00135 vec <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
144 | | <a name="l00136"></a>00136 mat <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">sample</a> ( <span class="keywordtype">int</span> N ) <span class="keyword">const</span>; |
145 | | <a name="l00137"></a>00137 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3" title="Evaluate normalized log-probability.">evallog_nn</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
146 | | <a name="l00138"></a>00138 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
147 | | <a name="l00139"></a><a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600">00139</a> vec <a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>;} |
148 | | <a name="l00140"></a><a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773">00140</a> vec <a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> diag ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.to_mat() );} |
149 | | <a name="l00141"></a>00141 <span class="comment">// mlnorm<sq_T>* condition ( const RV &rvn ) const ; <=========== fails to cmpile. Why?</span> |
150 | | <a name="l00142"></a>00142 <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a>* <a class="code" href="classbdm_1_1enorm.html#baea4d49c657342b58297d68cda16d26" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">condition</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn ) <span class="keyword">const</span> ; |
151 | | <a name="l00143"></a>00143 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* <a class="code" href="classbdm_1_1enorm.html#c2996bdaffad38fbe0fc776db54c9d80" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ) <span class="keyword">const</span>; |
152 | | <a name="l00144"></a>00144 <span class="comment">// epdf* marginal ( const RV &rv ) const;</span> |
153 | | <a name="l00146"></a>00146 <span class="comment"></span> |
154 | | <a name="l00149"></a>00149 |
155 | | <a name="l00150"></a>00150 vec& _mu() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>;} |
156 | | <a name="l00151"></a>00151 <span class="keywordtype">void</span> set_mu ( <span class="keyword">const</span> vec mu0 ) { <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>=mu0;} |
157 | | <a name="l00152"></a>00152 sq_T& _R() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>;} |
158 | | <a name="l00153"></a>00153 <span class="keyword">const</span> sq_T& _R()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>;} |
159 | | <a name="l00155"></a>00155 |
160 | | <a name="l00156"></a>00156 }; |
161 | | <a name="l00157"></a>00157 |
162 | | <a name="l00164"></a><a class="code" href="classbdm_1_1egiw.html">00164</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1egiw.html" title="Gauss-inverse-Wishart density stored in LD form.">egiw</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
163 | | <a name="l00165"></a>00165 { |
164 | | <a name="l00166"></a>00166 <span class="keyword">protected</span>: |
165 | | <a name="l00168"></a><a class="code" href="classbdm_1_1egiw.html#ae56852845c6af176fd9017dbebbbd52">00168</a> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1egiw.html#ae56852845c6af176fd9017dbebbbd52" title="Extended information matrix of sufficient statistics.">V</a>; |
166 | | <a name="l00170"></a><a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4">00170</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>; |
167 | | <a name="l00172"></a><a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a">00172</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>; |
168 | | <a name="l00174"></a><a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd">00174</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a>; |
169 | | <a name="l00175"></a>00175 <span class="keyword">public</span>: |
170 | | <a name="l00178"></a>00178 <a class="code" href="classbdm_1_1egiw.html" title="Gauss-inverse-Wishart density stored in LD form.">egiw</a>() :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a>() {}; |
171 | | <a name="l00179"></a>00179 <a class="code" href="classbdm_1_1egiw.html" title="Gauss-inverse-Wishart density stored in LD form.">egiw</a> ( <span class="keywordtype">int</span> dimx0, <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> V0, <span class="keywordtype">double</span> nu0=-1.0 ) :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a>() {set_parameters ( dimx0,V0, nu0 );}; |
172 | | <a name="l00180"></a>00180 |
173 | | <a name="l00181"></a>00181 <span class="keywordtype">void</span> set_parameters ( <span class="keywordtype">int</span> dimx0, <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> V0, <span class="keywordtype">double</span> nu0=-1.0 ) |
174 | | <a name="l00182"></a>00182 { |
175 | | <a name="l00183"></a>00183 <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>=dimx0; |
176 | | <a name="l00184"></a>00184 <a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> = V0.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>()-<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>; |
177 | | <a name="l00185"></a>00185 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>* ( <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>+<a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> ); <span class="comment">// size(R) + size(Theta)</span> |
178 | | <a name="l00186"></a>00186 |
179 | | <a name="l00187"></a>00187 <a class="code" href="classbdm_1_1egiw.html#ae56852845c6af176fd9017dbebbbd52" title="Extended information matrix of sufficient statistics.">V</a>=V0; |
180 | | <a name="l00188"></a>00188 <span class="keywordflow">if</span> ( nu0<0 ) |
181 | | <a name="l00189"></a>00189 { |
182 | | <a name="l00190"></a>00190 <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a> = 0.1 +<a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> +2*<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a> +2; <span class="comment">// +2 assures finite expected value of R</span> |
183 | | <a name="l00191"></a>00191 <span class="comment">// terms before that are sufficient for finite normalization</span> |
184 | | <a name="l00192"></a>00192 } |
185 | | <a name="l00193"></a>00193 <span class="keywordflow">else</span> |
186 | | <a name="l00194"></a>00194 { |
187 | | <a name="l00195"></a>00195 <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>=nu0; |
188 | | <a name="l00196"></a>00196 } |
189 | | <a name="l00197"></a>00197 } |
190 | | <a name="l00199"></a>00199 |
191 | | <a name="l00200"></a>00200 vec <a class="code" href="classbdm_1_1egiw.html#920f21548b7a3723923dd108fe514c61" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
192 | | <a name="l00201"></a>00201 vec <a class="code" href="classbdm_1_1egiw.html#df70c05f918c3a6f86d60f10c1fd6ba2" title="return expected value">mean</a>() <span class="keyword">const</span>; |
193 | | <a name="l00202"></a>00202 vec <a class="code" href="classbdm_1_1egiw.html#c1ecc406613cc2341225dc10c3d3b46a" title="return expected variance (not covariance!)">variance</a>() <span class="keyword">const</span>; |
194 | | <a name="l00203"></a>00203 |
195 | | <a name="l00205"></a>00205 vec <a class="code" href="classbdm_1_1egiw.html#66d2ba9295c306012b309efcc9e516f0" title="LS estimate of .">est_theta</a>() <span class="keyword">const</span>; |
196 | | <a name="l00206"></a>00206 |
197 | | <a name="l00208"></a>00208 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1egiw.html#88c321a2051d1afdbb31a098896a717b" title="Covariance of the LS estimate.">est_theta_cov</a>() <span class="keyword">const</span>; |
198 | | <a name="l00209"></a>00209 |
199 | | <a name="l00210"></a>00210 <span class="keywordtype">void</span> mean_mat ( mat &M, mat&R ) <span class="keyword">const</span>; |
200 | | <a name="l00212"></a>00212 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#bfb8e7c619b34ad804a73bff71742b5e" title="In this instance, val= [theta, r]. For multivariate instances, it is stored columnwise...">evallog_nn</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
201 | | <a name="l00213"></a>00213 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#41d72ba7b2abc8a9a4209ffa98ed5633" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
202 | | <a name="l00214"></a><a class="code" href="classbdm_1_1egiw.html#8e610e95401a11baf34f65e16ecd87be">00214</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egiw.html#8e610e95401a11baf34f65e16ecd87be" title="Power of the density, used e.g. to flatten the density.">pow</a> ( <span class="keywordtype">double</span> p ) {V*=p;<a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>*=p;}; |
203 | | <a name="l00215"></a>00215 |
204 | | <a name="l00218"></a>00218 |
205 | | <a name="l00219"></a>00219 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& _V() {<span class="keywordflow">return</span> V;} |
206 | | <a name="l00220"></a>00220 <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& _V()<span class="keyword"> const </span>{<span class="keywordflow">return</span> V;} |
207 | | <a name="l00221"></a>00221 <span class="keywordtype">double</span>& _nu() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>;} |
208 | | <a name="l00222"></a>00222 <span class="keyword">const</span> <span class="keywordtype">double</span>& _nu()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>;} |
209 | | <a name="l00224"></a>00224 }; |
210 | | <a name="l00225"></a>00225 |
211 | | <a name="l00234"></a><a class="code" href="classbdm_1_1eDirich.html">00234</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
212 | | <a name="l00235"></a>00235 { |
213 | | <a name="l00236"></a>00236 <span class="keyword">protected</span>: |
214 | | <a name="l00238"></a><a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2">00238</a> vec <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>; |
215 | | <a name="l00239"></a>00239 <span class="keyword">public</span>: |
216 | | <a name="l00242"></a>00242 |
217 | | <a name="l00243"></a>00243 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> () : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( ) {}; |
218 | | <a name="l00244"></a>00244 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> &D0 ) : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> () {set_parameters ( D0.<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> );}; |
219 | | <a name="l00245"></a>00245 eDirich ( <span class="keyword">const</span> vec &beta0 ) {set_parameters ( beta0 );}; |
220 | | <a name="l00246"></a>00246 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &beta0 ) |
221 | | <a name="l00247"></a>00247 { |
222 | | <a name="l00248"></a>00248 <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>= beta0; |
223 | | <a name="l00249"></a>00249 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length(); |
224 | | <a name="l00250"></a>00250 } |
225 | | <a name="l00252"></a>00252 |
226 | | <a name="l00253"></a><a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc">00253</a> vec <a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> vec_1 ( 0.0 );}; |
227 | | <a name="l00254"></a><a class="code" href="classbdm_1_1eDirich.html#cb343355ec791298bb5a3404cd482fb6">00254</a> vec <a class="code" href="classbdm_1_1eDirich.html#cb343355ec791298bb5a3404cd482fb6" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>/sum(<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>);}; |
228 | | <a name="l00255"></a><a class="code" href="classbdm_1_1eDirich.html#43c547a2507e233706f92712d8c2aacc">00255</a> vec <a class="code" href="classbdm_1_1eDirich.html#43c547a2507e233706f92712d8c2aacc" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordtype">double</span> gamma =sum(<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>); <span class="keywordflow">return</span> elem_mult ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>, ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>+1 ) ) / ( gamma* ( gamma+1 ) );} |
229 | | <a name="l00257"></a><a class="code" href="classbdm_1_1eDirich.html#e09a24938e80c3d94b0ee842d1552318">00257</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#e09a24938e80c3d94b0ee842d1552318" title="In this instance, val is ...">evallog_nn</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const</span> |
230 | | <a name="l00258"></a>00258 <span class="keyword"> </span>{ |
231 | | <a name="l00259"></a>00259 <span class="keywordtype">double</span> tmp; tmp= ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>-1 ) *log ( val ); it_assert_debug ( std::isfinite ( tmp ),<span class="stringliteral">"Infinite value"</span> ); |
232 | | <a name="l00260"></a>00260 <span class="keywordflow">return</span> tmp; |
233 | | <a name="l00261"></a>00261 }; |
234 | | <a name="l00262"></a><a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2">00262</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a> ()<span class="keyword"> const</span> |
235 | | <a name="l00263"></a>00263 <span class="keyword"> </span>{ |
236 | | <a name="l00264"></a>00264 <span class="keywordtype">double</span> tmp; |
237 | | <a name="l00265"></a>00265 <span class="keywordtype">double</span> gam=sum ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> ); |
238 | | <a name="l00266"></a>00266 <span class="keywordtype">double</span> lgb=0.0; |
239 | | <a name="l00267"></a>00267 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length();i++ ) {lgb+=lgamma ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> ( i ) );} |
240 | | <a name="l00268"></a>00268 tmp= lgb-lgamma ( gam ); |
241 | | <a name="l00269"></a>00269 it_assert_debug ( std::isfinite ( tmp ),<span class="stringliteral">"Infinite value"</span> ); |
242 | | <a name="l00270"></a>00270 <span class="keywordflow">return</span> tmp; |
243 | | <a name="l00271"></a>00271 }; |
244 | | <a name="l00273"></a><a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324">00273</a> vec& <a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324" title="access function">_beta</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>;} |
245 | | <a name="l00275"></a>00275 }; |
246 | | <a name="l00276"></a>00276 |
247 | | <a name="l00278"></a><a class="code" href="classbdm_1_1multiBM.html">00278</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> |
248 | | <a name="l00279"></a>00279 { |
249 | | <a name="l00280"></a>00280 <span class="keyword">protected</span>: |
250 | | <a name="l00282"></a><a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a">00282</a> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>; |
251 | | <a name="l00284"></a><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25">00284</a> vec &<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>; |
252 | | <a name="l00285"></a>00285 <span class="keyword">public</span>: |
253 | | <a name="l00287"></a><a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf">00287</a> <a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf" title="Default constructor.">multiBM</a> ( ) : <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> ( ),<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ( ),<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> ( <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>._beta() ) |
254 | | <a name="l00288"></a>00288 { |
255 | | <a name="l00289"></a>00289 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>.length() >0 ) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
256 | | <a name="l00290"></a>00290 <span class="keywordflow">else</span>{<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=0.0;} |
257 | | <a name="l00291"></a>00291 } |
258 | | <a name="l00293"></a><a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31">00293</a> <a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31" title="Copy constructor.">multiBM</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a> &B ) : <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> ( B ),<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ( B.<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ),<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> ( <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>._beta() ) {} |
259 | | <a name="l00295"></a><a class="code" href="classbdm_1_1multiBM.html#dbe6b90d410dc062a233d1dc09eeba52">00295</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#dbe6b90d410dc062a233d1dc09eeba52" title="Sets sufficient statistics to match that of givefrom mB0.">set_statistics</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a>* mB0 ) {<span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>* mB=<span class="keyword">dynamic_cast<</span><span class="keyword">const </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>*<span class="keyword">></span> ( mB0 ); <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>=mB-><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>;} |
260 | | <a name="l00296"></a><a class="code" href="classbdm_1_1multiBM.html#1e4bf41b61937fd80f34049742e23f95">00296</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#1e4bf41b61937fd80f34049742e23f95" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &dt ) |
261 | | <a name="l00297"></a>00297 { |
262 | | <a name="l00298"></a>00298 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a><1.0 ) {<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>*=<a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>;<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
263 | | <a name="l00299"></a>00299 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>+=dt; |
264 | | <a name="l00300"></a>00300 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {<a class="code" href="classbdm_1_1BM.html#4064b6559d962633e4372b12f4cd204a" title="Logarithm of marginalized data likelihood.">ll</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>()-<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
265 | | <a name="l00301"></a>00301 } |
266 | | <a name="l00302"></a><a class="code" href="classbdm_1_1multiBM.html#e157b607c1e3fa91d42aeea44458e2bf">00302</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1multiBM.html#e157b607c1e3fa91d42aeea44458e2bf">logpred</a> ( <span class="keyword">const</span> vec &dt )<span class="keyword"> const</span> |
267 | | <a name="l00303"></a>00303 <span class="keyword"> </span>{ |
268 | | <a name="l00304"></a>00304 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> pred ( <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ); |
269 | | <a name="l00305"></a>00305 vec &<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> = pred.<a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324" title="access function">_beta</a>(); |
270 | | <a name="l00306"></a>00306 |
271 | | <a name="l00307"></a>00307 <span class="keywordtype">double</span> lll; |
272 | | <a name="l00308"></a>00308 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a><1.0 ) |
273 | | <a name="l00309"></a>00309 {beta*=<a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>;lll=pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
274 | | <a name="l00310"></a>00310 <span class="keywordflow">else</span> |
275 | | <a name="l00311"></a>00311 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {lll=<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
276 | | <a name="l00312"></a>00312 <span class="keywordflow">else</span>{lll=pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
277 | | <a name="l00313"></a>00313 |
278 | | <a name="l00314"></a>00314 beta+=dt; |
279 | | <a name="l00315"></a>00315 <span class="keywordflow">return</span> pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>()-lll; |
280 | | <a name="l00316"></a>00316 } |
281 | | <a name="l00317"></a><a class="code" href="classbdm_1_1multiBM.html#aaeb18c989088feb8d26d300e4971732">00317</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#aaeb18c989088feb8d26d300e4971732" title="Flatten the posterior according to the given BMEF (of the same type!).">flatten</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* B ) |
282 | | <a name="l00318"></a>00318 { |
283 | | <a name="l00319"></a>00319 <span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>* E=<span class="keyword">dynamic_cast<</span><span class="keyword">const </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>*<span class="keyword">></span> ( B ); |
284 | | <a name="l00320"></a>00320 <span class="comment">// sum(beta) should be equal to sum(B.beta)</span> |
285 | | <a name="l00321"></a>00321 <span class="keyword">const</span> vec &Eb=E-><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>;<span class="comment">//const_cast<multiBM*> ( E )->_beta();</span> |
286 | | <a name="l00322"></a>00322 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>*= ( sum ( Eb ) /sum ( <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> ) ); |
287 | | <a name="l00323"></a>00323 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
288 | | <a name="l00324"></a>00324 } |
289 | | <a name="l00325"></a>00325 <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>& posterior()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>;}; |
290 | | <a name="l00326"></a>00326 <span class="keyword">const</span> eDirich* _e()<span class="keyword"> const </span>{<span class="keywordflow">return</span> &<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>;}; |
291 | | <a name="l00327"></a>00327 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &beta0 ) |
292 | | <a name="l00328"></a>00328 { |
293 | | <a name="l00329"></a>00329 <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.set_parameters ( beta0 ); |
294 | | <a name="l00330"></a>00330 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.lognc();} |
295 | | <a name="l00331"></a>00331 } |
296 | | <a name="l00332"></a>00332 }; |
297 | | <a name="l00333"></a>00333 |
298 | | <a name="l00343"></a><a class="code" href="classbdm_1_1egamma.html">00343</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
299 | | <a name="l00344"></a>00344 { |
300 | | <a name="l00345"></a>00345 <span class="keyword">protected</span>: |
301 | | <a name="l00347"></a><a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa">00347</a> vec <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>; |
302 | | <a name="l00349"></a><a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1">00349</a> vec <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>; |
303 | | <a name="l00350"></a>00350 <span class="keyword">public</span> : |
304 | | <a name="l00353"></a>00353 <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> ( ) :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( ), <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> ( 0 ), <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a> ( 0 ) {}; |
305 | | <a name="l00354"></a>00354 <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> ( <span class="keyword">const</span> vec &a, <span class="keyword">const</span> vec &b ) {set_parameters ( a, b );}; |
306 | | <a name="l00355"></a>00355 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &a, <span class="keyword">const</span> vec &b ) {<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>=a,<a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>=b;<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length();}; |
307 | | <a name="l00357"></a>00357 |
308 | | <a name="l00358"></a>00358 vec <a class="code" href="classbdm_1_1egamma.html#6ed82f0fd05f6002487256d8e75a0bbd" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
309 | | <a name="l00360"></a>00360 <span class="comment">// mat sample ( int N ) const;</span> |
310 | | <a name="l00361"></a>00361 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#a8e11e5a580ff42a1b205974c60768c6" title="TODO: is it used anywhere?">evallog</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
311 | | <a name="l00362"></a>00362 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#9a66cbd100e8520c769ccb3c451f86f8" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
312 | | <a name="l00364"></a><a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed">00364</a> vec& <a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed" title="Returns poiter to alpha and beta. Potentially dengerous: use with care!">_alpha</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>;} |
313 | | <a name="l00365"></a>00365 vec& _beta() {<span class="keywordflow">return</span> beta;} |
314 | | <a name="l00366"></a><a class="code" href="classbdm_1_1egamma.html#49d256c42cce14c6faa56ec242b57e85">00366</a> vec <a class="code" href="classbdm_1_1egamma.html#49d256c42cce14c6faa56ec242b57e85" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div ( <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>,beta );} |
315 | | <a name="l00367"></a><a class="code" href="classbdm_1_1egamma.html#36986cc01917cd0796fadc17125bdec1">00367</a> vec <a class="code" href="classbdm_1_1egamma.html#36986cc01917cd0796fadc17125bdec1" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div ( <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>,elem_mult ( beta,beta ) ); } |
316 | | <a name="l00368"></a>00368 }; |
317 | | <a name="l00369"></a>00369 |
318 | | <a name="l00386"></a><a class="code" href="classbdm_1_1eigamma.html">00386</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> |
319 | | <a name="l00387"></a>00387 { |
320 | | <a name="l00388"></a>00388 <span class="keyword">protected</span>: |
321 | | <a name="l00389"></a>00389 <span class="keyword">public</span> : |
322 | | <a name="l00394"></a>00394 |
323 | | <a name="l00395"></a><a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f">00395</a> vec <a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 1.0/<a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f" title="Returns a sample, from density .">egamma::sample</a>();}; |
324 | | <a name="l00397"></a><a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb">00397</a> vec <a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb" title="Returns poiter to alpha and beta. Potentially dangerous: use with care!">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div ( <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>,<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>-1 );} |
325 | | <a name="l00398"></a><a class="code" href="classbdm_1_1eigamma.html#c2c696f8c668e9f65392c9449f6a5133">00398</a> vec <a class="code" href="classbdm_1_1eigamma.html#c2c696f8c668e9f65392c9449f6a5133" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{vec mea=<a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb" title="Returns poiter to alpha and beta. Potentially dangerous: use with care!">mean</a>(); <span class="keywordflow">return</span> elem_div ( elem_mult ( mea,mea ),<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>-2 );} |
326 | | <a name="l00399"></a>00399 }; |
327 | | <a name="l00400"></a>00400 <span class="comment">/*</span> |
328 | | <a name="l00402"></a>00402 <span class="comment"> class emix : public epdf {</span> |
329 | | <a name="l00403"></a>00403 <span class="comment"> protected:</span> |
330 | | <a name="l00404"></a>00404 <span class="comment"> int n;</span> |
331 | | <a name="l00405"></a>00405 <span class="comment"> vec &w;</span> |
332 | | <a name="l00406"></a>00406 <span class="comment"> Array<epdf*> Coms;</span> |
333 | | <a name="l00407"></a>00407 <span class="comment"> public:</span> |
334 | | <a name="l00409"></a>00409 <span class="comment"> emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {};</span> |
335 | | <a name="l00410"></a>00410 <span class="comment"> void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;}</span> |
336 | | <a name="l00411"></a>00411 <span class="comment"> vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;};</span> |
337 | | <a name="l00412"></a>00412 <span class="comment"> vec sample() {it_error ( "Not implemented" );return 0;}</span> |
338 | | <a name="l00413"></a>00413 <span class="comment"> };</span> |
339 | | <a name="l00414"></a>00414 <span class="comment"> */</span> |
340 | | <a name="l00415"></a>00415 |
341 | | <a name="l00417"></a>00417 |
342 | | <a name="l00418"></a><a class="code" href="classbdm_1_1euni.html">00418</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> |
343 | | <a name="l00419"></a>00419 { |
344 | | <a name="l00420"></a>00420 <span class="keyword">protected</span>: |
345 | | <a name="l00422"></a><a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32">00422</a> vec <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>; |
346 | | <a name="l00424"></a><a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1">00424</a> vec <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>; |
347 | | <a name="l00426"></a><a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c">00426</a> vec <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>; |
348 | | <a name="l00428"></a><a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20">00428</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>; |
349 | | <a name="l00430"></a><a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476">00430</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
350 | | <a name="l00431"></a>00431 <span class="keyword">public</span>: |
351 | | <a name="l00434"></a>00434 <a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</a> ( ) :<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ) {} |
352 | | <a name="l00435"></a>00435 <a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</a> ( <span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0 ) {set_parameters ( low0,high0 );} |
353 | | <a name="l00436"></a>00436 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0 ) |
354 | | <a name="l00437"></a>00437 { |
355 | | <a name="l00438"></a>00438 <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> = high0-low0; |
356 | | <a name="l00439"></a>00439 it_assert_debug ( min ( <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> ) >0.0,<span class="stringliteral">"bad support"</span> ); |
357 | | <a name="l00440"></a>00440 <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> = low0; |
358 | | <a name="l00441"></a>00441 <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a> = high0; |
359 | | <a name="l00442"></a>00442 <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a> = prod ( 1.0/<a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> ); |
360 | | <a name="l00443"></a>00443 <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a> = log ( <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a> ); |
361 | | <a name="l00444"></a>00444 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>.length(); |
362 | | <a name="l00445"></a>00445 } |
363 | | <a name="l00447"></a>00447 |
364 | | <a name="l00448"></a>00448 <span class="keywordtype">double</span> eval ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>;} |
365 | | <a name="l00449"></a><a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81">00449</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81" title="Compute log-probability of argument val.">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>;} |
366 | | <a name="l00450"></a><a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194">00450</a> vec <a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const</span> |
367 | | <a name="l00451"></a>00451 <span class="keyword"> </span>{ |
368 | | <a name="l00452"></a>00452 vec smp ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
369 | | <a name="l00453"></a>00453 <span class="preprocessor">#pragma omp critical</span> |
370 | | <a name="l00454"></a>00454 <span class="preprocessor"></span> UniRNG.sample_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ,smp ); |
371 | | <a name="l00455"></a>00455 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>+elem_mult ( <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>,smp ); |
372 | | <a name="l00456"></a>00456 } |
373 | | <a name="l00458"></a><a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226">00458</a> vec <a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226" title="set values of low and high ">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> ( <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>-<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> ) /2.0;} |
374 | | <a name="l00459"></a><a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c">00459</a> vec <a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> ( pow ( <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>,2 ) +pow ( <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>,2 ) +elem_mult ( <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>,<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> ) ) /3.0;} |
375 | | <a name="l00460"></a>00460 }; |
376 | | <a name="l00461"></a>00461 |
| 139 | <a name="l00127"></a>00127 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#61bd470764020bea6e1ed35000f259e6" title="This method arrange instance properties according the data stored in the Setting...">from_setting</a>(<span class="keyword">const</span> Setting &root); |
| 140 | <a name="l00129"></a>00129 |
| 141 | <a name="l00132"></a>00132 |
| 142 | <a name="l00134"></a>00134 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2" title="dupdate in exponential form (not really handy)">dupdate</a> ( mat &v,<span class="keywordtype">double</span> nu=1.0 ); |
| 143 | <a name="l00135"></a>00135 |
| 144 | <a name="l00136"></a>00136 vec <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
| 145 | <a name="l00137"></a>00137 mat <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">sample</a> ( <span class="keywordtype">int</span> N ) <span class="keyword">const</span>; |
| 146 | <a name="l00138"></a>00138 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3" title="Evaluate normalized log-probability.">evallog_nn</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
| 147 | <a name="l00139"></a>00139 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
| 148 | <a name="l00140"></a><a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600">00140</a> vec <a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>;} |
| 149 | <a name="l00141"></a><a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773">00141</a> vec <a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> diag ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.to_mat() );} |
| 150 | <a name="l00142"></a>00142 <span class="comment">// mlnorm<sq_T>* condition ( const RV &rvn ) const ; <=========== fails to cmpile. Why?</span> |
| 151 | <a name="l00143"></a>00143 <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a>* <a class="code" href="classbdm_1_1enorm.html#baea4d49c657342b58297d68cda16d26" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">condition</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn ) <span class="keyword">const</span> ; |
| 152 | <a name="l00144"></a>00144 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* <a class="code" href="classbdm_1_1enorm.html#c2996bdaffad38fbe0fc776db54c9d80" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ) <span class="keyword">const</span>; |
| 153 | <a name="l00145"></a>00145 <span class="comment">// epdf* marginal ( const RV &rv ) const;</span> |
| 154 | <a name="l00147"></a>00147 <span class="comment"></span> |
| 155 | <a name="l00150"></a>00150 |
| 156 | <a name="l00151"></a>00151 vec& _mu() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>;} |
| 157 | <a name="l00152"></a>00152 <span class="keywordtype">void</span> set_mu ( <span class="keyword">const</span> vec mu0 ) { <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>=mu0;} |
| 158 | <a name="l00153"></a>00153 sq_T& _R() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>;} |
| 159 | <a name="l00154"></a>00154 <span class="keyword">const</span> sq_T& _R()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>;} |
| 160 | <a name="l00156"></a>00156 |
| 161 | <a name="l00157"></a>00157 }; |
| 162 | <a name="l00158"></a>00158 |
| 163 | <a name="l00165"></a><a class="code" href="classbdm_1_1egiw.html">00165</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1egiw.html" title="Gauss-inverse-Wishart density stored in LD form.">egiw</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
| 164 | <a name="l00166"></a>00166 { |
| 165 | <a name="l00167"></a>00167 <span class="keyword">protected</span>: |
| 166 | <a name="l00169"></a><a class="code" href="classbdm_1_1egiw.html#ae56852845c6af176fd9017dbebbbd52">00169</a> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1egiw.html#ae56852845c6af176fd9017dbebbbd52" title="Extended information matrix of sufficient statistics.">V</a>; |
| 167 | <a name="l00171"></a><a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4">00171</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>; |
| 168 | <a name="l00173"></a><a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a">00173</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>; |
| 169 | <a name="l00175"></a><a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd">00175</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a>; |
| 170 | <a name="l00176"></a>00176 <span class="keyword">public</span>: |
| 171 | <a name="l00179"></a>00179 <a class="code" href="classbdm_1_1egiw.html" title="Gauss-inverse-Wishart density stored in LD form.">egiw</a>() :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a>() {}; |
| 172 | <a name="l00180"></a>00180 <a class="code" href="classbdm_1_1egiw.html" title="Gauss-inverse-Wishart density stored in LD form.">egiw</a> ( <span class="keywordtype">int</span> dimx0, <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> V0, <span class="keywordtype">double</span> nu0=-1.0 ) :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a>() {set_parameters ( dimx0,V0, nu0 );}; |
| 173 | <a name="l00181"></a>00181 |
| 174 | <a name="l00182"></a>00182 <span class="keywordtype">void</span> set_parameters ( <span class="keywordtype">int</span> dimx0, <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> V0, <span class="keywordtype">double</span> nu0=-1.0 ) |
| 175 | <a name="l00183"></a>00183 { |
| 176 | <a name="l00184"></a>00184 <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>=dimx0; |
| 177 | <a name="l00185"></a>00185 <a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> = V0.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>()-<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>; |
| 178 | <a name="l00186"></a>00186 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>* ( <a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a>+<a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> ); <span class="comment">// size(R) + size(Theta)</span> |
| 179 | <a name="l00187"></a>00187 |
| 180 | <a name="l00188"></a>00188 <a class="code" href="classbdm_1_1egiw.html#ae56852845c6af176fd9017dbebbbd52" title="Extended information matrix of sufficient statistics.">V</a>=V0; |
| 181 | <a name="l00189"></a>00189 <span class="keywordflow">if</span> ( nu0<0 ) |
| 182 | <a name="l00190"></a>00190 { |
| 183 | <a name="l00191"></a>00191 <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a> = 0.1 +<a class="code" href="classbdm_1_1egiw.html#322414c32d9a21a006a5aab0311f64fd" title="Dimension of the regressor.">nPsi</a> +2*<a class="code" href="classbdm_1_1egiw.html#23e4d78bea7e98840f3da30e76a2b57a" title="Dimension of the output.">dimx</a> +2; <span class="comment">// +2 assures finite expected value of R</span> |
| 184 | <a name="l00192"></a>00192 <span class="comment">// terms before that are sufficient for finite normalization</span> |
| 185 | <a name="l00193"></a>00193 } |
| 186 | <a name="l00194"></a>00194 <span class="keywordflow">else</span> |
| 187 | <a name="l00195"></a>00195 { |
| 188 | <a name="l00196"></a>00196 <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>=nu0; |
| 189 | <a name="l00197"></a>00197 } |
| 190 | <a name="l00198"></a>00198 } |
| 191 | <a name="l00200"></a>00200 |
| 192 | <a name="l00201"></a>00201 vec <a class="code" href="classbdm_1_1egiw.html#920f21548b7a3723923dd108fe514c61" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
| 193 | <a name="l00202"></a>00202 vec <a class="code" href="classbdm_1_1egiw.html#df70c05f918c3a6f86d60f10c1fd6ba2" title="return expected value">mean</a>() <span class="keyword">const</span>; |
| 194 | <a name="l00203"></a>00203 vec <a class="code" href="classbdm_1_1egiw.html#c1ecc406613cc2341225dc10c3d3b46a" title="return expected variance (not covariance!)">variance</a>() <span class="keyword">const</span>; |
| 195 | <a name="l00204"></a>00204 |
| 196 | <a name="l00206"></a>00206 vec <a class="code" href="classbdm_1_1egiw.html#66d2ba9295c306012b309efcc9e516f0" title="LS estimate of .">est_theta</a>() <span class="keyword">const</span>; |
| 197 | <a name="l00207"></a>00207 |
| 198 | <a name="l00209"></a>00209 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1egiw.html#88c321a2051d1afdbb31a098896a717b" title="Covariance of the LS estimate.">est_theta_cov</a>() <span class="keyword">const</span>; |
| 199 | <a name="l00210"></a>00210 |
| 200 | <a name="l00211"></a>00211 <span class="keywordtype">void</span> mean_mat ( mat &M, mat&R ) <span class="keyword">const</span>; |
| 201 | <a name="l00213"></a>00213 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#bfb8e7c619b34ad804a73bff71742b5e" title="In this instance, val= [theta, r]. For multivariate instances, it is stored columnwise...">evallog_nn</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
| 202 | <a name="l00214"></a>00214 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egiw.html#41d72ba7b2abc8a9a4209ffa98ed5633" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
| 203 | <a name="l00215"></a><a class="code" href="classbdm_1_1egiw.html#8e610e95401a11baf34f65e16ecd87be">00215</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egiw.html#8e610e95401a11baf34f65e16ecd87be" title="Power of the density, used e.g. to flatten the density.">pow</a> ( <span class="keywordtype">double</span> p ) {V*=p;<a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>*=p;}; |
| 204 | <a name="l00216"></a>00216 |
| 205 | <a name="l00219"></a>00219 |
| 206 | <a name="l00220"></a>00220 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& _V() {<span class="keywordflow">return</span> V;} |
| 207 | <a name="l00221"></a>00221 <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& _V()<span class="keyword"> const </span>{<span class="keywordflow">return</span> V;} |
| 208 | <a name="l00222"></a>00222 <span class="keywordtype">double</span>& _nu() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>;} |
| 209 | <a name="l00223"></a>00223 <span class="keyword">const</span> <span class="keywordtype">double</span>& _nu()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egiw.html#447eacf19d4f4083872686f044814dc4" title="Number of data records (degrees of freedom) of sufficient statistics.">nu</a>;} |
| 210 | <a name="l00225"></a>00225 }; |
| 211 | <a name="l00226"></a>00226 |
| 212 | <a name="l00235"></a><a class="code" href="classbdm_1_1eDirich.html">00235</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
| 213 | <a name="l00236"></a>00236 { |
| 214 | <a name="l00237"></a>00237 <span class="keyword">protected</span>: |
| 215 | <a name="l00239"></a><a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2">00239</a> vec <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>; |
| 216 | <a name="l00240"></a>00240 <span class="keyword">public</span>: |
| 217 | <a name="l00243"></a>00243 |
| 218 | <a name="l00244"></a>00244 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> () : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( ) {}; |
| 219 | <a name="l00245"></a>00245 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> &D0 ) : <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> () {set_parameters ( D0.<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> );}; |
| 220 | <a name="l00246"></a>00246 eDirich ( <span class="keyword">const</span> vec &beta0 ) {set_parameters ( beta0 );}; |
| 221 | <a name="l00247"></a>00247 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &beta0 ) |
| 222 | <a name="l00248"></a>00248 { |
| 223 | <a name="l00249"></a>00249 <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>= beta0; |
| 224 | <a name="l00250"></a>00250 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length(); |
| 225 | <a name="l00251"></a>00251 } |
| 226 | <a name="l00253"></a>00253 |
| 227 | <a name="l00254"></a><a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc">00254</a> vec <a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> vec_1 ( 0.0 );}; |
| 228 | <a name="l00255"></a><a class="code" href="classbdm_1_1eDirich.html#cb343355ec791298bb5a3404cd482fb6">00255</a> vec <a class="code" href="classbdm_1_1eDirich.html#cb343355ec791298bb5a3404cd482fb6" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>/sum(<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>);}; |
| 229 | <a name="l00256"></a><a class="code" href="classbdm_1_1eDirich.html#43c547a2507e233706f92712d8c2aacc">00256</a> vec <a class="code" href="classbdm_1_1eDirich.html#43c547a2507e233706f92712d8c2aacc" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordtype">double</span> gamma =sum(<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>); <span class="keywordflow">return</span> elem_mult ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>, ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>+1 ) ) / ( gamma* ( gamma+1 ) );} |
| 230 | <a name="l00258"></a><a class="code" href="classbdm_1_1eDirich.html#e09a24938e80c3d94b0ee842d1552318">00258</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#e09a24938e80c3d94b0ee842d1552318" title="In this instance, val is ...">evallog_nn</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const</span> |
| 231 | <a name="l00259"></a>00259 <span class="keyword"> </span>{ |
| 232 | <a name="l00260"></a>00260 <span class="keywordtype">double</span> tmp; tmp= ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>-1 ) *log ( val ); it_assert_debug ( std::isfinite ( tmp ),<span class="stringliteral">"Infinite value"</span> ); |
| 233 | <a name="l00261"></a>00261 <span class="keywordflow">return</span> tmp; |
| 234 | <a name="l00262"></a>00262 }; |
| 235 | <a name="l00263"></a><a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2">00263</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a> ()<span class="keyword"> const</span> |
| 236 | <a name="l00264"></a>00264 <span class="keyword"> </span>{ |
| 237 | <a name="l00265"></a>00265 <span class="keywordtype">double</span> tmp; |
| 238 | <a name="l00266"></a>00266 <span class="keywordtype">double</span> gam=sum ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> ); |
| 239 | <a name="l00267"></a>00267 <span class="keywordtype">double</span> lgb=0.0; |
| 240 | <a name="l00268"></a>00268 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length();i++ ) {lgb+=lgamma ( <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> ( i ) );} |
| 241 | <a name="l00269"></a>00269 tmp= lgb-lgamma ( gam ); |
| 242 | <a name="l00270"></a>00270 it_assert_debug ( std::isfinite ( tmp ),<span class="stringliteral">"Infinite value"</span> ); |
| 243 | <a name="l00271"></a>00271 <span class="keywordflow">return</span> tmp; |
| 244 | <a name="l00272"></a>00272 }; |
| 245 | <a name="l00274"></a><a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324">00274</a> vec& <a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324" title="access function">_beta</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>;} |
| 246 | <a name="l00276"></a>00276 }; |
| 247 | <a name="l00277"></a>00277 |
| 248 | <a name="l00279"></a><a class="code" href="classbdm_1_1multiBM.html">00279</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> |
| 249 | <a name="l00280"></a>00280 { |
| 250 | <a name="l00281"></a>00281 <span class="keyword">protected</span>: |
| 251 | <a name="l00283"></a><a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a">00283</a> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>; |
| 252 | <a name="l00285"></a><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25">00285</a> vec &<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>; |
| 253 | <a name="l00286"></a>00286 <span class="keyword">public</span>: |
| 254 | <a name="l00288"></a><a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf">00288</a> <a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf" title="Default constructor.">multiBM</a> ( ) : <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> ( ),<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ( ),<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> ( <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>._beta() ) |
| 255 | <a name="l00289"></a>00289 { |
| 256 | <a name="l00290"></a>00290 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>.length() >0 ) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
| 257 | <a name="l00291"></a>00291 <span class="keywordflow">else</span>{<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=0.0;} |
| 258 | <a name="l00292"></a>00292 } |
| 259 | <a name="l00294"></a><a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31">00294</a> <a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31" title="Copy constructor.">multiBM</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a> &B ) : <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a> ( B ),<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ( B.<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ),<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> ( <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>._beta() ) {} |
| 260 | <a name="l00296"></a><a class="code" href="classbdm_1_1multiBM.html#dbe6b90d410dc062a233d1dc09eeba52">00296</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#dbe6b90d410dc062a233d1dc09eeba52" title="Sets sufficient statistics to match that of givefrom mB0.">set_statistics</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a>* mB0 ) {<span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>* mB=<span class="keyword">dynamic_cast<</span><span class="keyword">const </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>*<span class="keyword">></span> ( mB0 ); <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>=mB-><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>;} |
| 261 | <a name="l00297"></a><a class="code" href="classbdm_1_1multiBM.html#1e4bf41b61937fd80f34049742e23f95">00297</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#1e4bf41b61937fd80f34049742e23f95" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &dt ) |
| 262 | <a name="l00298"></a>00298 { |
| 263 | <a name="l00299"></a>00299 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a><1.0 ) {<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>*=<a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>;<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
| 264 | <a name="l00300"></a>00300 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>+=dt; |
| 265 | <a name="l00301"></a>00301 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {<a class="code" href="classbdm_1_1BM.html#4064b6559d962633e4372b12f4cd204a" title="Logarithm of marginalized data likelihood.">ll</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>()-<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
| 266 | <a name="l00302"></a>00302 } |
| 267 | <a name="l00303"></a><a class="code" href="classbdm_1_1multiBM.html#e157b607c1e3fa91d42aeea44458e2bf">00303</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1multiBM.html#e157b607c1e3fa91d42aeea44458e2bf">logpred</a> ( <span class="keyword">const</span> vec &dt )<span class="keyword"> const</span> |
| 268 | <a name="l00304"></a>00304 <span class="keyword"> </span>{ |
| 269 | <a name="l00305"></a>00305 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> pred ( <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> ); |
| 270 | <a name="l00306"></a>00306 vec &<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> = pred.<a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324" title="access function">_beta</a>(); |
| 271 | <a name="l00307"></a>00307 |
| 272 | <a name="l00308"></a>00308 <span class="keywordtype">double</span> lll; |
| 273 | <a name="l00309"></a>00309 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a><1.0 ) |
| 274 | <a name="l00310"></a>00310 {beta*=<a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>;lll=pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
| 275 | <a name="l00311"></a>00311 <span class="keywordflow">else</span> |
| 276 | <a name="l00312"></a>00312 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {lll=<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
| 277 | <a name="l00313"></a>00313 <span class="keywordflow">else</span>{lll=pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
| 278 | <a name="l00314"></a>00314 |
| 279 | <a name="l00315"></a>00315 beta+=dt; |
| 280 | <a name="l00316"></a>00316 <span class="keywordflow">return</span> pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>()-lll; |
| 281 | <a name="l00317"></a>00317 } |
| 282 | <a name="l00318"></a><a class="code" href="classbdm_1_1multiBM.html#aaeb18c989088feb8d26d300e4971732">00318</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#aaeb18c989088feb8d26d300e4971732" title="Flatten the posterior according to the given BMEF (of the same type!).">flatten</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* B ) |
| 283 | <a name="l00319"></a>00319 { |
| 284 | <a name="l00320"></a>00320 <span class="keyword">const</span> <a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>* E=<span class="keyword">dynamic_cast<</span><span class="keyword">const </span><a class="code" href="classbdm_1_1multiBM.html" title="Estimator for Multinomial density.">multiBM</a>*<span class="keyword">></span> ( B ); |
| 285 | <a name="l00321"></a>00321 <span class="comment">// sum(beta) should be equal to sum(B.beta)</span> |
| 286 | <a name="l00322"></a>00322 <span class="keyword">const</span> vec &Eb=E-><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>;<span class="comment">//const_cast<multiBM*> ( E )->_beta();</span> |
| 287 | <a name="l00323"></a>00323 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>*= ( sum ( Eb ) /sum ( <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> ) ); |
| 288 | <a name="l00324"></a>00324 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
| 289 | <a name="l00325"></a>00325 } |
| 290 | <a name="l00326"></a>00326 <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>& posterior()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>;}; |
| 291 | <a name="l00327"></a>00327 <span class="keyword">const</span> eDirich* _e()<span class="keyword"> const </span>{<span class="keywordflow">return</span> &<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>;}; |
| 292 | <a name="l00328"></a>00328 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &beta0 ) |
| 293 | <a name="l00329"></a>00329 { |
| 294 | <a name="l00330"></a>00330 <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.set_parameters ( beta0 ); |
| 295 | <a name="l00331"></a>00331 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> ) {<a class="code" href="classbdm_1_1BMEF.html#06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>=<a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.lognc();} |
| 296 | <a name="l00332"></a>00332 } |
| 297 | <a name="l00333"></a>00333 }; |
| 298 | <a name="l00334"></a>00334 |
| 299 | <a name="l00344"></a><a class="code" href="classbdm_1_1egamma.html">00344</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> |
| 300 | <a name="l00345"></a>00345 { |
| 301 | <a name="l00346"></a>00346 <span class="keyword">protected</span>: |
| 302 | <a name="l00348"></a><a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa">00348</a> vec <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>; |
| 303 | <a name="l00350"></a><a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1">00350</a> vec <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>; |
| 304 | <a name="l00351"></a>00351 <span class="keyword">public</span> : |
| 305 | <a name="l00354"></a>00354 <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> ( ) :<a class="code" href="classbdm_1_1eEF.html" title="General conjugate exponential family posterior density.">eEF</a> ( ), <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> ( 0 ), <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a> ( 0 ) {}; |
| 306 | <a name="l00355"></a>00355 <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> ( <span class="keyword">const</span> vec &a, <span class="keyword">const</span> vec &b ) {set_parameters ( a, b );}; |
| 307 | <a name="l00356"></a>00356 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &a, <span class="keyword">const</span> vec &b ) {<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>=a,<a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>=b;<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length();}; |
| 308 | <a name="l00358"></a>00358 |
| 309 | <a name="l00359"></a>00359 vec <a class="code" href="classbdm_1_1egamma.html#6ed82f0fd05f6002487256d8e75a0bbd" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
| 310 | <a name="l00361"></a>00361 <span class="comment">// mat sample ( int N ) const;</span> |
| 311 | <a name="l00362"></a>00362 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#a8e11e5a580ff42a1b205974c60768c6" title="TODO: is it used anywhere?">evallog</a> ( <span class="keyword">const</span> vec &val ) <span class="keyword">const</span>; |
| 312 | <a name="l00363"></a>00363 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#9a66cbd100e8520c769ccb3c451f86f8" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
| 313 | <a name="l00365"></a><a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed">00365</a> vec& <a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed" title="Returns poiter to alpha and beta. Potentially dengerous: use with care!">_alpha</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>;} |
| 314 | <a name="l00366"></a>00366 vec& _beta() {<span class="keywordflow">return</span> beta;} |
| 315 | <a name="l00367"></a><a class="code" href="classbdm_1_1egamma.html#49d256c42cce14c6faa56ec242b57e85">00367</a> vec <a class="code" href="classbdm_1_1egamma.html#49d256c42cce14c6faa56ec242b57e85" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div ( <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>,beta );} |
| 316 | <a name="l00368"></a><a class="code" href="classbdm_1_1egamma.html#36986cc01917cd0796fadc17125bdec1">00368</a> vec <a class="code" href="classbdm_1_1egamma.html#36986cc01917cd0796fadc17125bdec1" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div ( <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>,elem_mult ( beta,beta ) ); } |
| 317 | <a name="l00369"></a>00369 }; |
| 318 | <a name="l00370"></a>00370 |
| 319 | <a name="l00387"></a><a class="code" href="classbdm_1_1eigamma.html">00387</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> |
| 320 | <a name="l00388"></a>00388 { |
| 321 | <a name="l00389"></a>00389 <span class="keyword">protected</span>: |
| 322 | <a name="l00390"></a>00390 <span class="keyword">public</span> : |
| 323 | <a name="l00395"></a>00395 |
| 324 | <a name="l00396"></a><a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f">00396</a> vec <a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 1.0/<a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f" title="Returns a sample, from density .">egamma::sample</a>();}; |
| 325 | <a name="l00398"></a><a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb">00398</a> vec <a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb" title="Returns poiter to alpha and beta. Potentially dangerous: use with care!">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> elem_div ( <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>,<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>-1 );} |
| 326 | <a name="l00399"></a><a class="code" href="classbdm_1_1eigamma.html#c2c696f8c668e9f65392c9449f6a5133">00399</a> vec <a class="code" href="classbdm_1_1eigamma.html#c2c696f8c668e9f65392c9449f6a5133" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{vec mea=<a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb" title="Returns poiter to alpha and beta. Potentially dangerous: use with care!">mean</a>(); <span class="keywordflow">return</span> elem_div ( elem_mult ( mea,mea ),<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>-2 );} |
| 327 | <a name="l00400"></a>00400 }; |
| 328 | <a name="l00401"></a>00401 <span class="comment">/*</span> |
| 329 | <a name="l00403"></a>00403 <span class="comment"> class emix : public epdf {</span> |
| 330 | <a name="l00404"></a>00404 <span class="comment"> protected:</span> |
| 331 | <a name="l00405"></a>00405 <span class="comment"> int n;</span> |
| 332 | <a name="l00406"></a>00406 <span class="comment"> vec &w;</span> |
| 333 | <a name="l00407"></a>00407 <span class="comment"> Array<epdf*> Coms;</span> |
| 334 | <a name="l00408"></a>00408 <span class="comment"> public:</span> |
| 335 | <a name="l00410"></a>00410 <span class="comment"> emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {};</span> |
| 336 | <a name="l00411"></a>00411 <span class="comment"> void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;}</span> |
| 337 | <a name="l00412"></a>00412 <span class="comment"> vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;};</span> |
| 338 | <a name="l00413"></a>00413 <span class="comment"> vec sample() {it_error ( "Not implemented" );return 0;}</span> |
| 339 | <a name="l00414"></a>00414 <span class="comment"> };</span> |
| 340 | <a name="l00415"></a>00415 <span class="comment"> */</span> |
| 341 | <a name="l00416"></a>00416 |
| 342 | <a name="l00418"></a>00418 |
| 343 | <a name="l00419"></a><a class="code" href="classbdm_1_1euni.html">00419</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> |
| 344 | <a name="l00420"></a>00420 { |
| 345 | <a name="l00421"></a>00421 <span class="keyword">protected</span>: |
| 346 | <a name="l00423"></a><a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32">00423</a> vec <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>; |
| 347 | <a name="l00425"></a><a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1">00425</a> vec <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>; |
| 348 | <a name="l00427"></a><a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c">00427</a> vec <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>; |
| 349 | <a name="l00429"></a><a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20">00429</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>; |
| 350 | <a name="l00431"></a><a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476">00431</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
| 351 | <a name="l00432"></a>00432 <span class="keyword">public</span>: |
| 352 | <a name="l00435"></a>00435 <a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</a> ( ) :<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ) {} |
| 353 | <a name="l00436"></a>00436 <a class="code" href="classbdm_1_1euni.html" title="Uniform distributed density on a rectangular support.">euni</a> ( <span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0 ) {set_parameters ( low0,high0 );} |
| 354 | <a name="l00437"></a>00437 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0 ) |
| 355 | <a name="l00438"></a>00438 { |
| 356 | <a name="l00439"></a>00439 <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> = high0-low0; |
| 357 | <a name="l00440"></a>00440 it_assert_debug ( min ( <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> ) >0.0,<span class="stringliteral">"bad support"</span> ); |
| 358 | <a name="l00441"></a>00441 <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> = low0; |
| 359 | <a name="l00442"></a>00442 <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a> = high0; |
| 360 | <a name="l00443"></a>00443 <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a> = prod ( 1.0/<a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> ); |
| 361 | <a name="l00444"></a>00444 <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a> = log ( <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a> ); |
| 362 | <a name="l00445"></a>00445 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>.length(); |
| 363 | <a name="l00446"></a>00446 } |
| 364 | <a name="l00448"></a>00448 |
| 365 | <a name="l00449"></a>00449 <span class="keywordtype">double</span> eval ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>;} |
| 366 | <a name="l00450"></a><a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81">00450</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81" title="Compute log-probability of argument val.">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>;} |
| 367 | <a name="l00451"></a><a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194">00451</a> vec <a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const</span> |
| 368 | <a name="l00452"></a>00452 <span class="keyword"> </span>{ |
| 369 | <a name="l00453"></a>00453 vec smp ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
| 370 | <a name="l00454"></a>00454 <span class="preprocessor">#pragma omp critical</span> |
| 371 | <a name="l00455"></a>00455 <span class="preprocessor"></span> UniRNG.sample_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ,smp ); |
| 372 | <a name="l00456"></a>00456 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>+elem_mult ( <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>,smp ); |
| 373 | <a name="l00457"></a>00457 } |
| 374 | <a name="l00459"></a><a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226">00459</a> vec <a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226" title="set values of low and high ">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> ( <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>-<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> ) /2.0;} |
| 375 | <a name="l00460"></a><a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c">00460</a> vec <a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> ( pow ( <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>,2 ) +pow ( <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>,2 ) +elem_mult ( <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>,<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> ) ) /3.0;} |
| 376 | <a name="l00461"></a>00461 }; |
448 | | <a name="l00585"></a><a class="code" href="classbdm_1_1mlstudent.html">00585</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlstudent.html">mlstudent</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a><ldmat> |
449 | | <a name="l00586"></a>00586 { |
450 | | <a name="l00587"></a>00587 <span class="keyword">protected</span>: |
451 | | <a name="l00588"></a>00588 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> Lambda; |
452 | | <a name="l00589"></a>00589 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &<a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a>; |
453 | | <a name="l00590"></a>00590 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> Re; |
454 | | <a name="l00591"></a>00591 <span class="keyword">public</span>: |
455 | | <a name="l00592"></a>00592 <a class="code" href="classbdm_1_1mlstudent.html">mlstudent</a> ( ) :<a class="code" href="classbdm_1_1mlnorm.html">mlnorm<ldmat></a> (), |
456 | | <a name="l00593"></a>00593 Lambda (), <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._R() ) {} |
457 | | <a name="l00594"></a>00594 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &R0, <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& Lambda0 ) |
458 | | <a name="l00595"></a>00595 { |
459 | | <a name="l00596"></a>00596 it_assert_debug ( A0.rows() ==mu0.length(),<span class="stringliteral">""</span> ); |
460 | | <a name="l00597"></a>00597 it_assert_debug ( R0.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>() ==A0.rows(),<span class="stringliteral">""</span> ); |
461 | | <a name="l00598"></a>00598 |
462 | | <a name="l00599"></a>00599 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( mu0,Lambda ); <span class="comment">//</span> |
463 | | <a name="l00600"></a>00600 A = A0; |
464 | | <a name="l00601"></a>00601 mu_const = mu0; |
465 | | <a name="l00602"></a>00602 Re=R0; |
466 | | <a name="l00603"></a>00603 Lambda = Lambda0; |
467 | | <a name="l00604"></a>00604 } |
468 | | <a name="l00605"></a><a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">00605</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">condition</a> ( <span class="keyword">const</span> vec &cond ) |
469 | | <a name="l00606"></a>00606 { |
470 | | <a name="l00607"></a>00607 _mu = A*cond + mu_const; |
471 | | <a name="l00608"></a>00608 <span class="keywordtype">double</span> zeta; |
472 | | <a name="l00609"></a>00609 <span class="comment">//ugly hack!</span> |
473 | | <a name="l00610"></a>00610 <span class="keywordflow">if</span> ( ( cond.length() +1 ) ==Lambda.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>() ) |
474 | | <a name="l00611"></a>00611 { |
475 | | <a name="l00612"></a>00612 zeta = Lambda.<a class="code" href="classldmat.html#d876c5f83e02b3e809b35c9de5068f14" title="Evaluates quadratic form ;.">invqform</a> ( concat ( cond, vec_1 ( 1.0 ) ) ); |
476 | | <a name="l00613"></a>00613 } |
477 | | <a name="l00614"></a>00614 <span class="keywordflow">else</span> |
478 | | <a name="l00615"></a>00615 { |
479 | | <a name="l00616"></a>00616 zeta = Lambda.<a class="code" href="classldmat.html#d876c5f83e02b3e809b35c9de5068f14" title="Evaluates quadratic form ;.">invqform</a> ( cond ); |
480 | | <a name="l00617"></a>00617 } |
481 | | <a name="l00618"></a>00618 <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a> = Re; |
482 | | <a name="l00619"></a>00619 <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a>*= ( 1+zeta );<span class="comment">// / ( nu ); << nu is in Re!!!!!!</span> |
483 | | <a name="l00620"></a>00620 }; |
484 | | <a name="l00621"></a>00621 |
485 | | <a name="l00622"></a>00622 }; |
486 | | <a name="l00632"></a><a class="code" href="classbdm_1_1mgamma.html">00632</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgamma.html" title="Gamma random walk.">mgamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> |
487 | | <a name="l00633"></a>00633 { |
488 | | <a name="l00634"></a>00634 <span class="keyword">protected</span>: |
489 | | <a name="l00636"></a><a class="code" href="classbdm_1_1mgamma.html#bdc9f1e9e03c09e91103fee269864438">00636</a> <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
490 | | <a name="l00638"></a><a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09">00638</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>; |
491 | | <a name="l00640"></a><a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312">00640</a> vec &<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>; |
492 | | <a name="l00641"></a>00641 |
493 | | <a name="l00642"></a>00642 <span class="keyword">public</span>: |
494 | | <a name="l00644"></a><a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1">00644</a> <a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1" title="Constructor.">mgamma</a> ( ) : <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> ( ), <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> (), <a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
495 | | <a name="l00646"></a>00646 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#a0f21c2557b233a85838b497d040ab14" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, <span class="keyword">const</span> vec &beta0 ); |
496 | | <a name="l00647"></a><a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff">00647</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) {<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>=<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>/val;}; |
497 | | <a name="l00648"></a>00648 }; |
498 | | <a name="l00649"></a>00649 |
499 | | <a name="l00659"></a><a class="code" href="classbdm_1_1migamma.html">00659</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> |
500 | | <a name="l00660"></a>00660 { |
501 | | <a name="l00661"></a>00661 <span class="keyword">protected</span>: |
502 | | <a name="l00663"></a><a class="code" href="classbdm_1_1migamma.html#a31b39d4179551b593c9e0d7d756783a">00663</a> <a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
503 | | <a name="l00665"></a><a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c">00665</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>; |
504 | | <a name="l00667"></a><a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc">00667</a> vec &<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>; |
505 | | <a name="l00669"></a><a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5">00669</a> vec &<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>; |
506 | | <a name="l00670"></a>00670 |
507 | | <a name="l00671"></a>00671 <span class="keyword">public</span>: |
508 | | <a name="l00674"></a>00674 <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> ( ) : <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> (), <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ), <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>() ), <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
509 | | <a name="l00675"></a>00675 <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> &m ) : <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> (), <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( m.<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ), <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>() ), <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
510 | | <a name="l00677"></a>00677 |
511 | | <a name="l00679"></a><a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151">00679</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">int</span> len, <span class="keywordtype">double</span> k0 ) |
512 | | <a name="l00680"></a>00680 { |
513 | | <a name="l00681"></a>00681 <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>=k0; |
514 | | <a name="l00682"></a>00682 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( ( 1.0/ ( <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>*<a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a> ) +2.0 ) *ones ( len ) <span class="comment">/*alpha*/</span>, ones ( len ) <span class="comment">/*beta*/</span> ); |
515 | | <a name="l00683"></a>00683 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
516 | | <a name="l00684"></a>00684 }; |
517 | | <a name="l00685"></a><a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c">00685</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) |
518 | | <a name="l00686"></a>00686 { |
519 | | <a name="l00687"></a>00687 <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>=elem_mult ( val, ( <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>-1.0 ) ); |
520 | | <a name="l00688"></a>00688 }; |
521 | | <a name="l00689"></a>00689 }; |
522 | | <a name="l00690"></a>00690 |
| 448 | <a name="l00578"></a>00578 |
| 449 | <a name="l00586"></a><a class="code" href="classbdm_1_1mlstudent.html">00586</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlstudent.html">mlstudent</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a><ldmat> |
| 450 | <a name="l00587"></a>00587 { |
| 451 | <a name="l00588"></a>00588 <span class="keyword">protected</span>: |
| 452 | <a name="l00589"></a>00589 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> Lambda; |
| 453 | <a name="l00590"></a>00590 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &<a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a>; |
| 454 | <a name="l00591"></a>00591 <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> Re; |
| 455 | <a name="l00592"></a>00592 <span class="keyword">public</span>: |
| 456 | <a name="l00593"></a>00593 <a class="code" href="classbdm_1_1mlstudent.html">mlstudent</a> ( ) :<a class="code" href="classbdm_1_1mlnorm.html">mlnorm<ldmat></a> (), |
| 457 | <a name="l00594"></a>00594 Lambda (), <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>._R() ) {} |
| 458 | <a name="l00595"></a>00595 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &R0, <span class="keyword">const</span> <a class="code" href="classldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& Lambda0 ) |
| 459 | <a name="l00596"></a>00596 { |
| 460 | <a name="l00597"></a>00597 it_assert_debug ( A0.rows() ==mu0.length(),<span class="stringliteral">""</span> ); |
| 461 | <a name="l00598"></a>00598 it_assert_debug ( R0.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>() ==A0.rows(),<span class="stringliteral">""</span> ); |
| 462 | <a name="l00599"></a>00599 |
| 463 | <a name="l00600"></a>00600 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( mu0,Lambda ); <span class="comment">//</span> |
| 464 | <a name="l00601"></a>00601 A = A0; |
| 465 | <a name="l00602"></a>00602 mu_const = mu0; |
| 466 | <a name="l00603"></a>00603 Re=R0; |
| 467 | <a name="l00604"></a>00604 Lambda = Lambda0; |
| 468 | <a name="l00605"></a>00605 } |
| 469 | <a name="l00606"></a><a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">00606</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">condition</a> ( <span class="keyword">const</span> vec &cond ) |
| 470 | <a name="l00607"></a>00607 { |
| 471 | <a name="l00608"></a>00608 _mu = A*cond + mu_const; |
| 472 | <a name="l00609"></a>00609 <span class="keywordtype">double</span> zeta; |
| 473 | <a name="l00610"></a>00610 <span class="comment">//ugly hack!</span> |
| 474 | <a name="l00611"></a>00611 <span class="keywordflow">if</span> ( ( cond.length() +1 ) ==Lambda.<a class="code" href="group__math.html#g96dfb21865db4f5bd36fa70f9b0b1163" title="access function">rows</a>() ) |
| 475 | <a name="l00612"></a>00612 { |
| 476 | <a name="l00613"></a>00613 zeta = Lambda.<a class="code" href="classldmat.html#d876c5f83e02b3e809b35c9de5068f14" title="Evaluates quadratic form ;.">invqform</a> ( concat ( cond, vec_1 ( 1.0 ) ) ); |
| 477 | <a name="l00614"></a>00614 } |
| 478 | <a name="l00615"></a>00615 <span class="keywordflow">else</span> |
| 479 | <a name="l00616"></a>00616 { |
| 480 | <a name="l00617"></a>00617 zeta = Lambda.<a class="code" href="classldmat.html#d876c5f83e02b3e809b35c9de5068f14" title="Evaluates quadratic form ;.">invqform</a> ( cond ); |
| 481 | <a name="l00618"></a>00618 } |
| 482 | <a name="l00619"></a>00619 <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a> = Re; |
| 483 | <a name="l00620"></a>00620 <a class="code" href="classbdm_1_1mlnorm.html#78120ecd1c2b1d7e80124b4603504604" title="access function">_R</a>*= ( 1+zeta );<span class="comment">// / ( nu ); << nu is in Re!!!!!!</span> |
| 484 | <a name="l00621"></a>00621 }; |
| 485 | <a name="l00622"></a>00622 |
| 486 | <a name="l00623"></a>00623 }; |
| 487 | <a name="l00633"></a><a class="code" href="classbdm_1_1mgamma.html">00633</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgamma.html" title="Gamma random walk.">mgamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> |
| 488 | <a name="l00634"></a>00634 { |
| 489 | <a name="l00635"></a>00635 <span class="keyword">protected</span>: |
| 490 | <a name="l00637"></a><a class="code" href="classbdm_1_1mgamma.html#bdc9f1e9e03c09e91103fee269864438">00637</a> <a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
| 491 | <a name="l00639"></a><a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09">00639</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>; |
| 492 | <a name="l00641"></a><a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312">00641</a> vec &<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>; |
| 493 | <a name="l00642"></a>00642 |
| 494 | <a name="l00643"></a>00643 <span class="keyword">public</span>: |
| 495 | <a name="l00645"></a><a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1">00645</a> <a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1" title="Constructor.">mgamma</a> ( ) : <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> ( ), <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> (), <a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
| 496 | <a name="l00647"></a>00647 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#a0f21c2557b233a85838b497d040ab14" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, <span class="keyword">const</span> vec &beta0 ); |
| 497 | <a name="l00648"></a><a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff">00648</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) {<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of epdf.beta">_beta</a>=<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>/val;}; |
| 498 | <a name="l00649"></a>00649 }; |
| 499 | <a name="l00650"></a>00650 |
| 500 | <a name="l00660"></a><a class="code" href="classbdm_1_1migamma.html">00660</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> |
| 501 | <a name="l00661"></a>00661 { |
| 502 | <a name="l00662"></a>00662 <span class="keyword">protected</span>: |
| 503 | <a name="l00664"></a><a class="code" href="classbdm_1_1migamma.html#a31b39d4179551b593c9e0d7d756783a">00664</a> <a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>; |
| 504 | <a name="l00666"></a><a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c">00666</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>; |
| 505 | <a name="l00668"></a><a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc">00668</a> vec &<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>; |
| 506 | <a name="l00670"></a><a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5">00670</a> vec &<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>; |
| 507 | <a name="l00671"></a>00671 |
| 508 | <a name="l00672"></a>00672 <span class="keyword">public</span>: |
| 509 | <a name="l00675"></a>00675 <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> ( ) : <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> (), <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ), <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>() ), <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
| 510 | <a name="l00676"></a>00676 <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a> &m ) : <a class="code" href="classbdm_1_1mEF.html" title="Exponential family model.">mEF</a> (), <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( m.<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ), <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>() ), <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a> ( <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>;}; |
| 511 | <a name="l00678"></a>00678 |
| 512 | <a name="l00680"></a><a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151">00680</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">int</span> len, <span class="keywordtype">double</span> k0 ) |
| 513 | <a name="l00681"></a>00681 { |
| 514 | <a name="l00682"></a>00682 <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>=k0; |
| 515 | <a name="l00683"></a>00683 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( ( 1.0/ ( <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>*<a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a> ) +2.0 ) *ones ( len ) <span class="comment">/*alpha*/</span>, ones ( len ) <span class="comment">/*beta*/</span> ); |
| 516 | <a name="l00684"></a>00684 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
| 517 | <a name="l00685"></a>00685 }; |
| 518 | <a name="l00686"></a><a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c">00686</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) |
| 519 | <a name="l00687"></a>00687 { |
| 520 | <a name="l00688"></a>00688 <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of epdf.beta">_beta</a>=elem_mult ( val, ( <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of epdf.alpha">_alpha</a>-1.0 ) ); |
| 521 | <a name="l00689"></a>00689 }; |
| 522 | <a name="l00690"></a>00690 }; |
569 | | <a name="l00788"></a>00788 UIREGISTER(migamma_ref); |
570 | | <a name="l00789"></a>00789 |
571 | | <a name="l00799"></a><a class="code" href="classbdm_1_1elognorm.html">00799</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1elognorm.html">elognorm</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a><ldmat> |
572 | | <a name="l00800"></a>00800 { |
573 | | <a name="l00801"></a>00801 <span class="keyword">public</span>: |
574 | | <a name="l00802"></a><a class="code" href="classbdm_1_1elognorm.html#8b948e2bce1253765a2542199913aaba">00802</a> vec <a class="code" href="classbdm_1_1elognorm.html#8b948e2bce1253765a2542199913aaba" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> exp ( <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<ldmat>::sample</a>() );}; |
575 | | <a name="l00803"></a><a class="code" href="classbdm_1_1elognorm.html#adb41e4f4d6600dec6f8c1dbc5ed9eea">00803</a> vec <a class="code" href="classbdm_1_1elognorm.html#adb41e4f4d6600dec6f8c1dbc5ed9eea" title="return expected value">mean</a>()<span class="keyword"> const </span>{vec var=<a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773" title="return expected variance (not covariance!)">enorm<ldmat>::variance</a>();<span class="keywordflow">return</span> exp ( <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> - 0.5*var );}; |
576 | | <a name="l00804"></a>00804 |
577 | | <a name="l00805"></a>00805 }; |
578 | | <a name="l00806"></a>00806 |
579 | | <a name="l00818"></a><a class="code" href="classbdm_1_1mlognorm.html">00818</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlognorm.html" title="Log-Normal random walk.">mlognorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> |
580 | | <a name="l00819"></a>00819 { |
581 | | <a name="l00820"></a>00820 <span class="keyword">protected</span>: |
582 | | <a name="l00821"></a>00821 <a class="code" href="classbdm_1_1elognorm.html">elognorm</a> eno; |
583 | | <a name="l00823"></a><a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a">00823</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>; |
584 | | <a name="l00825"></a><a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2">00825</a> vec &<a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a>; |
585 | | <a name="l00826"></a>00826 <span class="keyword">public</span>: |
586 | | <a name="l00828"></a><a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41">00828</a> <a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41" title="Constructor.">mlognorm</a> ( ) : eno (), <a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a> ( eno._mu() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&eno;}; |
587 | | <a name="l00830"></a><a class="code" href="classbdm_1_1mlognorm.html#604cab0e8a76f9041dc3c606043bb39f">00830</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#604cab0e8a76f9041dc3c606043bb39f" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">int</span> size, <span class="keywordtype">double</span> k ) |
588 | | <a name="l00831"></a>00831 { |
589 | | <a name="l00832"></a>00832 <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a> = 0.5*log ( k*k+1 ); |
590 | | <a name="l00833"></a>00833 eno.<a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> ( zeros ( size ),2*<a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>*eye ( size ) ); |
591 | | <a name="l00834"></a>00834 |
592 | | <a name="l00835"></a>00835 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = size; |
593 | | <a name="l00836"></a>00836 }; |
594 | | <a name="l00837"></a>00837 |
595 | | <a name="l00838"></a><a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e">00838</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) |
596 | | <a name="l00839"></a>00839 { |
597 | | <a name="l00840"></a>00840 <a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a>=log ( val )-<a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>;<span class="comment">//elem_mult ( refl,pow ( val,l ) );</span> |
598 | | <a name="l00841"></a>00841 }; |
599 | | <a name="l00842"></a>00842 |
600 | | <a name="l00861"></a>00861 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#3a130457942be64ee9544e8dff00d09b">from_setting</a>( <span class="keyword">const</span> Setting &root ); |
601 | | <a name="l00862"></a>00862 |
602 | | <a name="l00863"></a>00863 <span class="comment">// TODO dodelat void to_setting( Setting &root ) const;</span> |
603 | | <a name="l00864"></a>00864 |
604 | | <a name="l00865"></a>00865 }; |
605 | | <a name="l00866"></a>00866 |
606 | | <a name="l00867"></a>00867 UIREGISTER(mlognorm); |
607 | | <a name="l00868"></a>00868 |
608 | | <a name="l00872"></a><a class="code" href="classbdm_1_1eWishartCh.html">00872</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eWishartCh.html">eWishartCh</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> |
609 | | <a name="l00873"></a>00873 { |
610 | | <a name="l00874"></a>00874 <span class="keyword">protected</span>: |
611 | | <a name="l00876"></a><a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490">00876</a> <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>; |
612 | | <a name="l00878"></a><a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f">00878</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>; |
613 | | <a name="l00880"></a><a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3">00880</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a>; |
614 | | <a name="l00881"></a>00881 <span class="keyword">public</span>: |
615 | | <a name="l00882"></a>00882 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> mat &Y0, <span class="keyword">const</span> <span class="keywordtype">double</span> delta0 ) {<a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>=<a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> ( Y0 );<a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a>=delta0; <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>=<a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classsqmat.html#071e80ced9cc3b8cbb360fa7462eb646" title="Reimplementing common functions of mat: cols().">rows</a>(); <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>*<a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>; } |
616 | | <a name="l00883"></a>00883 mat sample_mat()<span class="keyword"> const</span> |
617 | | <a name="l00884"></a>00884 <span class="keyword"> </span>{ |
618 | | <a name="l00885"></a>00885 mat X=zeros ( <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>,<a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a> ); |
619 | | <a name="l00886"></a>00886 |
620 | | <a name="l00887"></a>00887 <span class="comment">//sample diagonal</span> |
621 | | <a name="l00888"></a>00888 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>;i++ ) |
622 | | <a name="l00889"></a>00889 { |
623 | | <a name="l00890"></a>00890 GamRNG.setup ( 0.5* ( <a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a>-i ) , 0.5 ); <span class="comment">// no +1 !! index if from 0</span> |
624 | | <a name="l00891"></a>00891 <span class="preprocessor">#pragma omp critical</span> |
625 | | <a name="l00892"></a>00892 <span class="preprocessor"></span> X ( i,i ) =sqrt ( GamRNG() ); |
626 | | <a name="l00893"></a>00893 } |
627 | | <a name="l00894"></a>00894 <span class="comment">//do the rest</span> |
628 | | <a name="l00895"></a>00895 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<p;i++ ) |
629 | | <a name="l00896"></a>00896 { |
630 | | <a name="l00897"></a>00897 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> j=i+1;j<p;j++ ) |
631 | | <a name="l00898"></a>00898 { |
632 | | <a name="l00899"></a>00899 <span class="preprocessor">#pragma omp critical</span> |
633 | | <a name="l00900"></a>00900 <span class="preprocessor"></span> X ( i,j ) =NorRNG.sample(); |
634 | | <a name="l00901"></a>00901 } |
635 | | <a name="l00902"></a>00902 } |
636 | | <a name="l00903"></a>00903 <span class="keywordflow">return</span> X*<a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classchmat.html#9c50d31c999d85d8e9d8cf2b69b6ac8c" title="Access function.">_Ch</a>();<span class="comment">// return upper triangular part of the decomposition</span> |
637 | | <a name="l00904"></a>00904 } |
638 | | <a name="l00905"></a><a class="code" href="classbdm_1_1eWishartCh.html#8f2154b8b5be8f4c5788f261b6d57b9a">00905</a> vec <a class="code" href="classbdm_1_1eWishartCh.html#8f2154b8b5be8f4c5788f261b6d57b9a" title="Returns a sample, from density .">sample</a> ()<span class="keyword"> const</span> |
639 | | <a name="l00906"></a>00906 <span class="keyword"> </span>{ |
640 | | <a name="l00907"></a>00907 <span class="keywordflow">return</span> vec ( sample_mat()._data(),p*p ); |
641 | | <a name="l00908"></a>00908 } |
642 | | <a name="l00910"></a><a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981">00910</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981" title="fast access function y0 will be copied into Y.Ch.">setY</a> ( <span class="keyword">const</span> mat &Ch0 ) {copy_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,Ch0._data(), <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classchmat.html#9c50d31c999d85d8e9d8cf2b69b6ac8c" title="Access function.">_Ch</a>()._data() );} |
643 | | <a name="l00912"></a><a class="code" href="classbdm_1_1eWishartCh.html#7eac414ec10b85aa5536b0092c57bc4a">00912</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#7eac414ec10b85aa5536b0092c57bc4a" title="fast access function y0 will be copied into Y.Ch.">_setY</a> ( <span class="keyword">const</span> vec &ch0 ) {copy_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, ch0._data(), <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classchmat.html#9c50d31c999d85d8e9d8cf2b69b6ac8c" title="Access function.">_Ch</a>()._data() ); } |
644 | | <a name="l00914"></a><a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e">00914</a> <span class="keyword">const</span> <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a>& <a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e" title="access function">getY</a>()<span class="keyword">const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>;} |
645 | | <a name="l00915"></a>00915 }; |
646 | | <a name="l00916"></a>00916 |
647 | | <a name="l00917"></a>00917 <span class="keyword">class </span>eiWishartCh: <span class="keyword">public</span> epdf |
648 | | <a name="l00918"></a>00918 { |
649 | | <a name="l00919"></a>00919 <span class="keyword">protected</span>: |
650 | | <a name="l00920"></a>00920 eWishartCh W; |
651 | | <a name="l00921"></a>00921 <span class="keywordtype">int</span> p; |
652 | | <a name="l00922"></a>00922 <span class="keywordtype">double</span> delta; |
653 | | <a name="l00923"></a>00923 <span class="keyword">public</span>: |
654 | | <a name="l00924"></a>00924 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> mat &Y0, <span class="keyword">const</span> <span class="keywordtype">double</span> delta0) { |
655 | | <a name="l00925"></a>00925 delta = delta0; |
656 | | <a name="l00926"></a>00926 W.set_parameters ( inv ( Y0 ),delta0 ); |
657 | | <a name="l00927"></a>00927 dim = W.dimension(); p=Y0.rows(); |
658 | | <a name="l00928"></a>00928 } |
659 | | <a name="l00929"></a>00929 vec sample()<span class="keyword"> const </span>{mat iCh; iCh=inv ( W.sample_mat() ); <span class="keywordflow">return</span> vec ( iCh._data(),<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> );} |
660 | | <a name="l00930"></a>00930 <span class="keywordtype">void</span> _setY ( <span class="keyword">const</span> vec &y0 ) |
661 | | <a name="l00931"></a>00931 { |
662 | | <a name="l00932"></a>00932 mat Ch ( p,p ); |
663 | | <a name="l00933"></a>00933 mat iCh ( p,p ); |
664 | | <a name="l00934"></a>00934 copy_vector ( dim, y0._data(), Ch._data() ); |
665 | | <a name="l00935"></a>00935 |
666 | | <a name="l00936"></a>00936 iCh=inv ( Ch ); |
667 | | <a name="l00937"></a>00937 W.setY ( iCh ); |
668 | | <a name="l00938"></a>00938 } |
669 | | <a name="l00939"></a>00939 <span class="keyword">virtual</span> <span class="keywordtype">double</span> evallog ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
670 | | <a name="l00940"></a>00940 <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> X(p); |
671 | | <a name="l00941"></a>00941 <span class="keyword">const</span> <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a>& Y=W.getY(); |
672 | | <a name="l00942"></a>00942 |
673 | | <a name="l00943"></a>00943 copy_vector(p*p,val._data(),X._Ch()._data()); |
674 | | <a name="l00944"></a>00944 <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> iX(p);X.inv(iX); |
675 | | <a name="l00945"></a>00945 <span class="comment">// compute </span> |
676 | | <a name="l00946"></a>00946 <span class="comment">// \frac{ |\Psi|^{m/2}|X|^{-(m+p+1)/2}e^{-tr(\Psi X^{-1})/2} }{ 2^{mp/2}\Gamma_p(m/2)},</span> |
677 | | <a name="l00947"></a>00947 mat M=Y.<a class="code" href="classchmat.html#045addd685f8d978efda232d7dcb070e" title="Conversion to full matrix.">to_mat</a>()*iX.to_mat(); |
678 | | <a name="l00948"></a>00948 |
679 | | <a name="l00949"></a>00949 <span class="keywordtype">double</span> log1 = 0.5*p*(2*Y.<a class="code" href="classchmat.html#b504ca818203b13e667cb3c503980382" title="Logarithm of a determinant.">logdet</a>())-0.5*(delta+p+1)*(2*X.logdet())-0.5*trace(M); |
680 | | <a name="l00950"></a>00950 <span class="comment">//Fixme! Multivariate gamma omitted!! it is ok for sampling, but not otherwise!!</span> |
681 | | <a name="l00951"></a>00951 |
682 | | <a name="l00952"></a>00952 <span class="comment">/* if (0) {</span> |
683 | | <a name="l00953"></a>00953 <span class="comment"> mat XX=X.to_mat();</span> |
684 | | <a name="l00954"></a>00954 <span class="comment"> mat YY=Y.to_mat();</span> |
685 | | <a name="l00955"></a>00955 <span class="comment"> </span> |
686 | | <a name="l00956"></a>00956 <span class="comment"> double log2 = 0.5*p*log(det(YY))-0.5*(delta+p+1)*log(det(XX))-0.5*trace(YY*inv(XX)); </span> |
687 | | <a name="l00957"></a>00957 <span class="comment"> cout << log1 << "," << log2 << endl;</span> |
688 | | <a name="l00958"></a>00958 <span class="comment"> }*/</span> |
689 | | <a name="l00959"></a>00959 <span class="keywordflow">return</span> log1; |
690 | | <a name="l00960"></a>00960 }; |
691 | | <a name="l00961"></a>00961 |
692 | | <a name="l00962"></a>00962 }; |
693 | | <a name="l00963"></a>00963 |
694 | | <a name="l00964"></a>00964 <span class="keyword">class </span>rwiWishartCh : <span class="keyword">public</span> mpdf |
695 | | <a name="l00965"></a>00965 { |
696 | | <a name="l00966"></a>00966 <span class="keyword">protected</span>: |
697 | | <a name="l00967"></a>00967 eiWishartCh eiW; |
698 | | <a name="l00969"></a>00969 <span class="keywordtype">double</span> sqd; |
699 | | <a name="l00970"></a>00970 <span class="comment">//reference point for diagonal</span> |
700 | | <a name="l00971"></a>00971 vec refl; |
701 | | <a name="l00972"></a>00972 <span class="keywordtype">double</span> l; |
702 | | <a name="l00973"></a>00973 <span class="keywordtype">int</span> p; |
703 | | <a name="l00974"></a>00974 <span class="keyword">public</span>: |
704 | | <a name="l00975"></a>00975 <span class="keywordtype">void</span> set_parameters ( <span class="keywordtype">int</span> p0, <span class="keywordtype">double</span> k, vec ref0, <span class="keywordtype">double</span> l0 ) |
705 | | <a name="l00976"></a>00976 { |
706 | | <a name="l00977"></a>00977 p=p0; |
707 | | <a name="l00978"></a>00978 <span class="keywordtype">double</span> delta = 2/(k*k)+p+3; |
708 | | <a name="l00979"></a>00979 sqd=sqrt ( delta-p-1 ); |
709 | | <a name="l00980"></a>00980 l=l0; |
710 | | <a name="l00981"></a>00981 refl=pow(ref0,1-l); |
711 | | <a name="l00982"></a>00982 |
712 | | <a name="l00983"></a>00983 eiW.set_parameters ( eye ( p ),delta ); |
713 | | <a name="l00984"></a>00984 <a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&eiW; |
714 | | <a name="l00985"></a>00985 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a>=eiW.dimension(); |
715 | | <a name="l00986"></a>00986 } |
716 | | <a name="l00987"></a>00987 <span class="keywordtype">void</span> condition ( <span class="keyword">const</span> vec &c ) { |
717 | | <a name="l00988"></a>00988 vec z=c; |
718 | | <a name="l00989"></a>00989 <span class="keywordtype">int</span> ri=0; |
719 | | <a name="l00990"></a>00990 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i<p*p;i+=(p+1)){<span class="comment">//trace diagonal element</span> |
720 | | <a name="l00991"></a>00991 z(i) = pow(z(i),l)*refl(ri); |
721 | | <a name="l00992"></a>00992 ri++; |
722 | | <a name="l00993"></a>00993 } |
723 | | <a name="l00994"></a>00994 |
724 | | <a name="l00995"></a>00995 eiW._setY ( sqd*z ); |
725 | | <a name="l00996"></a>00996 } |
726 | | <a name="l00997"></a>00997 }; |
727 | | <a name="l00998"></a>00998 |
728 | | <a name="l01000"></a>01000 <span class="keyword">enum</span> RESAMPLING_METHOD { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; |
729 | | <a name="l01006"></a><a class="code" href="classbdm_1_1eEmp.html">01006</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> |
730 | | <a name="l01007"></a>01007 { |
731 | | <a name="l01008"></a>01008 <span class="keyword">protected</span> : |
732 | | <a name="l01010"></a><a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031">01010</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>; |
733 | | <a name="l01012"></a><a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d">01012</a> vec <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>; |
734 | | <a name="l01014"></a><a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3">01014</a> Array<vec> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>; |
735 | | <a name="l01015"></a>01015 <span class="keyword">public</span>: |
736 | | <a name="l01018"></a>01018 <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> ( ) :<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ),<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ( ),<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( ) {}; |
737 | | <a name="l01019"></a>01019 <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> &e ) : <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( e ), <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ( e.<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ), <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( e.<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ) {}; |
738 | | <a name="l01021"></a>01021 |
739 | | <a name="l01023"></a>01023 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#7cfd383180b486fe4526bdf0179350c0" title="Set samples and weights.">set_statistics</a> ( <span class="keyword">const</span> vec &w0, <span class="keyword">const</span> epdf* pdf0 ); |
740 | | <a name="l01025"></a><a class="code" href="classbdm_1_1eEmp.html#cef74aa5f87d10d440b9b1e8bc78c1e7">01025</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#cef74aa5f87d10d440b9b1e8bc78c1e7" title="Set samples and weights.">set_statistics</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* pdf0 , <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a> ) {<a class="code" href="classbdm_1_1eEmp.html#cef74aa5f87d10d440b9b1e8bc78c1e7" title="Set samples and weights.">set_statistics</a> ( ones ( n ) /n,pdf0 );}; |
741 | | <a name="l01027"></a>01027 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#b62d802b8ef39f7c4dcbeb366c90951a" title="Set sample.">set_samples</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* pdf0 ); |
742 | | <a name="l01029"></a><a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1">01029</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1" title="Set sample.">set_parameters</a> ( <span class="keywordtype">int</span> n0, <span class="keywordtype">bool</span> copy=<span class="keyword">true</span> ) {<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>=n0; <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>.set_size ( n0,copy );<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>.set_size ( n0,copy );}; |
743 | | <a name="l01031"></a><a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef">01031</a> vec& <a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>;}; |
744 | | <a name="l01033"></a><a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714">01033</a> <span class="keyword">const</span> vec& <a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714" title="Potentially dangerous, use with care.">_w</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>;}; |
745 | | <a name="l01035"></a><a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2">01035</a> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>;}; |
746 | | <a name="l01037"></a><a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2">01037</a> <span class="keyword">const</span> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2" title="access function">_samples</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>;}; |
747 | | <a name="l01039"></a>01039 ivec <a class="code" href="classbdm_1_1eEmp.html#f06ce255de5dbb2313f52ee51f82ba3d" title="Function performs resampling, i.e. removal of low-weight samples and duplication...">resample</a> ( RESAMPLING_METHOD method=SYSTEMATIC ); |
748 | | <a name="l01041"></a><a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270">01041</a> vec <a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270" title="inherited operation : NOT implemneted">sample</a>()<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> 0;} |
749 | | <a name="l01043"></a><a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09">01043</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09" title="inherited operation : NOT implemneted">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> 0.0;} |
750 | | <a name="l01044"></a><a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9">01044</a> vec <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>()<span class="keyword"> const</span> |
751 | | <a name="l01045"></a>01045 <span class="keyword"> </span>{ |
752 | | <a name="l01046"></a>01046 vec pom=zeros ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
753 | | <a name="l01047"></a>01047 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++ ) {pom+=<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) *<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ( i );} |
754 | | <a name="l01048"></a>01048 <span class="keywordflow">return</span> pom; |
755 | | <a name="l01049"></a>01049 } |
756 | | <a name="l01050"></a><a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87">01050</a> vec <a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const</span> |
757 | | <a name="l01051"></a>01051 <span class="keyword"> </span>{ |
758 | | <a name="l01052"></a>01052 vec pom=zeros ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
759 | | <a name="l01053"></a>01053 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++ ) {pom+=pow ( <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ),2 ) *<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ( i );} |
760 | | <a name="l01054"></a>01054 <span class="keywordflow">return</span> pom-pow ( <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>(),2 ); |
761 | | <a name="l01055"></a>01055 } |
762 | | <a name="l01057"></a><a class="code" href="classbdm_1_1eEmp.html#b1c9df656144edf79ba2d885613f661f">01057</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#b1c9df656144edf79ba2d885613f661f" title="For this class, qbounds are minimum and maximum value of the population!">qbounds</a> ( vec &lb, vec &ub, <span class="keywordtype">double</span> perc=0.95 )<span class="keyword"> const</span> |
763 | | <a name="l01058"></a>01058 <span class="keyword"> </span>{ |
764 | | <a name="l01059"></a>01059 <span class="comment">// lb in inf so than it will be pushed below;</span> |
765 | | <a name="l01060"></a>01060 lb.set_size ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
766 | | <a name="l01061"></a>01061 ub.set_size ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
767 | | <a name="l01062"></a>01062 lb = std::numeric_limits<double>::infinity(); |
768 | | <a name="l01063"></a>01063 ub = -std::numeric_limits<double>::infinity(); |
769 | | <a name="l01064"></a>01064 <span class="keywordtype">int</span> j; |
770 | | <a name="l01065"></a>01065 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++ ) |
771 | | <a name="l01066"></a>01066 { |
772 | | <a name="l01067"></a>01067 <span class="keywordflow">for</span> ( j=0;j<<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>; j++ ) |
773 | | <a name="l01068"></a>01068 { |
774 | | <a name="l01069"></a>01069 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j ) <lb ( j ) ) {lb ( j ) =<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j );} |
775 | | <a name="l01070"></a>01070 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j ) >ub ( j ) ) {ub ( j ) =<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j );} |
776 | | <a name="l01071"></a>01071 } |
777 | | <a name="l01072"></a>01072 } |
778 | | <a name="l01073"></a>01073 } |
779 | | <a name="l01074"></a>01074 }; |
780 | | <a name="l01075"></a>01075 |
781 | | <a name="l01076"></a>01076 |
| 569 | <a name="l00788"></a>00788 |
| 570 | <a name="l00789"></a>00789 UIREGISTER(migamma_ref); |
| 571 | <a name="l00790"></a>00790 |
| 572 | <a name="l00800"></a><a class="code" href="classbdm_1_1elognorm.html">00800</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1elognorm.html">elognorm</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a><ldmat> |
| 573 | <a name="l00801"></a>00801 { |
| 574 | <a name="l00802"></a>00802 <span class="keyword">public</span>: |
| 575 | <a name="l00803"></a><a class="code" href="classbdm_1_1elognorm.html#8b948e2bce1253765a2542199913aaba">00803</a> vec <a class="code" href="classbdm_1_1elognorm.html#8b948e2bce1253765a2542199913aaba" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> exp ( <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<ldmat>::sample</a>() );}; |
| 576 | <a name="l00804"></a><a class="code" href="classbdm_1_1elognorm.html#adb41e4f4d6600dec6f8c1dbc5ed9eea">00804</a> vec <a class="code" href="classbdm_1_1elognorm.html#adb41e4f4d6600dec6f8c1dbc5ed9eea" title="return expected value">mean</a>()<span class="keyword"> const </span>{vec var=<a class="code" href="classbdm_1_1enorm.html#729c75ef0fa8abae03d58ad1f81e6773" title="return expected variance (not covariance!)">enorm<ldmat>::variance</a>();<span class="keywordflow">return</span> exp ( <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> - 0.5*var );}; |
| 577 | <a name="l00805"></a>00805 |
| 578 | <a name="l00806"></a>00806 }; |
| 579 | <a name="l00807"></a>00807 |
| 580 | <a name="l00819"></a><a class="code" href="classbdm_1_1mlognorm.html">00819</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlognorm.html" title="Log-Normal random walk.">mlognorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> |
| 581 | <a name="l00820"></a>00820 { |
| 582 | <a name="l00821"></a>00821 <span class="keyword">protected</span>: |
| 583 | <a name="l00822"></a>00822 <a class="code" href="classbdm_1_1elognorm.html">elognorm</a> eno; |
| 584 | <a name="l00824"></a><a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a">00824</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>; |
| 585 | <a name="l00826"></a><a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2">00826</a> vec &<a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a>; |
| 586 | <a name="l00827"></a>00827 <span class="keyword">public</span>: |
| 587 | <a name="l00829"></a><a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41">00829</a> <a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41" title="Constructor.">mlognorm</a> ( ) : eno (), <a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a> ( eno._mu() ) {<a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&eno;}; |
| 588 | <a name="l00831"></a><a class="code" href="classbdm_1_1mlognorm.html#604cab0e8a76f9041dc3c606043bb39f">00831</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#604cab0e8a76f9041dc3c606043bb39f" title="Set value of k.">set_parameters</a> ( <span class="keywordtype">int</span> size, <span class="keywordtype">double</span> k ) |
| 589 | <a name="l00832"></a>00832 { |
| 590 | <a name="l00833"></a>00833 <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a> = 0.5*log ( k*k+1 ); |
| 591 | <a name="l00834"></a>00834 eno.<a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> ( zeros ( size ),2*<a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>*eye ( size ) ); |
| 592 | <a name="l00835"></a>00835 |
| 593 | <a name="l00836"></a>00836 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = size; |
| 594 | <a name="l00837"></a>00837 }; |
| 595 | <a name="l00838"></a>00838 |
| 596 | <a name="l00839"></a><a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e">00839</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e" title="Update ep so that it represents this mpdf conditioned on rvc = cond.">condition</a> ( <span class="keyword">const</span> vec &val ) |
| 597 | <a name="l00840"></a>00840 { |
| 598 | <a name="l00841"></a>00841 <a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a>=log ( val )-<a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>;<span class="comment">//elem_mult ( refl,pow ( val,l ) );</span> |
| 599 | <a name="l00842"></a>00842 }; |
| 600 | <a name="l00843"></a>00843 |
| 601 | <a name="l00862"></a>00862 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#3a130457942be64ee9544e8dff00d09b">from_setting</a>( <span class="keyword">const</span> Setting &root ); |
| 602 | <a name="l00863"></a>00863 |
| 603 | <a name="l00864"></a>00864 <span class="comment">// TODO dodelat void to_setting( Setting &root ) const;</span> |
| 604 | <a name="l00865"></a>00865 |
| 605 | <a name="l00866"></a>00866 }; |
| 606 | <a name="l00867"></a>00867 |
| 607 | <a name="l00868"></a>00868 UIREGISTER(mlognorm); |
| 608 | <a name="l00869"></a>00869 |
| 609 | <a name="l00873"></a><a class="code" href="classbdm_1_1eWishartCh.html">00873</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eWishartCh.html">eWishartCh</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> |
| 610 | <a name="l00874"></a>00874 { |
| 611 | <a name="l00875"></a>00875 <span class="keyword">protected</span>: |
| 612 | <a name="l00877"></a><a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490">00877</a> <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>; |
| 613 | <a name="l00879"></a><a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f">00879</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>; |
| 614 | <a name="l00881"></a><a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3">00881</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a>; |
| 615 | <a name="l00882"></a>00882 <span class="keyword">public</span>: |
| 616 | <a name="l00883"></a>00883 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> mat &Y0, <span class="keyword">const</span> <span class="keywordtype">double</span> delta0 ) {<a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>=<a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> ( Y0 );<a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a>=delta0; <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>=<a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classsqmat.html#071e80ced9cc3b8cbb360fa7462eb646" title="Reimplementing common functions of mat: cols().">rows</a>(); <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>*<a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>; } |
| 617 | <a name="l00884"></a>00884 mat sample_mat()<span class="keyword"> const</span> |
| 618 | <a name="l00885"></a>00885 <span class="keyword"> </span>{ |
| 619 | <a name="l00886"></a>00886 mat X=zeros ( <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>,<a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a> ); |
| 620 | <a name="l00887"></a>00887 |
| 621 | <a name="l00888"></a>00888 <span class="comment">//sample diagonal</span> |
| 622 | <a name="l00889"></a>00889 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>;i++ ) |
| 623 | <a name="l00890"></a>00890 { |
| 624 | <a name="l00891"></a>00891 GamRNG.setup ( 0.5* ( <a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a>-i ) , 0.5 ); <span class="comment">// no +1 !! index if from 0</span> |
| 625 | <a name="l00892"></a>00892 <span class="preprocessor">#pragma omp critical</span> |
| 626 | <a name="l00893"></a>00893 <span class="preprocessor"></span> X ( i,i ) =sqrt ( GamRNG() ); |
| 627 | <a name="l00894"></a>00894 } |
| 628 | <a name="l00895"></a>00895 <span class="comment">//do the rest</span> |
| 629 | <a name="l00896"></a>00896 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<p;i++ ) |
| 630 | <a name="l00897"></a>00897 { |
| 631 | <a name="l00898"></a>00898 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> j=i+1;j<p;j++ ) |
| 632 | <a name="l00899"></a>00899 { |
| 633 | <a name="l00900"></a>00900 <span class="preprocessor">#pragma omp critical</span> |
| 634 | <a name="l00901"></a>00901 <span class="preprocessor"></span> X ( i,j ) =NorRNG.sample(); |
| 635 | <a name="l00902"></a>00902 } |
| 636 | <a name="l00903"></a>00903 } |
| 637 | <a name="l00904"></a>00904 <span class="keywordflow">return</span> X*<a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classchmat.html#9c50d31c999d85d8e9d8cf2b69b6ac8c" title="Access function.">_Ch</a>();<span class="comment">// return upper triangular part of the decomposition</span> |
| 638 | <a name="l00905"></a>00905 } |
| 639 | <a name="l00906"></a><a class="code" href="classbdm_1_1eWishartCh.html#8f2154b8b5be8f4c5788f261b6d57b9a">00906</a> vec <a class="code" href="classbdm_1_1eWishartCh.html#8f2154b8b5be8f4c5788f261b6d57b9a" title="Returns a sample, from density .">sample</a> ()<span class="keyword"> const</span> |
| 640 | <a name="l00907"></a>00907 <span class="keyword"> </span>{ |
| 641 | <a name="l00908"></a>00908 <span class="keywordflow">return</span> vec ( sample_mat()._data(),p*p ); |
| 642 | <a name="l00909"></a>00909 } |
| 643 | <a name="l00911"></a><a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981">00911</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981" title="fast access function y0 will be copied into Y.Ch.">setY</a> ( <span class="keyword">const</span> mat &Ch0 ) {copy_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,Ch0._data(), <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classchmat.html#9c50d31c999d85d8e9d8cf2b69b6ac8c" title="Access function.">_Ch</a>()._data() );} |
| 644 | <a name="l00913"></a><a class="code" href="classbdm_1_1eWishartCh.html#7eac414ec10b85aa5536b0092c57bc4a">00913</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#7eac414ec10b85aa5536b0092c57bc4a" title="fast access function y0 will be copied into Y.Ch.">_setY</a> ( <span class="keyword">const</span> vec &ch0 ) {copy_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, ch0._data(), <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classchmat.html#9c50d31c999d85d8e9d8cf2b69b6ac8c" title="Access function.">_Ch</a>()._data() ); } |
| 645 | <a name="l00915"></a><a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e">00915</a> <span class="keyword">const</span> <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a>& <a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e" title="access function">getY</a>()<span class="keyword">const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>;} |
| 646 | <a name="l00916"></a>00916 }; |
| 647 | <a name="l00917"></a>00917 |
| 648 | <a name="l00918"></a>00918 <span class="keyword">class </span>eiWishartCh: <span class="keyword">public</span> epdf |
| 649 | <a name="l00919"></a>00919 { |
| 650 | <a name="l00920"></a>00920 <span class="keyword">protected</span>: |
| 651 | <a name="l00921"></a>00921 eWishartCh W; |
| 652 | <a name="l00922"></a>00922 <span class="keywordtype">int</span> p; |
| 653 | <a name="l00923"></a>00923 <span class="keywordtype">double</span> delta; |
| 654 | <a name="l00924"></a>00924 <span class="keyword">public</span>: |
| 655 | <a name="l00925"></a>00925 <span class="keywordtype">void</span> set_parameters ( <span class="keyword">const</span> mat &Y0, <span class="keyword">const</span> <span class="keywordtype">double</span> delta0) { |
| 656 | <a name="l00926"></a>00926 delta = delta0; |
| 657 | <a name="l00927"></a>00927 W.set_parameters ( inv ( Y0 ),delta0 ); |
| 658 | <a name="l00928"></a>00928 dim = W.dimension(); p=Y0.rows(); |
| 659 | <a name="l00929"></a>00929 } |
| 660 | <a name="l00930"></a>00930 vec sample()<span class="keyword"> const </span>{mat iCh; iCh=inv ( W.sample_mat() ); <span class="keywordflow">return</span> vec ( iCh._data(),<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> );} |
| 661 | <a name="l00931"></a>00931 <span class="keywordtype">void</span> _setY ( <span class="keyword">const</span> vec &y0 ) |
| 662 | <a name="l00932"></a>00932 { |
| 663 | <a name="l00933"></a>00933 mat Ch ( p,p ); |
| 664 | <a name="l00934"></a>00934 mat iCh ( p,p ); |
| 665 | <a name="l00935"></a>00935 copy_vector ( dim, y0._data(), Ch._data() ); |
| 666 | <a name="l00936"></a>00936 |
| 667 | <a name="l00937"></a>00937 iCh=inv ( Ch ); |
| 668 | <a name="l00938"></a>00938 W.setY ( iCh ); |
| 669 | <a name="l00939"></a>00939 } |
| 670 | <a name="l00940"></a>00940 <span class="keyword">virtual</span> <span class="keywordtype">double</span> evallog ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
| 671 | <a name="l00941"></a>00941 <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> X(p); |
| 672 | <a name="l00942"></a>00942 <span class="keyword">const</span> <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a>& Y=W.getY(); |
| 673 | <a name="l00943"></a>00943 |
| 674 | <a name="l00944"></a>00944 copy_vector(p*p,val._data(),X._Ch()._data()); |
| 675 | <a name="l00945"></a>00945 <a class="code" href="classchmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> iX(p);X.inv(iX); |
| 676 | <a name="l00946"></a>00946 <span class="comment">// compute </span> |
| 677 | <a name="l00947"></a>00947 <span class="comment">// \frac{ |\Psi|^{m/2}|X|^{-(m+p+1)/2}e^{-tr(\Psi X^{-1})/2} }{ 2^{mp/2}\Gamma_p(m/2)},</span> |
| 678 | <a name="l00948"></a>00948 mat M=Y.<a class="code" href="classchmat.html#045addd685f8d978efda232d7dcb070e" title="Conversion to full matrix.">to_mat</a>()*iX.to_mat(); |
| 679 | <a name="l00949"></a>00949 |
| 680 | <a name="l00950"></a>00950 <span class="keywordtype">double</span> log1 = 0.5*p*(2*Y.<a class="code" href="classchmat.html#b504ca818203b13e667cb3c503980382" title="Logarithm of a determinant.">logdet</a>())-0.5*(delta+p+1)*(2*X.logdet())-0.5*trace(M); |
| 681 | <a name="l00951"></a>00951 <span class="comment">//Fixme! Multivariate gamma omitted!! it is ok for sampling, but not otherwise!!</span> |
| 682 | <a name="l00952"></a>00952 |
| 683 | <a name="l00953"></a>00953 <span class="comment">/* if (0) {</span> |
| 684 | <a name="l00954"></a>00954 <span class="comment"> mat XX=X.to_mat();</span> |
| 685 | <a name="l00955"></a>00955 <span class="comment"> mat YY=Y.to_mat();</span> |
| 686 | <a name="l00956"></a>00956 <span class="comment"> </span> |
| 687 | <a name="l00957"></a>00957 <span class="comment"> double log2 = 0.5*p*log(det(YY))-0.5*(delta+p+1)*log(det(XX))-0.5*trace(YY*inv(XX)); </span> |
| 688 | <a name="l00958"></a>00958 <span class="comment"> cout << log1 << "," << log2 << endl;</span> |
| 689 | <a name="l00959"></a>00959 <span class="comment"> }*/</span> |
| 690 | <a name="l00960"></a>00960 <span class="keywordflow">return</span> log1; |
| 691 | <a name="l00961"></a>00961 }; |
| 692 | <a name="l00962"></a>00962 |
| 693 | <a name="l00963"></a>00963 }; |
| 694 | <a name="l00964"></a>00964 |
| 695 | <a name="l00965"></a>00965 <span class="keyword">class </span>rwiWishartCh : <span class="keyword">public</span> mpdf |
| 696 | <a name="l00966"></a>00966 { |
| 697 | <a name="l00967"></a>00967 <span class="keyword">protected</span>: |
| 698 | <a name="l00968"></a>00968 eiWishartCh eiW; |
| 699 | <a name="l00970"></a>00970 <span class="keywordtype">double</span> sqd; |
| 700 | <a name="l00971"></a>00971 <span class="comment">//reference point for diagonal</span> |
| 701 | <a name="l00972"></a>00972 vec refl; |
| 702 | <a name="l00973"></a>00973 <span class="keywordtype">double</span> l; |
| 703 | <a name="l00974"></a>00974 <span class="keywordtype">int</span> p; |
| 704 | <a name="l00975"></a>00975 <span class="keyword">public</span>: |
| 705 | <a name="l00976"></a>00976 <span class="keywordtype">void</span> set_parameters ( <span class="keywordtype">int</span> p0, <span class="keywordtype">double</span> k, vec ref0, <span class="keywordtype">double</span> l0 ) |
| 706 | <a name="l00977"></a>00977 { |
| 707 | <a name="l00978"></a>00978 p=p0; |
| 708 | <a name="l00979"></a>00979 <span class="keywordtype">double</span> delta = 2/(k*k)+p+3; |
| 709 | <a name="l00980"></a>00980 sqd=sqrt ( delta-p-1 ); |
| 710 | <a name="l00981"></a>00981 l=l0; |
| 711 | <a name="l00982"></a>00982 refl=pow(ref0,1-l); |
| 712 | <a name="l00983"></a>00983 |
| 713 | <a name="l00984"></a>00984 eiW.set_parameters ( eye ( p ),delta ); |
| 714 | <a name="l00985"></a>00985 <a class="code" href="classbdm_1_1mpdf.html#5eea43c56d38e4441bfb30270db949c0" title="pointer to internal epdf">ep</a>=&eiW; |
| 715 | <a name="l00986"></a>00986 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a>=eiW.dimension(); |
| 716 | <a name="l00987"></a>00987 } |
| 717 | <a name="l00988"></a>00988 <span class="keywordtype">void</span> condition ( <span class="keyword">const</span> vec &c ) { |
| 718 | <a name="l00989"></a>00989 vec z=c; |
| 719 | <a name="l00990"></a>00990 <span class="keywordtype">int</span> ri=0; |
| 720 | <a name="l00991"></a>00991 <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i<p*p;i+=(p+1)){<span class="comment">//trace diagonal element</span> |
| 721 | <a name="l00992"></a>00992 z(i) = pow(z(i),l)*refl(ri); |
| 722 | <a name="l00993"></a>00993 ri++; |
| 723 | <a name="l00994"></a>00994 } |
| 724 | <a name="l00995"></a>00995 |
| 725 | <a name="l00996"></a>00996 eiW._setY ( sqd*z ); |
| 726 | <a name="l00997"></a>00997 } |
| 727 | <a name="l00998"></a>00998 }; |
| 728 | <a name="l00999"></a>00999 |
| 729 | <a name="l01001"></a>01001 <span class="keyword">enum</span> RESAMPLING_METHOD { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; |
| 730 | <a name="l01007"></a><a class="code" href="classbdm_1_1eEmp.html">01007</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> |
| 731 | <a name="l01008"></a>01008 { |
| 732 | <a name="l01009"></a>01009 <span class="keyword">protected</span> : |
| 733 | <a name="l01011"></a><a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031">01011</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>; |
| 734 | <a name="l01013"></a><a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d">01013</a> vec <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>; |
| 735 | <a name="l01015"></a><a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3">01015</a> Array<vec> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>; |
| 736 | <a name="l01016"></a>01016 <span class="keyword">public</span>: |
| 737 | <a name="l01019"></a>01019 <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> ( ) :<a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ),<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ( ),<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( ) {}; |
| 738 | <a name="l01021"></a><a class="code" href="classbdm_1_1eEmp.html#a3daf6363455af099921715e1233c076">01021</a> <a class="code" href="classbdm_1_1eEmp.html#a3daf6363455af099921715e1233c076" title="copy constructor">eEmp</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> &e ) : <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( e ), <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ( e.<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ), <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( e.<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ) {}; |
| 739 | <a name="l01023"></a>01023 |
| 740 | <a name="l01025"></a>01025 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#7cfd383180b486fe4526bdf0179350c0" title="Set samples and weights.">set_statistics</a> ( <span class="keyword">const</span> vec &w0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* pdf0 ); |
| 741 | <a name="l01027"></a><a class="code" href="classbdm_1_1eEmp.html#cef74aa5f87d10d440b9b1e8bc78c1e7">01027</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#cef74aa5f87d10d440b9b1e8bc78c1e7" title="Set samples and weights.">set_statistics</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* pdf0 , <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a> ) {<a class="code" href="classbdm_1_1eEmp.html#cef74aa5f87d10d440b9b1e8bc78c1e7" title="Set samples and weights.">set_statistics</a> ( ones ( n ) /n,pdf0 );}; |
| 742 | <a name="l01029"></a>01029 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#b62d802b8ef39f7c4dcbeb366c90951a" title="Set sample.">set_samples</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* pdf0 ); |
| 743 | <a name="l01031"></a><a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1">01031</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1" title="Set sample.">set_parameters</a> ( <span class="keywordtype">int</span> n0, <span class="keywordtype">bool</span> copy=<span class="keyword">true</span> ) {<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>=n0; <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>.set_size ( n0,copy );<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>.set_size ( n0,copy );}; |
| 744 | <a name="l01033"></a><a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef">01033</a> vec& <a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>;}; |
| 745 | <a name="l01035"></a><a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714">01035</a> <span class="keyword">const</span> vec& <a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714" title="Potentially dangerous, use with care.">_w</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>;}; |
| 746 | <a name="l01037"></a><a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2">01037</a> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>;}; |
| 747 | <a name="l01039"></a><a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2">01039</a> <span class="keyword">const</span> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2" title="access function">_samples</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>;}; |
| 748 | <a name="l01041"></a>01041 ivec <a class="code" href="classbdm_1_1eEmp.html#f06ce255de5dbb2313f52ee51f82ba3d" title="Function performs resampling, i.e. removal of low-weight samples and duplication...">resample</a> ( RESAMPLING_METHOD method=SYSTEMATIC ); |
| 749 | <a name="l01043"></a><a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270">01043</a> vec <a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270" title="inherited operation : NOT implemneted">sample</a>()<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> 0;} |
| 750 | <a name="l01045"></a><a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09">01045</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09" title="inherited operation : NOT implemneted">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> 0.0;} |
| 751 | <a name="l01046"></a><a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9">01046</a> vec <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>()<span class="keyword"> const</span> |
| 752 | <a name="l01047"></a>01047 <span class="keyword"> </span>{ |
| 753 | <a name="l01048"></a>01048 vec pom=zeros ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
| 754 | <a name="l01049"></a>01049 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++ ) {pom+=<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) *<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ( i );} |
| 755 | <a name="l01050"></a>01050 <span class="keywordflow">return</span> pom; |
| 756 | <a name="l01051"></a>01051 } |
| 757 | <a name="l01052"></a><a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87">01052</a> vec <a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const</span> |
| 758 | <a name="l01053"></a>01053 <span class="keyword"> </span>{ |
| 759 | <a name="l01054"></a>01054 vec pom=zeros ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
| 760 | <a name="l01055"></a>01055 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++ ) {pom+=pow ( <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ),2 ) *<a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> ( i );} |
| 761 | <a name="l01056"></a>01056 <span class="keywordflow">return</span> pom-pow ( <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>(),2 ); |
| 762 | <a name="l01057"></a>01057 } |
| 763 | <a name="l01059"></a><a class="code" href="classbdm_1_1eEmp.html#b1c9df656144edf79ba2d885613f661f">01059</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#b1c9df656144edf79ba2d885613f661f" title="For this class, qbounds are minimum and maximum value of the population!">qbounds</a> ( vec &lb, vec &ub, <span class="keywordtype">double</span> perc=0.95 )<span class="keyword"> const</span> |
| 764 | <a name="l01060"></a>01060 <span class="keyword"> </span>{ |
| 765 | <a name="l01061"></a>01061 <span class="comment">// lb in inf so than it will be pushed below;</span> |
| 766 | <a name="l01062"></a>01062 lb.set_size ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
| 767 | <a name="l01063"></a>01063 ub.set_size ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
| 768 | <a name="l01064"></a>01064 lb = std::numeric_limits<double>::infinity(); |
| 769 | <a name="l01065"></a>01065 ub = -std::numeric_limits<double>::infinity(); |
| 770 | <a name="l01066"></a>01066 <span class="keywordtype">int</span> j; |
| 771 | <a name="l01067"></a>01067 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++ ) |
| 772 | <a name="l01068"></a>01068 { |
| 773 | <a name="l01069"></a>01069 <span class="keywordflow">for</span> ( j=0;j<<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>; j++ ) |
| 774 | <a name="l01070"></a>01070 { |
| 775 | <a name="l01071"></a>01071 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j ) <lb ( j ) ) {lb ( j ) =<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j );} |
| 776 | <a name="l01072"></a>01072 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j ) >ub ( j ) ) {ub ( j ) =<a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> ( i ) ( j );} |
| 777 | <a name="l01073"></a>01073 } |
| 778 | <a name="l01074"></a>01074 } |
| 779 | <a name="l01075"></a>01075 } |
| 780 | <a name="l01076"></a>01076 }; |
| 781 | <a name="l01077"></a>01077 |
783 | | <a name="l01079"></a>01079 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
784 | | <a name="l01080"></a>01080 <span class="keywordtype">void</span> enorm<sq_T>::set_parameters ( <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R0 ) |
785 | | <a name="l01081"></a>01081 { |
786 | | <a name="l01082"></a>01082 <span class="comment">//Fixme test dimensions of mu0 and R0;</span> |
787 | | <a name="l01083"></a>01083 mu = mu0; |
788 | | <a name="l01084"></a>01084 R = R0; |
789 | | <a name="l01085"></a>01085 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = mu0.length(); |
790 | | <a name="l01086"></a>01086 }; |
791 | | <a name="l01087"></a>01087 |
792 | | <a name="l01088"></a>01088 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
793 | | <a name="l01089"></a><a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2">01089</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2" title="dupdate in exponential form (not really handy)">enorm<sq_T>::dupdate</a> ( mat &v, <span class="keywordtype">double</span> nu ) |
794 | | <a name="l01090"></a>01090 { |
795 | | <a name="l01091"></a>01091 <span class="comment">//</span> |
796 | | <a name="l01092"></a>01092 }; |
797 | | <a name="l01093"></a>01093 |
798 | | <a name="l01094"></a>01094 <span class="comment">// template<class sq_T></span> |
799 | | <a name="l01095"></a>01095 <span class="comment">// void enorm<sq_T>::tupdate ( double phi, mat &vbar, double nubar ) {</span> |
800 | | <a name="l01096"></a>01096 <span class="comment">// //</span> |
801 | | <a name="l01097"></a>01097 <span class="comment">// };</span> |
802 | | <a name="l01098"></a>01098 |
803 | | <a name="l01099"></a>01099 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
804 | | <a name="l01100"></a><a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766">01100</a> vec <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">enorm<sq_T>::sample</a>()<span class="keyword"> const</span> |
805 | | <a name="l01101"></a>01101 <span class="keyword"> </span>{ |
806 | | <a name="l01102"></a>01102 vec x ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
807 | | <a name="l01103"></a>01103 <span class="preprocessor">#pragma omp critical</span> |
808 | | <a name="l01104"></a>01104 <span class="preprocessor"></span> NorRNG.sample_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,x ); |
809 | | <a name="l01105"></a>01105 vec smp = <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); |
810 | | <a name="l01106"></a>01106 |
811 | | <a name="l01107"></a>01107 smp += <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
812 | | <a name="l01108"></a>01108 <span class="keywordflow">return</span> smp; |
813 | | <a name="l01109"></a>01109 }; |
814 | | <a name="l01110"></a>01110 |
815 | | <a name="l01111"></a>01111 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
816 | | <a name="l01112"></a>01112 mat <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">enorm<sq_T>::sample</a> ( <span class="keywordtype">int</span> N )<span class="keyword"> const</span> |
817 | | <a name="l01113"></a>01113 <span class="keyword"> </span>{ |
818 | | <a name="l01114"></a>01114 mat X ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,N ); |
819 | | <a name="l01115"></a>01115 vec x ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
820 | | <a name="l01116"></a>01116 vec pom; |
821 | | <a name="l01117"></a>01117 <span class="keywordtype">int</span> i; |
822 | | <a name="l01118"></a>01118 |
823 | | <a name="l01119"></a>01119 <span class="keywordflow">for</span> ( i=0;i<N;i++ ) |
824 | | <a name="l01120"></a>01120 { |
825 | | <a name="l01121"></a>01121 <span class="preprocessor">#pragma omp critical</span> |
826 | | <a name="l01122"></a>01122 <span class="preprocessor"></span> NorRNG.sample_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,x ); |
827 | | <a name="l01123"></a>01123 pom = <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); |
828 | | <a name="l01124"></a>01124 pom +=<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
829 | | <a name="l01125"></a>01125 X.set_col ( i, pom ); |
830 | | <a name="l01126"></a>01126 } |
831 | | <a name="l01127"></a>01127 |
832 | | <a name="l01128"></a>01128 <span class="keywordflow">return</span> X; |
833 | | <a name="l01129"></a>01129 }; |
834 | | <a name="l01130"></a>01130 |
835 | | <a name="l01131"></a>01131 <span class="comment">// template<class sq_T></span> |
836 | | <a name="l01132"></a>01132 <span class="comment">// double enorm<sq_T>::eval ( const vec &val ) const {</span> |
837 | | <a name="l01133"></a>01133 <span class="comment">// double pdfl,e;</span> |
838 | | <a name="l01134"></a>01134 <span class="comment">// pdfl = evallog ( val );</span> |
839 | | <a name="l01135"></a>01135 <span class="comment">// e = exp ( pdfl );</span> |
840 | | <a name="l01136"></a>01136 <span class="comment">// return e;</span> |
841 | | <a name="l01137"></a>01137 <span class="comment">// };</span> |
842 | | <a name="l01138"></a>01138 |
843 | | <a name="l01139"></a>01139 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
844 | | <a name="l01140"></a><a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3">01140</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3" title="Evaluate normalized log-probability.">enorm<sq_T>::evallog_nn</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const</span> |
845 | | <a name="l01141"></a>01141 <span class="keyword"> </span>{ |
846 | | <a name="l01142"></a>01142 <span class="comment">// 1.83787706640935 = log(2pi)</span> |
847 | | <a name="l01143"></a>01143 <span class="keywordtype">double</span> tmp=-0.5* ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.invqform ( <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>-val ) );<span class="comment">// - lognc();</span> |
848 | | <a name="l01144"></a>01144 <span class="keywordflow">return</span> tmp; |
849 | | <a name="l01145"></a>01145 }; |
850 | | <a name="l01146"></a>01146 |
851 | | <a name="l01147"></a>01147 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
852 | | <a name="l01148"></a><a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32">01148</a> <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32" title="logarithm of the normalizing constant, ">enorm<sq_T>::lognc</a> ()<span class="keyword"> const</span> |
853 | | <a name="l01149"></a>01149 <span class="keyword"> </span>{ |
854 | | <a name="l01150"></a>01150 <span class="comment">// 1.83787706640935 = log(2pi)</span> |
855 | | <a name="l01151"></a>01151 <span class="keywordtype">double</span> tmp=0.5* ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.cols() * 1.83787706640935 +<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.logdet() ); |
856 | | <a name="l01152"></a>01152 <span class="keywordflow">return</span> tmp; |
857 | | <a name="l01153"></a>01153 }; |
858 | | <a name="l01154"></a>01154 |
859 | | <a name="l01155"></a>01155 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
860 | | <a name="l01156"></a><a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f">01156</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f" title="Set A and R.">mlnorm<sq_T>::set_parameters</a> ( <span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R0 ) |
861 | | <a name="l01157"></a>01157 { |
862 | | <a name="l01158"></a>01158 it_assert_debug ( A0.rows() ==mu0.length(),<span class="stringliteral">""</span> ); |
863 | | <a name="l01159"></a>01159 it_assert_debug ( A0.rows() ==R0.rows(),<span class="stringliteral">""</span> ); |
864 | | <a name="l01160"></a>01160 |
865 | | <a name="l01161"></a>01161 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( zeros ( A0.rows() ),R0 ); |
866 | | <a name="l01162"></a>01162 A = A0; |
867 | | <a name="l01163"></a>01163 mu_const = mu0; |
868 | | <a name="l01164"></a>01164 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a>=A0.cols(); |
869 | | <a name="l01165"></a>01165 } |
870 | | <a name="l01166"></a>01166 |
871 | | <a name="l01167"></a>01167 <span class="comment">// template<class sq_T></span> |
872 | | <a name="l01168"></a>01168 <span class="comment">// vec mlnorm<sq_T>::samplecond (const vec &cond, double &lik ) {</span> |
873 | | <a name="l01169"></a>01169 <span class="comment">// this->condition ( cond );</span> |
874 | | <a name="l01170"></a>01170 <span class="comment">// vec smp = epdf.sample();</span> |
875 | | <a name="l01171"></a>01171 <span class="comment">// lik = epdf.eval ( smp );</span> |
876 | | <a name="l01172"></a>01172 <span class="comment">// return smp;</span> |
877 | | <a name="l01173"></a>01173 <span class="comment">// }</span> |
878 | | <a name="l01174"></a>01174 |
879 | | <a name="l01175"></a>01175 <span class="comment">// template<class sq_T></span> |
880 | | <a name="l01176"></a>01176 <span class="comment">// mat mlnorm<sq_T>::samplecond (const vec &cond, vec &lik, int n ) {</span> |
881 | | <a name="l01177"></a>01177 <span class="comment">// int i;</span> |
882 | | <a name="l01178"></a>01178 <span class="comment">// int dim = rv.count();</span> |
883 | | <a name="l01179"></a>01179 <span class="comment">// mat Smp ( dim,n );</span> |
884 | | <a name="l01180"></a>01180 <span class="comment">// vec smp ( dim );</span> |
885 | | <a name="l01181"></a>01181 <span class="comment">// this->condition ( cond );</span> |
886 | | <a name="l01182"></a>01182 <span class="comment">//</span> |
887 | | <a name="l01183"></a>01183 <span class="comment">// for ( i=0; i<n; i++ ) {</span> |
888 | | <a name="l01184"></a>01184 <span class="comment">// smp = epdf.sample();</span> |
889 | | <a name="l01185"></a>01185 <span class="comment">// lik ( i ) = epdf.eval ( smp );</span> |
890 | | <a name="l01186"></a>01186 <span class="comment">// Smp.set_col ( i ,smp );</span> |
891 | | <a name="l01187"></a>01187 <span class="comment">// }</span> |
892 | | <a name="l01188"></a>01188 <span class="comment">//</span> |
893 | | <a name="l01189"></a>01189 <span class="comment">// return Smp;</span> |
894 | | <a name="l01190"></a>01190 <span class="comment">// }</span> |
895 | | <a name="l01191"></a>01191 |
896 | | <a name="l01192"></a>01192 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
897 | | <a name="l01193"></a><a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2">01193</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2">mlnorm<sq_T>::condition</a> ( <span class="keyword">const</span> vec &cond ) |
898 | | <a name="l01194"></a>01194 { |
899 | | <a name="l01195"></a>01195 _mu = A*cond + mu_const; |
900 | | <a name="l01196"></a>01196 <span class="comment">//R is already assigned;</span> |
901 | | <a name="l01197"></a>01197 } |
902 | | <a name="l01198"></a>01198 |
903 | | <a name="l01199"></a>01199 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
904 | | <a name="l01200"></a><a class="code" href="classbdm_1_1enorm.html#c2996bdaffad38fbe0fc776db54c9d80">01200</a> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* <a class="code" href="classbdm_1_1enorm.html#c2996bdaffad38fbe0fc776db54c9d80" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">enorm<sq_T>::marginal</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn )<span class="keyword"> const</span> |
905 | | <a name="l01201"></a>01201 <span class="keyword"> </span>{ |
906 | | <a name="l01202"></a>01202 it_assert_debug ( <a class="code" href="classbdm_1_1epdf.html#c4b863ff84c7a4882fb3ad18556027f9" title="True if rv is assigned.">isnamed</a>(), <span class="stringliteral">"rv description is not assigned"</span> ); |
907 | | <a name="l01203"></a>01203 ivec irvn = rvn.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55">dataind</a> ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ); |
908 | | <a name="l01204"></a>01204 |
909 | | <a name="l01205"></a>01205 sq_T Rn ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>,irvn ); <span class="comment">//select rows and columns of R</span> |
| 783 | <a name="l01080"></a>01080 |
| 784 | <a name="l01081"></a>01081 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 785 | <a name="l01082"></a>01082 <span class="keywordtype">void</span> enorm<sq_T>::set_parameters ( <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R0 ) |
| 786 | <a name="l01083"></a>01083 { |
| 787 | <a name="l01084"></a>01084 <span class="comment">//Fixme test dimensions of mu0 and R0;</span> |
| 788 | <a name="l01085"></a>01085 mu = mu0; |
| 789 | <a name="l01086"></a>01086 R = R0; |
| 790 | <a name="l01087"></a>01087 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = mu0.length(); |
| 791 | <a name="l01088"></a>01088 }; |
| 792 | <a name="l01089"></a>01089 |
| 793 | <a name="l01090"></a>01090 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 794 | <a name="l01091"></a><a class="code" href="classbdm_1_1enorm.html#61bd470764020bea6e1ed35000f259e6">01091</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#61bd470764020bea6e1ed35000f259e6" title="This method arrange instance properties according the data stored in the Setting...">enorm<sq_T>::from_setting</a>(<span class="keyword">const</span> Setting &root){ |
| 795 | <a name="l01092"></a>01092 vec <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
| 796 | <a name="l01093"></a>01093 <a class="code" href="classbdm_1_1UI.html#652bfd23f5052e4f1cb317057d74a3e2" title="This methods tries to build a new double matrix.">UI::get</a>(mu,root,<span class="stringliteral">"mu"</span>); |
| 797 | <a name="l01094"></a>01094 mat <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>; |
| 798 | <a name="l01095"></a>01095 <a class="code" href="classbdm_1_1UI.html#652bfd23f5052e4f1cb317057d74a3e2" title="This methods tries to build a new double matrix.">UI::get</a>(R,root,<span class="stringliteral">"R"</span>); |
| 799 | <a name="l01096"></a>01096 set_parameters(mu,R); |
| 800 | <a name="l01097"></a>01097 |
| 801 | <a name="l01098"></a>01098 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a>* r = UI::build<RV>(root,<span class="stringliteral">"rv"</span>); |
| 802 | <a name="l01099"></a>01099 <a class="code" href="classbdm_1_1epdf.html#f423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a>(*r); |
| 803 | <a name="l01100"></a>01100 <span class="keyword">delete</span> r; |
| 804 | <a name="l01101"></a>01101 } |
| 805 | <a name="l01102"></a>01102 |
| 806 | <a name="l01103"></a>01103 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 807 | <a name="l01104"></a><a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2">01104</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#d2e0d3a1e30ab3ab04df2d0c43ae74a2" title="dupdate in exponential form (not really handy)">enorm<sq_T>::dupdate</a> ( mat &v, <span class="keywordtype">double</span> nu ) |
| 808 | <a name="l01105"></a>01105 { |
| 809 | <a name="l01106"></a>01106 <span class="comment">//</span> |
| 810 | <a name="l01107"></a>01107 }; |
| 811 | <a name="l01108"></a>01108 |
| 812 | <a name="l01109"></a>01109 <span class="comment">// template<class sq_T></span> |
| 813 | <a name="l01110"></a>01110 <span class="comment">// void enorm<sq_T>::tupdate ( double phi, mat &vbar, double nubar ) {</span> |
| 814 | <a name="l01111"></a>01111 <span class="comment">// //</span> |
| 815 | <a name="l01112"></a>01112 <span class="comment">// };</span> |
| 816 | <a name="l01113"></a>01113 |
| 817 | <a name="l01114"></a>01114 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 818 | <a name="l01115"></a><a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766">01115</a> vec <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">enorm<sq_T>::sample</a>()<span class="keyword"> const</span> |
| 819 | <a name="l01116"></a>01116 <span class="keyword"> </span>{ |
| 820 | <a name="l01117"></a>01117 vec x ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
| 821 | <a name="l01118"></a>01118 <span class="preprocessor">#pragma omp critical</span> |
| 822 | <a name="l01119"></a>01119 <span class="preprocessor"></span> NorRNG.sample_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,x ); |
| 823 | <a name="l01120"></a>01120 vec smp = <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); |
| 824 | <a name="l01121"></a>01121 |
| 825 | <a name="l01122"></a>01122 smp += <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
| 826 | <a name="l01123"></a>01123 <span class="keywordflow">return</span> smp; |
| 827 | <a name="l01124"></a>01124 }; |
| 828 | <a name="l01125"></a>01125 |
| 829 | <a name="l01126"></a>01126 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 830 | <a name="l01127"></a>01127 mat <a class="code" href="classbdm_1_1enorm.html#e1a48f52351ec3a349bd443b713b1766" title="Returns a sample, from density .">enorm<sq_T>::sample</a> ( <span class="keywordtype">int</span> N )<span class="keyword"> const</span> |
| 831 | <a name="l01128"></a>01128 <span class="keyword"> </span>{ |
| 832 | <a name="l01129"></a>01129 mat X ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,N ); |
| 833 | <a name="l01130"></a>01130 vec x ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> ); |
| 834 | <a name="l01131"></a>01131 vec pom; |
| 835 | <a name="l01132"></a>01132 <span class="keywordtype">int</span> i; |
| 836 | <a name="l01133"></a>01133 |
| 837 | <a name="l01134"></a>01134 <span class="keywordflow">for</span> ( i=0;i<N;i++ ) |
| 838 | <a name="l01135"></a>01135 { |
| 839 | <a name="l01136"></a>01136 <span class="preprocessor">#pragma omp critical</span> |
| 840 | <a name="l01137"></a>01137 <span class="preprocessor"></span> NorRNG.sample_vector ( <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>,x ); |
| 841 | <a name="l01138"></a>01138 pom = <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.sqrt_mult ( x ); |
| 842 | <a name="l01139"></a>01139 pom +=<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>; |
| 843 | <a name="l01140"></a>01140 X.set_col ( i, pom ); |
| 844 | <a name="l01141"></a>01141 } |
| 845 | <a name="l01142"></a>01142 |
| 846 | <a name="l01143"></a>01143 <span class="keywordflow">return</span> X; |
| 847 | <a name="l01144"></a>01144 }; |
| 848 | <a name="l01145"></a>01145 |
| 849 | <a name="l01146"></a>01146 <span class="comment">// template<class sq_T></span> |
| 850 | <a name="l01147"></a>01147 <span class="comment">// double enorm<sq_T>::eval ( const vec &val ) const {</span> |
| 851 | <a name="l01148"></a>01148 <span class="comment">// double pdfl,e;</span> |
| 852 | <a name="l01149"></a>01149 <span class="comment">// pdfl = evallog ( val );</span> |
| 853 | <a name="l01150"></a>01150 <span class="comment">// e = exp ( pdfl );</span> |
| 854 | <a name="l01151"></a>01151 <span class="comment">// return e;</span> |
| 855 | <a name="l01152"></a>01152 <span class="comment">// };</span> |
| 856 | <a name="l01153"></a>01153 |
| 857 | <a name="l01154"></a>01154 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 858 | <a name="l01155"></a><a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3">01155</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#e13aeed5b543b2179bacdc4fa2ae47a3" title="Evaluate normalized log-probability.">enorm<sq_T>::evallog_nn</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const</span> |
| 859 | <a name="l01156"></a>01156 <span class="keyword"> </span>{ |
| 860 | <a name="l01157"></a>01157 <span class="comment">// 1.83787706640935 = log(2pi)</span> |
| 861 | <a name="l01158"></a>01158 <span class="keywordtype">double</span> tmp=-0.5* ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.invqform ( <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a>-val ) );<span class="comment">// - lognc();</span> |
| 862 | <a name="l01159"></a>01159 <span class="keywordflow">return</span> tmp; |
| 863 | <a name="l01160"></a>01160 }; |
| 864 | <a name="l01161"></a>01161 |
| 865 | <a name="l01162"></a>01162 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 866 | <a name="l01163"></a><a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32">01163</a> <span class="keyword">inline</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1enorm.html#25785343aff102cc5df1cab08ba16d32" title="logarithm of the normalizing constant, ">enorm<sq_T>::lognc</a> ()<span class="keyword"> const</span> |
| 867 | <a name="l01164"></a>01164 <span class="keyword"> </span>{ |
| 868 | <a name="l01165"></a>01165 <span class="comment">// 1.83787706640935 = log(2pi)</span> |
| 869 | <a name="l01166"></a>01166 <span class="keywordtype">double</span> tmp=0.5* ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.cols() * 1.83787706640935 +<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.logdet() ); |
| 870 | <a name="l01167"></a>01167 <span class="keywordflow">return</span> tmp; |
| 871 | <a name="l01168"></a>01168 }; |
| 872 | <a name="l01169"></a>01169 |
| 873 | <a name="l01170"></a>01170 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 874 | <a name="l01171"></a><a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f">01171</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#5d18dec3167584338a4775c1d165d96f" title="Set A and R.">mlnorm<sq_T>::set_parameters</a> ( <span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R0 ) |
| 875 | <a name="l01172"></a>01172 { |
| 876 | <a name="l01173"></a>01173 it_assert_debug ( A0.rows() ==mu0.length(),<span class="stringliteral">""</span> ); |
| 877 | <a name="l01174"></a>01174 it_assert_debug ( A0.rows() ==R0.rows(),<span class="stringliteral">""</span> ); |
| 878 | <a name="l01175"></a>01175 |
| 879 | <a name="l01176"></a>01176 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>.set_parameters ( zeros ( A0.rows() ),R0 ); |
| 880 | <a name="l01177"></a>01177 A = A0; |
| 881 | <a name="l01178"></a>01178 mu_const = mu0; |
| 882 | <a name="l01179"></a>01179 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a>=A0.cols(); |
| 883 | <a name="l01180"></a>01180 } |
| 884 | <a name="l01181"></a>01181 |
| 885 | <a name="l01182"></a>01182 <span class="comment">// template<class sq_T></span> |
| 886 | <a name="l01183"></a>01183 <span class="comment">// vec mlnorm<sq_T>::samplecond (const vec &cond, double &lik ) {</span> |
| 887 | <a name="l01184"></a>01184 <span class="comment">// this->condition ( cond );</span> |
| 888 | <a name="l01185"></a>01185 <span class="comment">// vec smp = epdf.sample();</span> |
| 889 | <a name="l01186"></a>01186 <span class="comment">// lik = epdf.eval ( smp );</span> |
| 890 | <a name="l01187"></a>01187 <span class="comment">// return smp;</span> |
| 891 | <a name="l01188"></a>01188 <span class="comment">// }</span> |
| 892 | <a name="l01189"></a>01189 |
| 893 | <a name="l01190"></a>01190 <span class="comment">// template<class sq_T></span> |
| 894 | <a name="l01191"></a>01191 <span class="comment">// mat mlnorm<sq_T>::samplecond (const vec &cond, vec &lik, int n ) {</span> |
| 895 | <a name="l01192"></a>01192 <span class="comment">// int i;</span> |
| 896 | <a name="l01193"></a>01193 <span class="comment">// int dim = rv.count();</span> |
| 897 | <a name="l01194"></a>01194 <span class="comment">// mat Smp ( dim,n );</span> |
| 898 | <a name="l01195"></a>01195 <span class="comment">// vec smp ( dim );</span> |
| 899 | <a name="l01196"></a>01196 <span class="comment">// this->condition ( cond );</span> |
| 900 | <a name="l01197"></a>01197 <span class="comment">//</span> |
| 901 | <a name="l01198"></a>01198 <span class="comment">// for ( i=0; i<n; i++ ) {</span> |
| 902 | <a name="l01199"></a>01199 <span class="comment">// smp = epdf.sample();</span> |
| 903 | <a name="l01200"></a>01200 <span class="comment">// lik ( i ) = epdf.eval ( smp );</span> |
| 904 | <a name="l01201"></a>01201 <span class="comment">// Smp.set_col ( i ,smp );</span> |
| 905 | <a name="l01202"></a>01202 <span class="comment">// }</span> |
| 906 | <a name="l01203"></a>01203 <span class="comment">//</span> |
| 907 | <a name="l01204"></a>01204 <span class="comment">// return Smp;</span> |
| 908 | <a name="l01205"></a>01205 <span class="comment">// }</span> |
911 | | <a name="l01207"></a>01207 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* tmp = <span class="keyword">new</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>; |
912 | | <a name="l01208"></a>01208 tmp-><a class="code" href="classbdm_1_1epdf.html#f423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a> ( rvn ); |
913 | | <a name="l01209"></a>01209 tmp-><a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> ( <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( irvn ), Rn ); |
914 | | <a name="l01210"></a>01210 <span class="keywordflow">return</span> tmp; |
915 | | <a name="l01211"></a>01211 } |
916 | | <a name="l01212"></a>01212 |
917 | | <a name="l01213"></a>01213 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
918 | | <a name="l01214"></a><a class="code" href="classbdm_1_1enorm.html#baea4d49c657342b58297d68cda16d26">01214</a> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a>* <a class="code" href="classbdm_1_1enorm.html#baea4d49c657342b58297d68cda16d26" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">enorm<sq_T>::condition</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn )<span class="keyword"> const</span> |
919 | | <a name="l01215"></a>01215 <span class="keyword"> </span>{ |
920 | | <a name="l01216"></a>01216 |
921 | | <a name="l01217"></a>01217 it_assert_debug ( <a class="code" href="classbdm_1_1epdf.html#c4b863ff84c7a4882fb3ad18556027f9" title="True if rv is assigned.">isnamed</a>(),<span class="stringliteral">"rvs are not assigned"</span> ); |
922 | | <a name="l01218"></a>01218 |
923 | | <a name="l01219"></a>01219 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rvc = <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#aec44dabdf0a6d90fbae95e1356eda39" title="Subtract another variable from the current one.">subt</a> ( rvn ); |
924 | | <a name="l01220"></a>01220 it_assert_debug ( ( rvc.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>() +rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>() ==<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>() ),<span class="stringliteral">"wrong rvn"</span> ); |
925 | | <a name="l01221"></a>01221 <span class="comment">//Permutation vector of the new R</span> |
926 | | <a name="l01222"></a>01222 ivec irvn = rvn.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55">dataind</a> ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ); |
927 | | <a name="l01223"></a>01223 ivec irvc = rvc.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55">dataind</a> ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ); |
928 | | <a name="l01224"></a>01224 ivec perm=concat ( irvn , irvc ); |
929 | | <a name="l01225"></a>01225 sq_T Rn ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>,perm ); |
930 | | <a name="l01226"></a>01226 |
931 | | <a name="l01227"></a>01227 <span class="comment">//fixme - could this be done in general for all sq_T?</span> |
932 | | <a name="l01228"></a>01228 mat S=Rn.to_mat(); |
933 | | <a name="l01229"></a>01229 <span class="comment">//fixme</span> |
934 | | <a name="l01230"></a>01230 <span class="keywordtype">int</span> n=rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>()-1; |
935 | | <a name="l01231"></a>01231 <span class="keywordtype">int</span> end=<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.rows()-1; |
936 | | <a name="l01232"></a>01232 mat S11 = S.get ( 0,n, 0, n ); |
937 | | <a name="l01233"></a>01233 mat S12 = S.get ( 0, n , rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(), end ); |
938 | | <a name="l01234"></a>01234 mat S22 = S.get ( rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(), end, rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(), end ); |
939 | | <a name="l01235"></a>01235 |
940 | | <a name="l01236"></a>01236 vec mu1 = <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( irvn ); |
941 | | <a name="l01237"></a>01237 vec mu2 = <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( irvc ); |
942 | | <a name="l01238"></a>01238 mat A=S12*inv ( S22 ); |
943 | | <a name="l01239"></a>01239 sq_T R_n ( S11 - A *S12.T() ); |
944 | | <a name="l01240"></a>01240 |
945 | | <a name="l01241"></a>01241 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T></a>* tmp=<span class="keyword">new</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T></a> ( ); |
946 | | <a name="l01242"></a>01242 tmp->set_rv ( rvn ); tmp->set_rvc ( rvc ); |
947 | | <a name="l01243"></a>01243 tmp->set_parameters ( A,mu1-A*mu2,R_n ); |
948 | | <a name="l01244"></a>01244 <span class="keywordflow">return</span> tmp; |
949 | | <a name="l01245"></a>01245 } |
950 | | <a name="l01246"></a>01246 |
951 | | <a name="l01248"></a>01248 |
952 | | <a name="l01249"></a>01249 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
953 | | <a name="l01250"></a>01250 std::ostream &operator<< ( std::ostream &os, mlnorm<sq_T> &ml ) |
954 | | <a name="l01251"></a>01251 { |
955 | | <a name="l01252"></a>01252 os << <span class="stringliteral">"A:"</span><< ml.A<<endl; |
956 | | <a name="l01253"></a>01253 os << <span class="stringliteral">"mu:"</span><< ml.mu_const<<endl; |
957 | | <a name="l01254"></a>01254 os << <span class="stringliteral">"R:"</span> << ml.epdf._R().to_mat() <<endl; |
958 | | <a name="l01255"></a>01255 <span class="keywordflow">return</span> os; |
959 | | <a name="l01256"></a>01256 }; |
960 | | <a name="l01257"></a>01257 |
961 | | <a name="l01258"></a>01258 } |
962 | | <a name="l01259"></a>01259 <span class="preprocessor">#endif //EF_H</span> |
| 910 | <a name="l01207"></a>01207 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 911 | <a name="l01208"></a><a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2">01208</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#0dafc0196e7e07fd06dc6716e0e18bc2">mlnorm<sq_T>::condition</a> ( <span class="keyword">const</span> vec &cond ) |
| 912 | <a name="l01209"></a>01209 { |
| 913 | <a name="l01210"></a>01210 _mu = A*cond + mu_const; |
| 914 | <a name="l01211"></a>01211 <span class="comment">//R is already assigned;</span> |
| 915 | <a name="l01212"></a>01212 } |
| 916 | <a name="l01213"></a>01213 |
| 917 | <a name="l01214"></a>01214 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 918 | <a name="l01215"></a><a class="code" href="classbdm_1_1enorm.html#c2996bdaffad38fbe0fc776db54c9d80">01215</a> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* <a class="code" href="classbdm_1_1enorm.html#c2996bdaffad38fbe0fc776db54c9d80" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">enorm<sq_T>::marginal</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn )<span class="keyword"> const</span> |
| 919 | <a name="l01216"></a>01216 <span class="keyword"> </span>{ |
| 920 | <a name="l01217"></a>01217 it_assert_debug ( <a class="code" href="classbdm_1_1epdf.html#c4b863ff84c7a4882fb3ad18556027f9" title="True if rv is assigned.">isnamed</a>(), <span class="stringliteral">"rv description is not assigned"</span> ); |
| 921 | <a name="l01218"></a>01218 ivec irvn = rvn.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55">dataind</a> ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ); |
| 922 | <a name="l01219"></a>01219 |
| 923 | <a name="l01220"></a>01220 sq_T Rn ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>,irvn ); <span class="comment">//select rows and columns of R</span> |
| 924 | <a name="l01221"></a>01221 |
| 925 | <a name="l01222"></a>01222 <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>* tmp = <span class="keyword">new</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>; |
| 926 | <a name="l01223"></a>01223 tmp-><a class="code" href="classbdm_1_1epdf.html#f423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a> ( rvn ); |
| 927 | <a name="l01224"></a>01224 tmp-><a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> ( <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( irvn ), Rn ); |
| 928 | <a name="l01225"></a>01225 <span class="keywordflow">return</span> tmp; |
| 929 | <a name="l01226"></a>01226 } |
| 930 | <a name="l01227"></a>01227 |
| 931 | <a name="l01228"></a>01228 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 932 | <a name="l01229"></a><a class="code" href="classbdm_1_1enorm.html#baea4d49c657342b58297d68cda16d26">01229</a> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a>* <a class="code" href="classbdm_1_1enorm.html#baea4d49c657342b58297d68cda16d26" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">enorm<sq_T>::condition</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> &rvn )<span class="keyword"> const</span> |
| 933 | <a name="l01230"></a>01230 <span class="keyword"> </span>{ |
| 934 | <a name="l01231"></a>01231 |
| 935 | <a name="l01232"></a>01232 it_assert_debug ( <a class="code" href="classbdm_1_1epdf.html#c4b863ff84c7a4882fb3ad18556027f9" title="True if rv is assigned.">isnamed</a>(),<span class="stringliteral">"rvs are not assigned"</span> ); |
| 936 | <a name="l01233"></a>01233 |
| 937 | <a name="l01234"></a>01234 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rvc = <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#aec44dabdf0a6d90fbae95e1356eda39" title="Subtract another variable from the current one.">subt</a> ( rvn ); |
| 938 | <a name="l01235"></a>01235 it_assert_debug ( ( rvc.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>() +rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>() ==<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>() ),<span class="stringliteral">"wrong rvn"</span> ); |
| 939 | <a name="l01236"></a>01236 <span class="comment">//Permutation vector of the new R</span> |
| 940 | <a name="l01237"></a>01237 ivec irvn = rvn.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55">dataind</a> ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ); |
| 941 | <a name="l01238"></a>01238 ivec irvc = rvc.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55">dataind</a> ( <a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> ); |
| 942 | <a name="l01239"></a>01239 ivec perm=concat ( irvn , irvc ); |
| 943 | <a name="l01240"></a>01240 sq_T Rn ( <a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>,perm ); |
| 944 | <a name="l01241"></a>01241 |
| 945 | <a name="l01242"></a>01242 <span class="comment">//fixme - could this be done in general for all sq_T?</span> |
| 946 | <a name="l01243"></a>01243 mat S=Rn.to_mat(); |
| 947 | <a name="l01244"></a>01244 <span class="comment">//fixme</span> |
| 948 | <a name="l01245"></a>01245 <span class="keywordtype">int</span> n=rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>()-1; |
| 949 | <a name="l01246"></a>01246 <span class="keywordtype">int</span> end=<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.rows()-1; |
| 950 | <a name="l01247"></a>01247 mat S11 = S.get ( 0,n, 0, n ); |
| 951 | <a name="l01248"></a>01248 mat S12 = S.get ( 0, n , rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(), end ); |
| 952 | <a name="l01249"></a>01249 mat S22 = S.get ( rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(), end, rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089">_dsize</a>(), end ); |
| 953 | <a name="l01250"></a>01250 |
| 954 | <a name="l01251"></a>01251 vec mu1 = <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( irvn ); |
| 955 | <a name="l01252"></a>01252 vec mu2 = <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> ( irvc ); |
| 956 | <a name="l01253"></a>01253 mat A=S12*inv ( S22 ); |
| 957 | <a name="l01254"></a>01254 sq_T R_n ( S11 - A *S12.T() ); |
| 958 | <a name="l01255"></a>01255 |
| 959 | <a name="l01256"></a>01256 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T></a>* tmp=<span class="keyword">new</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T></a> ( ); |
| 960 | <a name="l01257"></a>01257 tmp->set_rv ( rvn ); tmp->set_rvc ( rvc ); |
| 961 | <a name="l01258"></a>01258 tmp->set_parameters ( A,mu1-A*mu2,R_n ); |
| 962 | <a name="l01259"></a>01259 <span class="keywordflow">return</span> tmp; |
| 963 | <a name="l01260"></a>01260 } |
| 964 | <a name="l01261"></a>01261 |
| 965 | <a name="l01263"></a>01263 |
| 966 | <a name="l01264"></a>01264 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 967 | <a name="l01265"></a>01265 std::ostream &operator<< ( std::ostream &os, mlnorm<sq_T> &ml ) |
| 968 | <a name="l01266"></a>01266 { |
| 969 | <a name="l01267"></a>01267 os << <span class="stringliteral">"A:"</span><< ml.A<<endl; |
| 970 | <a name="l01268"></a>01268 os << <span class="stringliteral">"mu:"</span><< ml.mu_const<<endl; |
| 971 | <a name="l01269"></a>01269 os << <span class="stringliteral">"R:"</span> << ml.epdf._R().to_mat() <<endl; |
| 972 | <a name="l01270"></a>01270 <span class="keywordflow">return</span> os; |
| 973 | <a name="l01271"></a>01271 }; |
| 974 | <a name="l01272"></a>01272 |
| 975 | <a name="l01273"></a>01273 } |
| 976 | <a name="l01274"></a>01274 <span class="preprocessor">#endif //EF_H</span> |