258 | | <a name="l00300"></a><a class="code" href="classbdm_1_1eDirich.html#a3290613d31d58daa8a45a54b003871fc">00300</a> vec <a class="code" href="classbdm_1_1eDirich.html#a3290613d31d58daa8a45a54b003871fc" title="using sampling procedure from wikipedia">sample</a>()<span class="keyword"> const </span>{ |
259 | | <a name="l00301"></a>00301 vec y(<a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length()); |
260 | | <a name="l00302"></a>00302 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i=0; i<<a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length(); i++){ |
261 | | <a name="l00303"></a>00303 GamRNG.setup(<a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>(i),1); |
262 | | <a name="l00304"></a>00304 y(i)=GamRNG.sample(); |
263 | | <a name="l00305"></a>00305 } |
264 | | <a name="l00306"></a>00306 <span class="keywordflow">return</span> y/sum(y); |
265 | | <a name="l00307"></a>00307 } |
266 | | <a name="l00308"></a>00308 |
267 | | <a name="l00309"></a><a class="code" href="classbdm_1_1eDirich.html#acb343355ec791298bb5a3404cd482fb6">00309</a> vec <a class="code" href="classbdm_1_1eDirich.html#acb343355ec791298bb5a3404cd482fb6" title="return expected value">mean</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> / sum (<a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>);}; |
268 | | <a name="l00310"></a><a class="code" href="classbdm_1_1eDirich.html#a43c547a2507e233706f92712d8c2aacc">00310</a> vec <a class="code" href="classbdm_1_1eDirich.html#a43c547a2507e233706f92712d8c2aacc" 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#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>); <span class="keywordflow">return</span> elem_mult (<a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>, (gamma-<a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>)) / (gamma*gamma* (gamma + 1));} |
269 | | <a name="l00312"></a><a class="code" href="classbdm_1_1eDirich.html#ae09a24938e80c3d94b0ee842d1552318">00312</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#ae09a24938e80c3d94b0ee842d1552318" title="In this instance, val is ...">evallog_nn</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
270 | | <a name="l00313"></a>00313 <span class="keywordtype">double</span> tmp; tmp = (<a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> - 1) * log (val); |
271 | | <a name="l00314"></a>00314 <span class="keywordflow">return</span> tmp; |
272 | | <a name="l00315"></a>00315 } |
273 | | <a name="l00316"></a>00316 |
274 | | <a name="l00317"></a><a class="code" href="classbdm_1_1eDirich.html#a279a99f6266c82fe2273e83841f19eb2">00317</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eDirich.html#a279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a> ()<span class="keyword"> const </span>{ |
275 | | <a name="l00318"></a>00318 <span class="keywordtype">double</span> tmp; |
276 | | <a name="l00319"></a>00319 <span class="keywordtype">double</span> gam = sum (<a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>); |
277 | | <a name="l00320"></a>00320 <span class="keywordtype">double</span> lgb = 0.0; |
278 | | <a name="l00321"></a>00321 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length();i++) {lgb += lgamma (<a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> (i));} |
279 | | <a name="l00322"></a>00322 tmp = lgb - lgamma (gam); |
280 | | <a name="l00323"></a>00323 <span class="keywordflow">return</span> tmp; |
281 | | <a name="l00324"></a>00324 } |
282 | | <a name="l00325"></a>00325 |
283 | | <a name="l00327"></a><a class="code" href="classbdm_1_1eDirich.html#a175e0add26d2105c28d8121eefb9e324">00327</a> vec& <a class="code" href="classbdm_1_1eDirich.html#a175e0add26d2105c28d8121eefb9e324" title="access function">_beta</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>;} |
284 | | <a name="l00334"></a><a class="code" href="classbdm_1_1eDirich.html#aaef2c328917dd80dce689d3d11d09567">00334</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eDirich.html#aaef2c328917dd80dce689d3d11d09567">from_setting</a>(<span class="keyword">const</span> Setting &<span class="keyword">set</span>){ |
285 | | <a name="l00335"></a>00335 <a class="code" href="classbdm_1_1eDirich.html#aaef2c328917dd80dce689d3d11d09567">epdf::from_setting</a>(<span class="keyword">set</span>); |
286 | | <a name="l00336"></a>00336 <a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a>(<a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>,<span class="keyword">set</span>, <span class="stringliteral">"beta"</span>, UI::compulsory); |
287 | | <a name="l00337"></a>00337 <a class="code" href="classbdm_1_1eDirich.html#a3ee16ce701b850e1c5bdb7005c326a57" title="This method TODO.">validate</a>(); |
288 | | <a name="l00338"></a>00338 } |
289 | | <a name="l00339"></a><a class="code" href="classbdm_1_1eDirich.html#a3ee16ce701b850e1c5bdb7005c326a57">00339</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eDirich.html#a3ee16ce701b850e1c5bdb7005c326a57" title="This method TODO.">validate</a>() { |
290 | | <a name="l00340"></a>00340 <span class="comment">//check rv</span> |
291 | | <a name="l00341"></a>00341 <a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eDirich.html#af25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length(); |
292 | | <a name="l00342"></a>00342 } |
293 | | <a name="l00343"></a>00343 }; |
294 | | <a name="l00344"></a>00344 <a class="code" href="user__info_8h.html#a4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(eDirich); |
295 | | <a name="l00345"></a>00345 |
296 | | <a name="l00357"></a><a class="code" href="classbdm_1_1mDirich.html">00357</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mDirich.html">mDirich</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><eDirich> { |
297 | | <a name="l00358"></a>00358 <span class="keyword">protected</span>: |
298 | | <a name="l00360"></a><a class="code" href="classbdm_1_1mDirich.html#acf9baed9baab754872ec59b9d45bf164">00360</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mDirich.html#acf9baed9baab754872ec59b9d45bf164" title="constant of the random walk">k</a>; |
299 | | <a name="l00362"></a><a class="code" href="classbdm_1_1mDirich.html#a44230d127f95c6da1032e4e5886204ab">00362</a> vec &<a class="code" href="classbdm_1_1mDirich.html#a44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a>; |
300 | | <a name="l00364"></a><a class="code" href="classbdm_1_1mDirich.html#a0c367b11fc853db86e9f00143e68013a">00364</a> vec <a class="code" href="classbdm_1_1mDirich.html#a0c367b11fc853db86e9f00143e68013a" title="stabilizing coefficient ">betac</a>; |
301 | | <a name="l00365"></a>00365 <span class="keyword">public</span>: |
302 | | <a name="l00366"></a>00366 <a class="code" href="classbdm_1_1mDirich.html">mDirich</a>(): <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a>>(), <a class="code" href="classbdm_1_1mDirich.html#a44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a>(<a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1mDirich.html#a44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a>()){}; |
303 | | <a name="l00367"></a><a class="code" href="classbdm_1_1mDirich.html#a78a06fc013ca7fc8dbc13ee899e3b0d0">00367</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mDirich.html#a78a06fc013ca7fc8dbc13ee899e3b0d0" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">condition</a> (<span class="keyword">const</span> vec &val) {<a class="code" href="classbdm_1_1mDirich.html#a44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a> = val/<a class="code" href="classbdm_1_1mDirich.html#acf9baed9baab754872ec59b9d45bf164" title="constant of the random walk">k</a>+<a class="code" href="classbdm_1_1mDirich.html#a0c367b11fc853db86e9f00143e68013a" title="stabilizing coefficient ">betac</a>; }; |
304 | | <a name="l00380"></a><a class="code" href="classbdm_1_1mDirich.html#ac1e6f42277b97f700ea1b6045cb6b2d7">00380</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mDirich.html#ac1e6f42277b97f700ea1b6045cb6b2d7">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
305 | | <a name="l00381"></a>00381 <a class="code" href="classbdm_1_1mDirich.html#ac1e6f42277b97f700ea1b6045cb6b2d7">mpdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv and rvc</span> |
306 | | <a name="l00382"></a>00382 <span class="keywordflow">if</span> (_rv()._dsize()>0){ |
307 | | <a name="l00383"></a>00383 <a class="code" href="classbdm_1_1mpdf.html#a5a5f08950daa08b85b01ddf4e1c36288" title="random variable in condition">rvc</a> = _rv().<a class="code" href="classbdm_1_1RV.html#a627222f49abc5d07e5e8aecac7708ee2" title="create new RV from the current one with time shifted by given value">copy_t</a>(-1); |
308 | | <a name="l00384"></a>00384 } |
309 | | <a name="l00385"></a>00385 vec beta0; |
310 | | <a name="l00386"></a>00386 <span class="keywordflow">if</span> (!<a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (beta0, <span class="keyword">set</span>, <span class="stringliteral">"beta0"</span>, UI::optional)){ |
311 | | <a name="l00387"></a>00387 beta0 = ones(_rv()._dsize()); |
312 | | <a name="l00388"></a>00388 } |
313 | | <a name="l00389"></a>00389 <span class="keywordflow">if</span> (!<a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mDirich.html#a0c367b11fc853db86e9f00143e68013a" title="stabilizing coefficient ">betac</a>, <span class="keyword">set</span>, <span class="stringliteral">"betac"</span>, UI::optional)){ |
314 | | <a name="l00390"></a>00390 <a class="code" href="classbdm_1_1mDirich.html#a0c367b11fc853db86e9f00143e68013a" title="stabilizing coefficient ">betac</a> = 0.1*ones(_rv()._dsize()); |
315 | | <a name="l00391"></a>00391 } |
316 | | <a name="l00392"></a>00392 <a class="code" href="classbdm_1_1mDirich.html#a44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a> = beta0; |
317 | | <a name="l00393"></a>00393 |
318 | | <a name="l00394"></a>00394 <a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mDirich.html#acf9baed9baab754872ec59b9d45bf164" title="constant of the random walk">k</a>, <span class="keyword">set</span>, <span class="stringliteral">"k"</span>, UI::compulsory); |
319 | | <a name="l00395"></a>00395 <a class="code" href="classbdm_1_1mDirich.html#abd6dfd941c1cf5092b02d23f58d7bde4" title="This method TODO.">validate</a>(); |
320 | | <a name="l00396"></a>00396 } |
321 | | <a name="l00397"></a><a class="code" href="classbdm_1_1mDirich.html#abd6dfd941c1cf5092b02d23f58d7bde4">00397</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mDirich.html#abd6dfd941c1cf5092b02d23f58d7bde4" title="This method TODO.">validate</a>() { |
322 | | <a name="l00398"></a>00398 <a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1eDirich.html#a3ee16ce701b850e1c5bdb7005c326a57" title="This method TODO.">validate</a>(); |
323 | | <a name="l00399"></a>00399 <a class="code" href="bdmerror_8h.html#a7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a>(<a class="code" href="classbdm_1_1mDirich.html#a44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a>.length()==<a class="code" href="classbdm_1_1mDirich.html#a0c367b11fc853db86e9f00143e68013a" title="stabilizing coefficient ">betac</a>.length(),<span class="stringliteral">"beta0 and betac are not compatible"</span>); |
324 | | <a name="l00400"></a>00400 <span class="keywordflow">if</span> (_rv().<a class="code" href="classbdm_1_1RV.html#ade30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>()>0){ |
325 | | <a name="l00401"></a>00401 <a class="code" href="bdmerror_8h.html#a7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a>( (_rv()._dsize()==dimension()) , <span class="stringliteral">"Size of rv does not match with beta"</span>); |
326 | | <a name="l00402"></a>00402 } |
327 | | <a name="l00403"></a>00403 <a class="code" href="classbdm_1_1mpdf.html#a7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = <a class="code" href="classbdm_1_1mDirich.html#a44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a>.length(); |
328 | | <a name="l00404"></a>00404 }; |
329 | | <a name="l00405"></a>00405 }; |
330 | | <a name="l00406"></a>00406 <a class="code" href="user__info_8h.html#a4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(mDirich); |
331 | | <a name="l00407"></a>00407 |
332 | | <a name="l00409"></a><a class="code" href="classbdm_1_1multiBM.html">00409</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> |
333 | | <a name="l00410"></a>00410 { |
334 | | <a name="l00411"></a>00411 <span class="keyword">protected</span>: |
335 | | <a name="l00413"></a><a class="code" href="classbdm_1_1multiBM.html#a9ecc6878abbd20eb8d8e43b6ab3f941a">00413</a> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> <a class="code" href="classbdm_1_1multiBM.html#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>; |
336 | | <a name="l00415"></a><a class="code" href="classbdm_1_1multiBM.html#a044263356944c92209eecd39a5187d25">00415</a> vec &<a class="code" href="classbdm_1_1multiBM.html#a044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>; |
337 | | <a name="l00416"></a>00416 <span class="keyword">public</span>: |
338 | | <a name="l00418"></a><a class="code" href="classbdm_1_1multiBM.html#ac4dd6d9522a8a605776d21bac9bd9daf">00418</a> <a class="code" href="classbdm_1_1multiBM.html#ac4dd6d9522a8a605776d21bac9bd9daf" 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#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> (), <a class="code" href="classbdm_1_1multiBM.html#a044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> (<a class="code" href="classbdm_1_1multiBM.html#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>._beta()) { |
339 | | <a name="l00419"></a>00419 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1multiBM.html#a044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>.length() > 0) {<a class="code" href="classbdm_1_1BMEF.html#a06e7b3ac03e10017d4288c76888e2865" 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#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#a279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
340 | | <a name="l00420"></a>00420 <span class="keywordflow">else</span>{<a class="code" href="classbdm_1_1BMEF.html#a06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a> = 0.0;} |
341 | | <a name="l00421"></a>00421 } |
342 | | <a name="l00423"></a><a class="code" href="classbdm_1_1multiBM.html#ac4378cf8037f6bed29c74eea63344b31">00423</a> <a class="code" href="classbdm_1_1multiBM.html#ac4378cf8037f6bed29c74eea63344b31" 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#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a> (B.<a class="code" href="classbdm_1_1multiBM.html#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>), <a class="code" href="classbdm_1_1multiBM.html#a044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> (<a class="code" href="classbdm_1_1multiBM.html#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>._beta()) {} |
343 | | <a name="l00425"></a><a class="code" href="classbdm_1_1multiBM.html#adbe6b90d410dc062a233d1dc09eeba52">00425</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#adbe6b90d410dc062a233d1dc09eeba52" 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#a044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> = mB-><a class="code" href="classbdm_1_1multiBM.html#a044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>;} |
344 | | <a name="l00426"></a><a class="code" href="classbdm_1_1multiBM.html#a1e4bf41b61937fd80f34049742e23f95">00426</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#a1e4bf41b61937fd80f34049742e23f95" title="Incremental Bayes rule.">bayes</a> (<span class="keyword">const</span> vec &dt) { |
345 | | <a name="l00427"></a>00427 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BMEF.html#a1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a> < 1.0) {<a class="code" href="classbdm_1_1multiBM.html#a044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> *= <a class="code" href="classbdm_1_1BMEF.html#a1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>;<a class="code" href="classbdm_1_1BMEF.html#a06e7b3ac03e10017d4288c76888e2865" 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#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#a279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
346 | | <a name="l00428"></a>00428 <a class="code" href="classbdm_1_1multiBM.html#a044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> += dt; |
347 | | <a name="l00429"></a>00429 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BM.html#afaff0ad12556fe7dc0e2807d4fd938ee" 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#a4064b6559d962633e4372b12f4cd204a" title="Logarithm of marginalized data likelihood.">ll</a> = <a class="code" href="classbdm_1_1multiBM.html#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#a279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>() - <a class="code" href="classbdm_1_1BMEF.html#a06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
348 | | <a name="l00430"></a>00430 } |
349 | | <a name="l00431"></a><a class="code" href="classbdm_1_1multiBM.html#ae157b607c1e3fa91d42aeea44458e2bf">00431</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1multiBM.html#ae157b607c1e3fa91d42aeea44458e2bf">logpred</a> (<span class="keyword">const</span> vec &dt)<span class="keyword"> const </span>{ |
350 | | <a name="l00432"></a>00432 <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a> pred (<a class="code" href="classbdm_1_1multiBM.html#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>); |
351 | | <a name="l00433"></a>00433 vec &<a class="code" href="classbdm_1_1multiBM.html#a044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> = pred.<a class="code" href="classbdm_1_1eDirich.html#a175e0add26d2105c28d8121eefb9e324" title="access function">_beta</a>(); |
352 | | <a name="l00434"></a>00434 |
353 | | <a name="l00435"></a>00435 <span class="keywordtype">double</span> lll; |
354 | | <a name="l00436"></a>00436 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BMEF.html#a1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a> < 1.0) |
355 | | <a name="l00437"></a>00437 {beta *= <a class="code" href="classbdm_1_1BMEF.html#a1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a>;lll = pred.<a class="code" href="classbdm_1_1eDirich.html#a279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
356 | | <a name="l00438"></a>00438 <span class="keywordflow">else</span> |
357 | | <a name="l00439"></a>00439 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BM.html#afaff0ad12556fe7dc0e2807d4fd938ee" 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#a06e7b3ac03e10017d4288c76888e2865" title="cached value of lognc() in the previous step (used in evaluation of ll )">last_lognc</a>;} |
358 | | <a name="l00440"></a>00440 <span class="keywordflow">else</span>{lll = pred.<a class="code" href="classbdm_1_1eDirich.html#a279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
359 | | <a name="l00441"></a>00441 |
360 | | <a name="l00442"></a>00442 beta += dt; |
361 | | <a name="l00443"></a>00443 <span class="keywordflow">return</span> pred.<a class="code" href="classbdm_1_1eDirich.html#a279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>() - lll; |
362 | | <a name="l00444"></a>00444 } |
363 | | <a name="l00445"></a>00445 <span class="keywordtype">void</span> flatten (<span class="keyword">const</span> <a class="code" href="classbdm_1_1BMEF.html" title="Estimator for Exponential family.">BMEF</a>* B) { |
364 | | <a name="l00446"></a>00446 <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); |
365 | | <a name="l00447"></a>00447 <span class="comment">// sum(beta) should be equal to sum(B.beta)</span> |
366 | | <a name="l00448"></a>00448 <span class="keyword">const</span> vec &Eb = E-><a class="code" href="classbdm_1_1multiBM.html#a044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>;<span class="comment">//const_cast<multiBM*> ( E )->_beta();</span> |
367 | | <a name="l00449"></a>00449 <a class="code" href="classbdm_1_1multiBM.html#a044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> *= (sum (Eb) / sum (<a class="code" href="classbdm_1_1multiBM.html#a044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>)); |
368 | | <a name="l00450"></a>00450 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BM.html#afaff0ad12556fe7dc0e2807d4fd938ee" 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#a06e7b3ac03e10017d4288c76888e2865" 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#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#a279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
369 | | <a name="l00451"></a>00451 } |
370 | | <a name="l00453"></a><a class="code" href="classbdm_1_1multiBM.html#a31ff93f89473f099e489b9e1dc8d9513">00453</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a>& <a class="code" href="classbdm_1_1multiBM.html#a31ff93f89473f099e489b9e1dc8d9513" title="reimplemnetation of BM::posterior()">posterior</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1multiBM.html#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>;}; |
371 | | <a name="l00455"></a><a class="code" href="classbdm_1_1multiBM.html#a7a480eace4446661bacca94c57499f01">00455</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#a7a480eace4446661bacca94c57499f01" title="constructor function">set_parameters</a> (<span class="keyword">const</span> vec &beta0) { |
372 | | <a name="l00456"></a>00456 <a class="code" href="classbdm_1_1multiBM.html#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.set_parameters (beta0); |
373 | | <a name="l00457"></a>00457 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BM.html#afaff0ad12556fe7dc0e2807d4fd938ee" 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#a06e7b3ac03e10017d4288c76888e2865" 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#a9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.<a class="code" href="classbdm_1_1eDirich.html#a279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
374 | | <a name="l00458"></a>00458 } |
375 | | <a name="l00459"></a>00459 }; |
376 | | <a name="l00460"></a>00460 |
377 | | <a name="l00470"></a><a class="code" href="classbdm_1_1egamma.html">00470</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> |
378 | | <a name="l00471"></a>00471 { |
379 | | <a name="l00472"></a>00472 <span class="keyword">protected</span>: |
380 | | <a name="l00474"></a><a class="code" href="classbdm_1_1egamma.html#a0901ec983e66b8337aaa506e13b122fa">00474</a> vec <a class="code" href="classbdm_1_1egamma.html#a0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>; |
381 | | <a name="l00476"></a><a class="code" href="classbdm_1_1egamma.html#a457bfb1ccb2057df85073e519a15ccc1">00476</a> vec <a class="code" href="classbdm_1_1egamma.html#a457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>; |
382 | | <a name="l00477"></a>00477 <span class="keyword">public</span> : |
383 | | <a name="l00480"></a>00480 <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#a0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> (0), <a class="code" href="classbdm_1_1egamma.html#a457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a> (0) {}; |
384 | | <a name="l00481"></a>00481 <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);}; |
385 | | <a name="l00482"></a>00482 <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#a0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> = a, <a class="code" href="classbdm_1_1egamma.html#a457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a> = b;<a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egamma.html#a0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length();}; |
386 | | <a name="l00484"></a>00484 |
387 | | <a name="l00485"></a>00485 vec <a class="code" href="classbdm_1_1egamma.html#a6ed82f0fd05f6002487256d8e75a0bbd" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
388 | | <a name="l00486"></a>00486 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#aa8e11e5a580ff42a1b205974c60768c6" title="Evaluate normalized log-probability.">evallog</a> (<span class="keyword">const</span> vec &val) <span class="keyword">const</span>; |
389 | | <a name="l00487"></a>00487 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#a9a66cbd100e8520c769ccb3c451f86f8" title="logarithm of the normalizing constant, ">lognc</a> () <span class="keyword">const</span>; |
390 | | <a name="l00489"></a><a class="code" href="classbdm_1_1egamma.html#a0865cb3d6339fdc7410806cf70a329ed">00489</a> vec& <a class="code" href="classbdm_1_1egamma.html#a0865cb3d6339fdc7410806cf70a329ed" title="Returns pointer to internal alpha. Potentially dengerous: use with care!">_alpha</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1egamma.html#a0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>;} |
391 | | <a name="l00491"></a><a class="code" href="classbdm_1_1egamma.html#ac42cadd9cbd344caaa69b0b433cd16ca">00491</a> vec& <a class="code" href="classbdm_1_1egamma.html#ac42cadd9cbd344caaa69b0b433cd16ca" title="Returns pointer to internal beta. Potentially dengerous: use with care!">_beta</a>() {<span class="keywordflow">return</span> beta;} |
392 | | <a name="l00492"></a><a class="code" href="classbdm_1_1egamma.html#a49d256c42cce14c6faa56ec242b57e85">00492</a> vec <a class="code" href="classbdm_1_1egamma.html#a49d256c42cce14c6faa56ec242b57e85" 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#a0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>, beta);} |
393 | | <a name="l00493"></a><a class="code" href="classbdm_1_1egamma.html#a36986cc01917cd0796fadc17125bdec1">00493</a> vec <a class="code" href="classbdm_1_1egamma.html#a36986cc01917cd0796fadc17125bdec1" 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#a0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>, elem_mult (beta, beta)); } |
394 | | <a name="l00494"></a>00494 |
395 | | <a name="l00505"></a><a class="code" href="classbdm_1_1egamma.html#a8a6fd1a1c0190f3e0d95a2a1f99aafc1">00505</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egamma.html#a8a6fd1a1c0190f3e0d95a2a1f99aafc1">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
396 | | <a name="l00506"></a>00506 <a class="code" href="classbdm_1_1egamma.html#a8a6fd1a1c0190f3e0d95a2a1f99aafc1">epdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv</span> |
397 | | <a name="l00507"></a>00507 <a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1egamma.html#a0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>, <span class="keyword">set</span>, <span class="stringliteral">"alpha"</span>, UI::compulsory); |
398 | | <a name="l00508"></a>00508 <a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (beta, <span class="keyword">set</span>, <span class="stringliteral">"beta"</span>, UI::compulsory); |
399 | | <a name="l00509"></a>00509 <a class="code" href="classbdm_1_1egamma.html#ac3a8d8ae8ba79d0fb35036711fa7d127" title="This method TODO.">validate</a>(); |
400 | | <a name="l00510"></a>00510 } |
401 | | <a name="l00511"></a><a class="code" href="classbdm_1_1egamma.html#ac3a8d8ae8ba79d0fb35036711fa7d127">00511</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egamma.html#ac3a8d8ae8ba79d0fb35036711fa7d127" title="This method TODO.">validate</a>() { |
402 | | <a name="l00512"></a>00512 <a class="code" href="bdmerror_8h.html#a7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<a class="code" href="classbdm_1_1egamma.html#a0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length() == beta.length(), <span class="stringliteral">"parameters do not match"</span>); |
403 | | <a name="l00513"></a>00513 <a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1egamma.html#a0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length(); |
404 | | <a name="l00514"></a>00514 } |
405 | | <a name="l00515"></a>00515 }; |
406 | | <a name="l00516"></a>00516 <a class="code" href="user__info_8h.html#a4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a> (egamma); |
407 | | <a name="l00517"></a>00517 SHAREDPTR ( egamma ); |
408 | | <a name="l00518"></a>00518 |
409 | | <a name="l00535"></a><a class="code" href="classbdm_1_1eigamma.html">00535</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> |
410 | | <a name="l00536"></a>00536 { |
411 | | <a name="l00537"></a>00537 <span class="keyword">protected</span>: |
412 | | <a name="l00538"></a>00538 <span class="keyword">public</span> : |
413 | | <a name="l00543"></a>00543 |
414 | | <a name="l00544"></a><a class="code" href="classbdm_1_1eigamma.html#a3aff7bf25ddac27731c60826fcfd878f">00544</a> vec <a class="code" href="classbdm_1_1eigamma.html#a3aff7bf25ddac27731c60826fcfd878f" 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#a3aff7bf25ddac27731c60826fcfd878f" title="Returns a sample, from density .">egamma::sample</a>();}; |
415 | | <a name="l00546"></a><a class="code" href="classbdm_1_1eigamma.html#a46cecb295edbabd28120cb0f6f572bcb">00546</a> vec <a class="code" href="classbdm_1_1eigamma.html#a46cecb295edbabd28120cb0f6f572bcb" 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#a457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>, <a class="code" href="classbdm_1_1egamma.html#a0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> - 1);} |
416 | | <a name="l00547"></a><a class="code" href="classbdm_1_1eigamma.html#ac2c696f8c668e9f65392c9449f6a5133">00547</a> vec <a class="code" href="classbdm_1_1eigamma.html#ac2c696f8c668e9f65392c9449f6a5133" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{vec mea = <a class="code" href="classbdm_1_1eigamma.html#a46cecb295edbabd28120cb0f6f572bcb" 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#a0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a> - 2);} |
417 | | <a name="l00548"></a>00548 }; |
418 | | <a name="l00549"></a>00549 <span class="comment">/*</span> |
419 | | <a name="l00551"></a>00551 <span class="comment">class emix : public epdf {</span> |
420 | | <a name="l00552"></a>00552 <span class="comment">protected:</span> |
421 | | <a name="l00553"></a>00553 <span class="comment"> int n;</span> |
422 | | <a name="l00554"></a>00554 <span class="comment"> vec &w;</span> |
423 | | <a name="l00555"></a>00555 <span class="comment"> Array<epdf*> Coms;</span> |
424 | | <a name="l00556"></a>00556 <span class="comment">public:</span> |
425 | | <a name="l00558"></a>00558 <span class="comment"> emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {};</span> |
426 | | <a name="l00559"></a>00559 <span class="comment"> void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;}</span> |
427 | | <a name="l00560"></a>00560 <span class="comment"> vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;};</span> |
428 | | <a name="l00561"></a>00561 <span class="comment">};</span> |
429 | | <a name="l00562"></a>00562 <span class="comment">*/</span> |
430 | | <a name="l00563"></a>00563 |
431 | | <a name="l00565"></a>00565 |
432 | | <a name="l00566"></a><a class="code" href="classbdm_1_1euni.html">00566</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> |
433 | | <a name="l00567"></a>00567 { |
434 | | <a name="l00568"></a>00568 <span class="keyword">protected</span>: |
435 | | <a name="l00570"></a><a class="code" href="classbdm_1_1euni.html#aff7ce6a2ef5ef0015bbd1398bed12f32">00570</a> vec <a class="code" href="classbdm_1_1euni.html#aff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>; |
436 | | <a name="l00572"></a><a class="code" href="classbdm_1_1euni.html#acfad2dea4a62db6872bda8abd75f0de1">00572</a> vec <a class="code" href="classbdm_1_1euni.html#acfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>; |
437 | | <a name="l00574"></a><a class="code" href="classbdm_1_1euni.html#ad3c27e331f90c754d80228108de8ed4c">00574</a> vec <a class="code" href="classbdm_1_1euni.html#ad3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>; |
438 | | <a name="l00576"></a><a class="code" href="classbdm_1_1euni.html#a31bb13e8449a8eff35246d46dae35c20">00576</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#a31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>; |
439 | | <a name="l00578"></a><a class="code" href="classbdm_1_1euni.html#a3e63be48dd58659663ca60cd18700476">00578</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#a3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
440 | | <a name="l00579"></a>00579 <span class="keyword">public</span>: |
441 | | <a name="l00582"></a>00582 <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> () {} |
442 | | <a name="l00583"></a>00583 <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);} |
443 | | <a name="l00584"></a>00584 <span class="keywordtype">void</span> set_parameters (<span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0) { |
444 | | <a name="l00585"></a>00585 <a class="code" href="classbdm_1_1euni.html#ad3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> = high0 - low0; |
445 | | <a name="l00586"></a>00586 <a class="code" href="classbdm_1_1euni.html#aff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> = low0; |
446 | | <a name="l00587"></a>00587 <a class="code" href="classbdm_1_1euni.html#acfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a> = high0; |
447 | | <a name="l00588"></a>00588 <a class="code" href="classbdm_1_1euni.html#a31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a> = prod (1.0 / <a class="code" href="classbdm_1_1euni.html#ad3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>); |
448 | | <a name="l00589"></a>00589 <a class="code" href="classbdm_1_1euni.html#a3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a> = log (<a class="code" href="classbdm_1_1euni.html#a31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>); |
449 | | <a name="l00590"></a>00590 <a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1euni.html#aff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>.length(); |
450 | | <a name="l00591"></a>00591 } |
451 | | <a name="l00593"></a>00593 |
452 | | <a name="l00594"></a><a class="code" href="classbdm_1_1euni.html#acaa07b8307bd793d5339d6583e0aba81">00594</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#acaa07b8307bd793d5339d6583e0aba81" title="Compute log-probability of argument val In case the argument is out of suport return...">evallog</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
453 | | <a name="l00595"></a>00595 <span class="keywordflow">if</span> (any (val < <a class="code" href="classbdm_1_1euni.html#aff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>) && any (val > <a class="code" href="classbdm_1_1euni.html#acfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>)) {<span class="keywordflow">return</span> inf;} |
454 | | <a name="l00596"></a>00596 <span class="keywordflow">else</span> <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#a3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
455 | | <a name="l00597"></a>00597 } |
456 | | <a name="l00598"></a><a class="code" href="classbdm_1_1euni.html#afc5df80359ead2918384b2004ce67194">00598</a> vec <a class="code" href="classbdm_1_1euni.html#afc5df80359ead2918384b2004ce67194" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
457 | | <a name="l00599"></a>00599 vec smp (<a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
458 | | <a name="l00600"></a>00600 <span class="preprocessor">#pragma omp critical</span> |
459 | | <a name="l00601"></a>00601 <span class="preprocessor"></span> UniRNG.sample_vector (<a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> , smp); |
460 | | <a name="l00602"></a>00602 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#aff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> + elem_mult (<a class="code" href="classbdm_1_1euni.html#ad3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>, smp); |
461 | | <a name="l00603"></a>00603 } |
462 | | <a name="l00605"></a><a class="code" href="classbdm_1_1euni.html#a46caa8c13aba2e6228f964208918b226">00605</a> vec <a class="code" href="classbdm_1_1euni.html#a46caa8c13aba2e6228f964208918b226" 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#acfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a> -<a class="code" href="classbdm_1_1euni.html#aff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>) / 2.0;} |
463 | | <a name="l00606"></a><a class="code" href="classbdm_1_1euni.html#a951f932155111f6053c980f672b4c22c">00606</a> vec <a class="code" href="classbdm_1_1euni.html#a951f932155111f6053c980f672b4c22c" 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#acfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>, 2) + pow (<a class="code" href="classbdm_1_1euni.html#aff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>, 2) + elem_mult (<a class="code" href="classbdm_1_1euni.html#acfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>, <a class="code" href="classbdm_1_1euni.html#aff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>)) / 3.0;} |
464 | | <a name="l00617"></a><a class="code" href="classbdm_1_1euni.html#a77f5fef1f006fe056066da23b9e5f042">00617</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1euni.html#a77f5fef1f006fe056066da23b9e5f042">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
465 | | <a name="l00618"></a>00618 <a class="code" href="classbdm_1_1euni.html#a77f5fef1f006fe056066da23b9e5f042">epdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv and rvc</span> |
466 | | <a name="l00619"></a>00619 |
467 | | <a name="l00620"></a>00620 <a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1euni.html#acfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>, <span class="keyword">set</span>, <span class="stringliteral">"high"</span>, UI::compulsory); |
468 | | <a name="l00621"></a>00621 <a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1euni.html#aff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>, <span class="keyword">set</span>, <span class="stringliteral">"low"</span>, UI::compulsory); |
469 | | <a name="l00622"></a>00622 set_parameters(<a class="code" href="classbdm_1_1euni.html#aff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>,<a class="code" href="classbdm_1_1euni.html#acfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>); |
470 | | <a name="l00623"></a>00623 <a class="code" href="classbdm_1_1euni.html#a70c5a7dcf7cb0f7ea83b9165f31868e9" title="This method TODO.">validate</a>(); |
471 | | <a name="l00624"></a>00624 } |
472 | | <a name="l00625"></a><a class="code" href="classbdm_1_1euni.html#a70c5a7dcf7cb0f7ea83b9165f31868e9">00625</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1euni.html#a70c5a7dcf7cb0f7ea83b9165f31868e9" title="This method TODO.">validate</a>() { |
473 | | <a name="l00626"></a>00626 <a class="code" href="bdmerror_8h.html#a7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a>(<a class="code" href="classbdm_1_1euni.html#acfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>.length()==<a class="code" href="classbdm_1_1euni.html#aff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>.length(), <span class="stringliteral">"Incompatible high and low vectors"</span>); |
474 | | <a name="l00627"></a>00627 <a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1euni.html#acfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>.length(); |
475 | | <a name="l00628"></a>00628 <a class="code" href="bdmerror_8h.html#a7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (min (<a class="code" href="classbdm_1_1euni.html#ad3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>) > 0.0, <span class="stringliteral">"bad support"</span>); |
476 | | <a name="l00629"></a>00629 } |
477 | | <a name="l00630"></a>00630 }; |
478 | | <a name="l00631"></a>00631 <a class="code" href="user__info_8h.html#a4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(euni); |
479 | | <a name="l00632"></a>00632 |
480 | | <a name="l00638"></a>00638 <span class="keyword">template</span> < <span class="keyword">class</span> sq_T, <span class="keyword">template</span> <<span class="keyword">typename</span>> <span class="keyword">class </span>TEpdf = enorm > |
481 | | <a name="l00639"></a><a class="code" href="classbdm_1_1mlnorm.html">00639</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< TEpdf<sq_T> > |
482 | | <a name="l00640"></a>00640 { |
483 | | <a name="l00641"></a>00641 <span class="keyword">protected</span>: |
484 | | <a name="l00643"></a><a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42">00643</a> mat <a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>; |
485 | | <a name="l00645"></a><a class="code" href="classbdm_1_1mlnorm.html#a831b50121cad10aa03a16682bd0c3ed6">00645</a> vec <a class="code" href="classbdm_1_1mlnorm.html#a831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>; |
486 | | <a name="l00646"></a>00646 <span class="comment">// vec& _mu; //cached epdf.mu; !!!!!! WHY NOT?</span> |
487 | | <a name="l00647"></a>00647 <span class="keyword">public</span>: |
488 | | <a name="l00650"></a>00650 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< TEpdf<sq_T> >() {}; |
489 | | <a name="l00651"></a>00651 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a> (<span class="keyword">const</span> mat &<a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R) : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< TEpdf<sq_T> >() { |
490 | | <a name="l00652"></a>00652 <a class="code" href="classbdm_1_1mlnorm.html#a04f7c6cda7b2f95161dd5fbcf15d1fd5" title="Set A and R.">set_parameters</a> (A, mu0, R); |
491 | | <a name="l00653"></a>00653 } |
492 | | <a name="l00654"></a>00654 |
493 | | <a name="l00656"></a><a class="code" href="classbdm_1_1mlnorm.html#a04f7c6cda7b2f95161dd5fbcf15d1fd5">00656</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#a04f7c6cda7b2f95161dd5fbcf15d1fd5" title="Set A and R.">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) { |
494 | | <a name="l00657"></a>00657 this-><a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.set_parameters (zeros (A0.rows()), R0); |
495 | | <a name="l00658"></a>00658 <a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> = A0; |
496 | | <a name="l00659"></a>00659 <a class="code" href="classbdm_1_1mlnorm.html#a831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a> = mu0; |
497 | | <a name="l00660"></a>00660 this-><a class="code" href="classbdm_1_1mpdf.html#a7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = A0.cols(); |
498 | | <a name="l00661"></a>00661 } |
499 | | <a name="l00664"></a><a class="code" href="classbdm_1_1mlnorm.html#ac2895ae549ee76d961be98d7061bd110">00664</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#ac2895ae549ee76d961be98d7061bd110">condition</a> (<span class="keyword">const</span> vec &cond) { |
500 | | <a name="l00665"></a>00665 this-><a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._mu() = <a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> * cond + <a class="code" href="classbdm_1_1mlnorm.html#a831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>; |
501 | | <a name="l00666"></a>00666 <span class="comment">//R is already assigned;</span> |
502 | | <a name="l00667"></a>00667 } |
503 | | <a name="l00668"></a>00668 |
504 | | <a name="l00670"></a><a class="code" href="classbdm_1_1mlnorm.html#af6b0b4b0b17271525ad02660a4087cf7">00670</a> <span class="keyword">const</span> vec& <a class="code" href="classbdm_1_1mlnorm.html#af6b0b4b0b17271525ad02660a4087cf7" title="access function">_mu_const</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1mlnorm.html#a831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>;} |
505 | | <a name="l00672"></a><a class="code" href="classbdm_1_1mlnorm.html#a55e1bd7fa70b852bd7fe50ce72fb8f23">00672</a> <span class="keyword">const</span> mat& <a class="code" href="classbdm_1_1mlnorm.html#a55e1bd7fa70b852bd7fe50ce72fb8f23" title="access function">_A</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>;} |
506 | | <a name="l00674"></a><a class="code" href="classbdm_1_1mlnorm.html#a9af0714b7b29ab1162ebc3291b7c4a43">00674</a> mat <a class="code" href="classbdm_1_1mlnorm.html#a9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> this-><a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._R().to_mat(); } |
507 | | <a name="l00675"></a>00675 |
508 | | <a name="l00677"></a>00677 <span class="keyword">template</span><<span class="keyword">typename</span> sq_M> |
509 | | <a name="l00678"></a>00678 <span class="keyword">friend</span> std::ostream &operator<< (std::ostream &os, mlnorm<sq_M, enorm> &ml); |
510 | | <a name="l00679"></a>00679 |
511 | | <a name="l00690"></a><a class="code" href="classbdm_1_1mlnorm.html#a52980f13d80162d00b30d5864343f564">00690</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#a52980f13d80162d00b30d5864343f564">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
512 | | <a name="l00691"></a>00691 <a class="code" href="classbdm_1_1mlnorm.html#a52980f13d80162d00b30d5864343f564">mpdf::from_setting</a> (<span class="keyword">set</span>); |
513 | | <a name="l00692"></a>00692 |
514 | | <a name="l00693"></a>00693 <a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>, <span class="keyword">set</span>, <span class="stringliteral">"A"</span>, UI::compulsory); |
515 | | <a name="l00694"></a>00694 <a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mlnorm.html#a831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>, <span class="keyword">set</span>, <span class="stringliteral">"const"</span>, UI::compulsory); |
516 | | <a name="l00695"></a>00695 mat R0; |
517 | | <a name="l00696"></a>00696 <a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (R0, <span class="keyword">set</span>, <span class="stringliteral">"R"</span>, UI::compulsory); |
518 | | <a name="l00697"></a>00697 <a class="code" href="classbdm_1_1mlnorm.html#a04f7c6cda7b2f95161dd5fbcf15d1fd5" title="Set A and R.">set_parameters</a> (<a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>, <a class="code" href="classbdm_1_1mlnorm.html#a831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>, R0); |
519 | | <a name="l00698"></a>00698 <a class="code" href="classbdm_1_1mlnorm.html#acafcb3fb9bad8ff5fd51897f6eb10924" title="This method TODO.">validate</a>(); |
520 | | <a name="l00699"></a>00699 }; |
521 | | <a name="l00700"></a><a class="code" href="classbdm_1_1mlnorm.html#acafcb3fb9bad8ff5fd51897f6eb10924">00700</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#acafcb3fb9bad8ff5fd51897f6eb10924" title="This method TODO.">validate</a>() { |
522 | | <a name="l00701"></a>00701 <a class="code" href="bdmerror_8h.html#a7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>.rows() == <a class="code" href="classbdm_1_1mlnorm.html#a831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>.length(), <span class="stringliteral">"mlnorm: A vs. mu mismatch"</span>); |
523 | | <a name="l00702"></a>00702 <a class="code" href="bdmerror_8h.html#a7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>.rows() == <a class="code" href="classbdm_1_1mlnorm.html#a9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a>().rows(), <span class="stringliteral">"mlnorm: A vs. R mismatch"</span>); |
524 | | <a name="l00703"></a>00703 |
525 | | <a name="l00704"></a>00704 } |
526 | | <a name="l00705"></a>00705 }; |
527 | | <a name="l00706"></a>00706 <a class="code" href="user__info_8h.html#ab06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mlnorm,ldmat); |
528 | | <a name="l00707"></a>00707 SHAREDPTR2 ( mlnorm, ldmat ); |
529 | | <a name="l00708"></a>00708 <a class="code" href="user__info_8h.html#ab06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mlnorm,fsqmat); |
530 | | <a name="l00709"></a>00709 SHAREDPTR2 ( mlnorm, fsqmat ); |
531 | | <a name="l00710"></a>00710 <a class="code" href="user__info_8h.html#ab06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mlnorm, chmat); |
532 | | <a name="l00711"></a>00711 SHAREDPTR2 ( mlnorm, chmat ); |
533 | | <a name="l00712"></a>00712 |
534 | | <a name="l00714"></a>00714 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
535 | | <a name="l00715"></a><a class="code" href="classbdm_1_1mgnorm.html">00715</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgnorm.html" title="Mpdf with general function for mean value.">mgnorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< enorm< sq_T > > |
536 | | <a name="l00716"></a>00716 { |
537 | | <a name="l00717"></a>00717 <span class="keyword">private</span>: |
538 | | <a name="l00718"></a>00718 <span class="comment">// vec &mu; WHY NOT?</span> |
539 | | <a name="l00719"></a>00719 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<fnc></a> g; |
540 | | <a name="l00720"></a>00720 |
541 | | <a name="l00721"></a>00721 <span class="keyword">public</span>: |
542 | | <a name="l00723"></a><a class="code" href="classbdm_1_1mgnorm.html#a1b014915d74470d3efab74e07cacb97d">00723</a> <a class="code" href="classbdm_1_1mgnorm.html#a1b014915d74470d3efab74e07cacb97d" title="default constructor">mgnorm</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a><sq_T> >() { } |
543 | | <a name="l00725"></a>00725 <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#ab736332d20e418bf50d45836e129f339" title="set mean function">set_parameters</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<fnc></a> &g0, <span class="keyword">const</span> sq_T &R0); |
544 | | <a name="l00726"></a>00726 <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#ab31d63472cf6a1030cd8dbd8094c1f6d" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">condition</a> (<span class="keyword">const</span> vec &cond); |
545 | | <a name="l00727"></a>00727 |
| 255 | <a name="l00300"></a><a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc">00300</a> vec <a class="code" href="classbdm_1_1eDirich.html#3290613d31d58daa8a45a54b003871fc" title="using sampling procedure from wikipedia">sample</a>()<span class="keyword"> const </span>{ |
| 256 | <a name="l00301"></a>00301 vec y(<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>.length()); |
| 257 | <a name="l00302"></a>00302 <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++){ |
| 258 | <a name="l00303"></a>00303 GamRNG.<a class="code" href="classitpp_1_1Gamma__RNG.html#dfaae19411e39aa87e1f72e409b6babe" title="Set lambda.">setup</a>(<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>(i),1); |
| 259 | <a name="l00304"></a>00304 <span class="preprocessor"> #pragma omp critical</span> |
| 260 | <a name="l00305"></a>00305 <span class="preprocessor"></span> y(i)=GamRNG(); |
| 261 | <a name="l00306"></a>00306 } |
| 262 | <a name="l00307"></a>00307 <span class="keywordflow">return</span> y/sum(y); |
| 263 | <a name="l00308"></a>00308 } |
| 264 | <a name="l00309"></a>00309 |
| 265 | <a name="l00310"></a><a class="code" href="classbdm_1_1eDirich.html#cb343355ec791298bb5a3404cd482fb6">00310</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>);}; |
| 266 | <a name="l00311"></a><a class="code" href="classbdm_1_1eDirich.html#43c547a2507e233706f92712d8c2aacc">00311</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>, (gamma-<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>)) / (gamma*gamma* (gamma + 1));} |
| 267 | <a name="l00313"></a><a class="code" href="classbdm_1_1eDirich.html#e09a24938e80c3d94b0ee842d1552318">00313</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>{ |
| 268 | <a name="l00314"></a>00314 <span class="keywordtype">double</span> tmp; tmp = (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a> - 1) * log (val); |
| 269 | <a name="l00315"></a>00315 <span class="keywordflow">return</span> tmp; |
| 270 | <a name="l00316"></a>00316 } |
| 271 | <a name="l00317"></a>00317 |
| 272 | <a name="l00318"></a><a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2">00318</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>{ |
| 273 | <a name="l00319"></a>00319 <span class="keywordtype">double</span> tmp; |
| 274 | <a name="l00320"></a>00320 <span class="keywordtype">double</span> gam = sum (<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>); |
| 275 | <a name="l00321"></a>00321 <span class="keywordtype">double</span> lgb = 0.0; |
| 276 | <a name="l00322"></a>00322 <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));} |
| 277 | <a name="l00323"></a>00323 tmp = lgb - lgamma (gam); |
| 278 | <a name="l00324"></a>00324 <span class="keywordflow">return</span> tmp; |
| 279 | <a name="l00325"></a>00325 } |
| 280 | <a name="l00326"></a>00326 |
| 281 | <a name="l00328"></a><a class="code" href="classbdm_1_1eDirich.html#175e0add26d2105c28d8121eefb9e324">00328</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>;} |
| 282 | <a name="l00335"></a><a class="code" href="classbdm_1_1eDirich.html#aef2c328917dd80dce689d3d11d09567">00335</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eDirich.html#aef2c328917dd80dce689d3d11d09567">from_setting</a>(<span class="keyword">const</span> Setting &<span class="keyword">set</span>){ |
| 283 | <a name="l00336"></a>00336 <a class="code" href="classbdm_1_1eDirich.html#aef2c328917dd80dce689d3d11d09567">epdf::from_setting</a>(<span class="keyword">set</span>); |
| 284 | <a name="l00337"></a>00337 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a>(<a class="code" href="classbdm_1_1eDirich.html#f25886a49b4667af61245de81c83b5d2" title="sufficient statistics">beta</a>,<span class="keyword">set</span>, <span class="stringliteral">"beta"</span>, UI::compulsory); |
| 285 | <a name="l00338"></a>00338 <a class="code" href="classbdm_1_1eDirich.html#3ee16ce701b850e1c5bdb7005c326a57" title="This method TODO.">validate</a>(); |
| 286 | <a name="l00339"></a>00339 } |
| 287 | <a name="l00340"></a><a class="code" href="classbdm_1_1eDirich.html#3ee16ce701b850e1c5bdb7005c326a57">00340</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eDirich.html#3ee16ce701b850e1c5bdb7005c326a57" title="This method TODO.">validate</a>() { |
| 288 | <a name="l00341"></a>00341 <span class="comment">//check rv</span> |
| 289 | <a name="l00342"></a>00342 <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(); |
| 290 | <a name="l00343"></a>00343 } |
| 291 | <a name="l00344"></a>00344 }; |
| 292 | <a name="l00345"></a>00345 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(eDirich); |
| 293 | <a name="l00346"></a>00346 |
| 294 | <a name="l00358"></a><a class="code" href="classbdm_1_1mDirich.html">00358</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mDirich.html">mDirich</a>: <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><eDirich> { |
| 295 | <a name="l00359"></a>00359 <span class="keyword">protected</span>: |
| 296 | <a name="l00361"></a><a class="code" href="classbdm_1_1mDirich.html#cf9baed9baab754872ec59b9d45bf164">00361</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mDirich.html#cf9baed9baab754872ec59b9d45bf164" title="constant of the random walk">k</a>; |
| 297 | <a name="l00363"></a><a class="code" href="classbdm_1_1mDirich.html#44230d127f95c6da1032e4e5886204ab">00363</a> vec &<a class="code" href="classbdm_1_1mDirich.html#44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a>; |
| 298 | <a name="l00365"></a><a class="code" href="classbdm_1_1mDirich.html#0c367b11fc853db86e9f00143e68013a">00365</a> vec <a class="code" href="classbdm_1_1mDirich.html#0c367b11fc853db86e9f00143e68013a" title="stabilizing coefficient ">betac</a>; |
| 299 | <a name="l00366"></a>00366 <span class="keyword">public</span>: |
| 300 | <a name="l00367"></a>00367 <a class="code" href="classbdm_1_1mDirich.html">mDirich</a>(): <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a>>(), <a class="code" href="classbdm_1_1mDirich.html#44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a>(<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1mDirich.html#44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a>()){}; |
| 301 | <a name="l00368"></a><a class="code" href="classbdm_1_1mDirich.html#78a06fc013ca7fc8dbc13ee899e3b0d0">00368</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mDirich.html#78a06fc013ca7fc8dbc13ee899e3b0d0" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">condition</a> (<span class="keyword">const</span> vec &val) {<a class="code" href="classbdm_1_1mDirich.html#44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a> = val/<a class="code" href="classbdm_1_1mDirich.html#cf9baed9baab754872ec59b9d45bf164" title="constant of the random walk">k</a>+<a class="code" href="classbdm_1_1mDirich.html#0c367b11fc853db86e9f00143e68013a" title="stabilizing coefficient ">betac</a>; }; |
| 302 | <a name="l00381"></a><a class="code" href="classbdm_1_1mDirich.html#c1e6f42277b97f700ea1b6045cb6b2d7">00381</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mDirich.html#c1e6f42277b97f700ea1b6045cb6b2d7">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
| 303 | <a name="l00382"></a>00382 <a class="code" href="classbdm_1_1mDirich.html#c1e6f42277b97f700ea1b6045cb6b2d7">mpdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv and rvc</span> |
| 304 | <a name="l00383"></a>00383 <span class="keywordflow">if</span> (_rv()._dsize()>0){ |
| 305 | <a name="l00384"></a>00384 <a class="code" href="classbdm_1_1mpdf.html#5a5f08950daa08b85b01ddf4e1c36288" title="random variable in condition">rvc</a> = _rv().<a class="code" href="classbdm_1_1RV.html#627222f49abc5d07e5e8aecac7708ee2" title="create new RV from the current one with time shifted by given value">copy_t</a>(-1); |
| 306 | <a name="l00385"></a>00385 } |
| 307 | <a name="l00386"></a>00386 vec beta0; |
| 308 | <a name="l00387"></a>00387 <span class="keywordflow">if</span> (!<a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (beta0, <span class="keyword">set</span>, <span class="stringliteral">"beta0"</span>, UI::optional)){ |
| 309 | <a name="l00388"></a>00388 beta0 = ones(_rv()._dsize()); |
| 310 | <a name="l00389"></a>00389 } |
| 311 | <a name="l00390"></a>00390 <span class="keywordflow">if</span> (!<a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mDirich.html#0c367b11fc853db86e9f00143e68013a" title="stabilizing coefficient ">betac</a>, <span class="keyword">set</span>, <span class="stringliteral">"betac"</span>, UI::optional)){ |
| 312 | <a name="l00391"></a>00391 <a class="code" href="classbdm_1_1mDirich.html#0c367b11fc853db86e9f00143e68013a" title="stabilizing coefficient ">betac</a> = 0.1*ones(_rv()._dsize()); |
| 313 | <a name="l00392"></a>00392 } |
| 314 | <a name="l00393"></a>00393 <a class="code" href="classbdm_1_1mDirich.html#44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a> = beta0; |
| 315 | <a name="l00394"></a>00394 |
| 316 | <a name="l00395"></a>00395 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mDirich.html#cf9baed9baab754872ec59b9d45bf164" title="constant of the random walk">k</a>, <span class="keyword">set</span>, <span class="stringliteral">"k"</span>, UI::compulsory); |
| 317 | <a name="l00396"></a>00396 <a class="code" href="classbdm_1_1mDirich.html#bd6dfd941c1cf5092b02d23f58d7bde4" title="This method TODO.">validate</a>(); |
| 318 | <a name="l00397"></a>00397 } |
| 319 | <a name="l00398"></a><a class="code" href="classbdm_1_1mDirich.html#bd6dfd941c1cf5092b02d23f58d7bde4">00398</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mDirich.html#bd6dfd941c1cf5092b02d23f58d7bde4" title="This method TODO.">validate</a>() { |
| 320 | <a name="l00399"></a>00399 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1eDirich.html#3ee16ce701b850e1c5bdb7005c326a57" title="This method TODO.">validate</a>(); |
| 321 | <a name="l00400"></a>00400 <a class="code" href="bdmerror_8h.html#7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a>(<a class="code" href="classbdm_1_1mDirich.html#44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a>.length()==<a class="code" href="classbdm_1_1mDirich.html#0c367b11fc853db86e9f00143e68013a" title="stabilizing coefficient ">betac</a>.length(),<span class="stringliteral">"beta0 and betac are not compatible"</span>); |
| 322 | <a name="l00401"></a>00401 <span class="keywordflow">if</span> (_rv().<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>()>0){ |
| 323 | <a name="l00402"></a>00402 <a class="code" href="bdmerror_8h.html#7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a>( (_rv()._dsize()==dimension()) , <span class="stringliteral">"Size of rv does not match with beta"</span>); |
| 324 | <a name="l00403"></a>00403 } |
| 325 | <a name="l00404"></a>00404 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = <a class="code" href="classbdm_1_1mDirich.html#44230d127f95c6da1032e4e5886204ab" title="cache of beta_i">_beta</a>.length(); |
| 326 | <a name="l00405"></a>00405 }; |
| 327 | <a name="l00406"></a>00406 }; |
| 328 | <a name="l00407"></a>00407 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(mDirich); |
| 329 | <a name="l00408"></a>00408 |
| 330 | <a name="l00410"></a><a class="code" href="classbdm_1_1multiBM.html">00410</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> |
| 331 | <a name="l00411"></a>00411 { |
| 332 | <a name="l00412"></a>00412 <span class="keyword">protected</span>: |
| 333 | <a name="l00414"></a><a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a">00414</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>; |
| 334 | <a name="l00416"></a><a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25">00416</a> vec &<a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a>; |
| 335 | <a name="l00417"></a>00417 <span class="keyword">public</span>: |
| 336 | <a name="l00419"></a><a class="code" href="classbdm_1_1multiBM.html#c4dd6d9522a8a605776d21bac9bd9daf">00419</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()) { |
| 337 | <a name="l00420"></a>00420 <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>();} |
| 338 | <a name="l00421"></a>00421 <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;} |
| 339 | <a name="l00422"></a>00422 } |
| 340 | <a name="l00424"></a><a class="code" href="classbdm_1_1multiBM.html#c4378cf8037f6bed29c74eea63344b31">00424</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()) {} |
| 341 | <a name="l00426"></a><a class="code" href="classbdm_1_1multiBM.html#dbe6b90d410dc062a233d1dc09eeba52">00426</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>;} |
| 342 | <a name="l00427"></a><a class="code" href="classbdm_1_1multiBM.html#1e4bf41b61937fd80f34049742e23f95">00427</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) { |
| 343 | <a name="l00428"></a>00428 <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>();} |
| 344 | <a name="l00429"></a>00429 <a class="code" href="classbdm_1_1multiBM.html#044263356944c92209eecd39a5187d25" title="Pointer inside est to sufficient statistics.">beta</a> += dt; |
| 345 | <a name="l00430"></a>00430 <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>;} |
| 346 | <a name="l00431"></a>00431 } |
| 347 | <a name="l00432"></a><a class="code" href="classbdm_1_1multiBM.html#e157b607c1e3fa91d42aeea44458e2bf">00432</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>{ |
| 348 | <a name="l00433"></a>00433 <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>); |
| 349 | <a name="l00434"></a>00434 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>(); |
| 350 | <a name="l00435"></a>00435 |
| 351 | <a name="l00436"></a>00436 <span class="keywordtype">double</span> lll; |
| 352 | <a name="l00437"></a>00437 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1BMEF.html#1331865e10fb1ccef65bb4c47fa3be64" title="forgetting factor">frg</a> < 1.0) |
| 353 | <a name="l00438"></a>00438 {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>();} |
| 354 | <a name="l00439"></a>00439 <span class="keywordflow">else</span> |
| 355 | <a name="l00440"></a>00440 <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>;} |
| 356 | <a name="l00441"></a>00441 <span class="keywordflow">else</span>{lll = pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>();} |
| 357 | <a name="l00442"></a>00442 |
| 358 | <a name="l00443"></a>00443 beta += dt; |
| 359 | <a name="l00444"></a>00444 <span class="keywordflow">return</span> pred.<a class="code" href="classbdm_1_1eDirich.html#279a99f6266c82fe2273e83841f19eb2" title="logarithm of the normalizing constant, ">lognc</a>() - lll; |
| 360 | <a name="l00445"></a>00445 } |
| 361 | <a name="l00446"></a><a class="code" href="classbdm_1_1multiBM.html#aaeb18c989088feb8d26d300e4971732">00446</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) { |
| 362 | <a name="l00447"></a>00447 <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); |
| 363 | <a name="l00448"></a>00448 <span class="comment">// sum(beta) should be equal to sum(B.beta)</span> |
| 364 | <a name="l00449"></a>00449 <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> |
| 365 | <a name="l00450"></a>00450 <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>)); |
| 366 | <a name="l00451"></a>00451 <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>();} |
| 367 | <a name="l00452"></a>00452 } |
| 368 | <a name="l00454"></a><a class="code" href="classbdm_1_1multiBM.html#31ff93f89473f099e489b9e1dc8d9513">00454</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1eDirich.html" title="Dirichlet posterior density.">eDirich</a>& <a class="code" href="classbdm_1_1multiBM.html#31ff93f89473f099e489b9e1dc8d9513" title="reimplemnetation of BM::posterior()">posterior</a>()<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>;}; |
| 369 | <a name="l00456"></a><a class="code" href="classbdm_1_1multiBM.html#7a480eace4446661bacca94c57499f01">00456</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1multiBM.html#7a480eace4446661bacca94c57499f01" title="constructor function">set_parameters</a> (<span class="keyword">const</span> vec &beta0) { |
| 370 | <a name="l00457"></a>00457 <a class="code" href="classbdm_1_1multiBM.html#9ecc6878abbd20eb8d8e43b6ab3f941a" title="Conjugate prior and posterior.">est</a>.set_parameters (beta0); |
| 371 | <a name="l00458"></a>00458 <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>();} |
| 372 | <a name="l00459"></a>00459 } |
| 373 | <a name="l00460"></a>00460 }; |
| 374 | <a name="l00461"></a>00461 |
| 375 | <a name="l00471"></a><a class="code" href="classbdm_1_1egamma.html">00471</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> |
| 376 | <a name="l00472"></a>00472 { |
| 377 | <a name="l00473"></a>00473 <span class="keyword">protected</span>: |
| 378 | <a name="l00475"></a><a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa">00475</a> vec <a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>; |
| 379 | <a name="l00477"></a><a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1">00477</a> vec <a class="code" href="classbdm_1_1egamma.html#457bfb1ccb2057df85073e519a15ccc1" title="Vector .">beta</a>; |
| 380 | <a name="l00478"></a>00478 <span class="keyword">public</span> : |
| 381 | <a name="l00481"></a>00481 <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) {}; |
| 382 | <a name="l00482"></a>00482 <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);}; |
| 383 | <a name="l00483"></a>00483 <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();}; |
| 384 | <a name="l00485"></a>00485 |
| 385 | <a name="l00486"></a>00486 vec <a class="code" href="classbdm_1_1egamma.html#6ed82f0fd05f6002487256d8e75a0bbd" title="Returns a sample, from density .">sample</a>() <span class="keyword">const</span>; |
| 386 | <a name="l00487"></a>00487 <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1egamma.html#a8e11e5a580ff42a1b205974c60768c6" title="Evaluate normalized log-probability.">evallog</a> (<span class="keyword">const</span> vec &val) <span class="keyword">const</span>; |
| 387 | <a name="l00488"></a>00488 <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>; |
| 388 | <a name="l00490"></a><a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed">00490</a> vec& <a class="code" href="classbdm_1_1egamma.html#0865cb3d6339fdc7410806cf70a329ed" title="Returns pointer to internal alpha. 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>;} |
| 389 | <a name="l00492"></a><a class="code" href="classbdm_1_1egamma.html#c42cadd9cbd344caaa69b0b433cd16ca">00492</a> vec& <a class="code" href="classbdm_1_1egamma.html#c42cadd9cbd344caaa69b0b433cd16ca" title="Returns pointer to internal beta. Potentially dengerous: use with care!">_beta</a>() {<span class="keywordflow">return</span> beta;} |
| 390 | <a name="l00493"></a><a class="code" href="classbdm_1_1egamma.html#49d256c42cce14c6faa56ec242b57e85">00493</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);} |
| 391 | <a name="l00494"></a><a class="code" href="classbdm_1_1egamma.html#36986cc01917cd0796fadc17125bdec1">00494</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)); } |
| 392 | <a name="l00495"></a>00495 |
| 393 | <a name="l00506"></a><a class="code" href="classbdm_1_1egamma.html#8a6fd1a1c0190f3e0d95a2a1f99aafc1">00506</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egamma.html#8a6fd1a1c0190f3e0d95a2a1f99aafc1">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
| 394 | <a name="l00507"></a>00507 <a class="code" href="classbdm_1_1egamma.html#8a6fd1a1c0190f3e0d95a2a1f99aafc1">epdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv</span> |
| 395 | <a name="l00508"></a>00508 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>, <span class="keyword">set</span>, <span class="stringliteral">"alpha"</span>, UI::compulsory); |
| 396 | <a name="l00509"></a>00509 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (beta, <span class="keyword">set</span>, <span class="stringliteral">"beta"</span>, UI::compulsory); |
| 397 | <a name="l00510"></a>00510 <a class="code" href="classbdm_1_1egamma.html#c3a8d8ae8ba79d0fb35036711fa7d127" title="This method TODO.">validate</a>(); |
| 398 | <a name="l00511"></a>00511 } |
| 399 | <a name="l00512"></a><a class="code" href="classbdm_1_1egamma.html#c3a8d8ae8ba79d0fb35036711fa7d127">00512</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1egamma.html#c3a8d8ae8ba79d0fb35036711fa7d127" title="This method TODO.">validate</a>() { |
| 400 | <a name="l00513"></a>00513 <a class="code" href="bdmerror_8h.html#7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<a class="code" href="classbdm_1_1egamma.html#0901ec983e66b8337aaa506e13b122fa" title="Vector .">alpha</a>.length() == beta.length(), <span class="stringliteral">"parameters do not match"</span>); |
| 401 | <a name="l00514"></a>00514 <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(); |
| 402 | <a name="l00515"></a>00515 } |
| 403 | <a name="l00516"></a>00516 }; |
| 404 | <a name="l00517"></a>00517 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a> (egamma); |
| 405 | <a name="l00518"></a>00518 SHAREDPTR ( egamma ); |
| 406 | <a name="l00519"></a>00519 |
| 407 | <a name="l00536"></a><a class="code" href="classbdm_1_1eigamma.html">00536</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> |
| 408 | <a name="l00537"></a>00537 { |
| 409 | <a name="l00538"></a>00538 <span class="keyword">protected</span>: |
| 410 | <a name="l00539"></a>00539 <span class="keyword">public</span> : |
| 411 | <a name="l00544"></a>00544 |
| 412 | <a name="l00545"></a><a class="code" href="classbdm_1_1eigamma.html#3aff7bf25ddac27731c60826fcfd878f">00545</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>();}; |
| 413 | <a name="l00547"></a><a class="code" href="classbdm_1_1eigamma.html#46cecb295edbabd28120cb0f6f572bcb">00547</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);} |
| 414 | <a name="l00548"></a><a class="code" href="classbdm_1_1eigamma.html#c2c696f8c668e9f65392c9449f6a5133">00548</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);} |
| 415 | <a name="l00549"></a>00549 }; |
| 416 | <a name="l00550"></a>00550 <span class="comment">/*</span> |
| 417 | <a name="l00552"></a>00552 <span class="comment">class emix : public epdf {</span> |
| 418 | <a name="l00553"></a>00553 <span class="comment">protected:</span> |
| 419 | <a name="l00554"></a>00554 <span class="comment"> int n;</span> |
| 420 | <a name="l00555"></a>00555 <span class="comment"> vec &w;</span> |
| 421 | <a name="l00556"></a>00556 <span class="comment"> Array<epdf*> Coms;</span> |
| 422 | <a name="l00557"></a>00557 <span class="comment">public:</span> |
| 423 | <a name="l00559"></a>00559 <span class="comment"> emix ( const RV &rv, vec &w0): epdf(rv), n(w0.length()), w(w0), Coms(n) {};</span> |
| 424 | <a name="l00560"></a>00560 <span class="comment"> void set_parameters( int &i, double wi, epdf* ep){w(i)=wi;Coms(i)=ep;}</span> |
| 425 | <a name="l00561"></a>00561 <span class="comment"> vec mean(){vec pom; for(int i=0;i<n;i++){pom+=Coms(i)->mean()*w(i);} return pom;};</span> |
| 426 | <a name="l00562"></a>00562 <span class="comment">};</span> |
| 427 | <a name="l00563"></a>00563 <span class="comment">*/</span> |
| 428 | <a name="l00564"></a>00564 |
| 429 | <a name="l00566"></a>00566 |
| 430 | <a name="l00567"></a><a class="code" href="classbdm_1_1euni.html">00567</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> |
| 431 | <a name="l00568"></a>00568 { |
| 432 | <a name="l00569"></a>00569 <span class="keyword">protected</span>: |
| 433 | <a name="l00571"></a><a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32">00571</a> vec <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>; |
| 434 | <a name="l00573"></a><a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1">00573</a> vec <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>; |
| 435 | <a name="l00575"></a><a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c">00575</a> vec <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>; |
| 436 | <a name="l00577"></a><a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20">00577</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#31bb13e8449a8eff35246d46dae35c20" title="normalizing coefficients">nk</a>; |
| 437 | <a name="l00579"></a><a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476">00579</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
| 438 | <a name="l00580"></a>00580 <span class="keyword">public</span>: |
| 439 | <a name="l00583"></a>00583 <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> () {} |
| 440 | <a name="l00584"></a>00584 <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);} |
| 441 | <a name="l00585"></a>00585 <span class="keywordtype">void</span> set_parameters (<span class="keyword">const</span> vec &low0, <span class="keyword">const</span> vec &high0) { |
| 442 | <a name="l00586"></a>00586 <a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a> = high0 - low0; |
| 443 | <a name="l00587"></a>00587 <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a> = low0; |
| 444 | <a name="l00588"></a>00588 <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a> = high0; |
| 445 | <a name="l00589"></a>00589 <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>); |
| 446 | <a name="l00590"></a>00590 <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>); |
| 447 | <a name="l00591"></a>00591 <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(); |
| 448 | <a name="l00592"></a>00592 } |
| 449 | <a name="l00594"></a>00594 |
| 450 | <a name="l00595"></a><a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81">00595</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1euni.html#caa07b8307bd793d5339d6583e0aba81" title="Compute log-probability of argument val In case the argument is out of suport return...">evallog</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
| 451 | <a name="l00596"></a>00596 <span class="keywordflow">if</span> (any (val < <a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>) && any (val > <a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>)) {<span class="keywordflow">return</span> inf;} |
| 452 | <a name="l00597"></a>00597 <span class="keywordflow">else</span> <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1euni.html#3e63be48dd58659663ca60cd18700476" title="cache of log( nk )">lnk</a>; |
| 453 | <a name="l00598"></a>00598 } |
| 454 | <a name="l00599"></a><a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194">00599</a> vec <a class="code" href="classbdm_1_1euni.html#fc5df80359ead2918384b2004ce67194" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
| 455 | <a name="l00600"></a>00600 vec smp (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
| 456 | <a name="l00601"></a>00601 <span class="preprocessor">#pragma omp critical</span> |
| 457 | <a name="l00602"></a>00602 <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); |
| 458 | <a name="l00603"></a>00603 <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); |
| 459 | <a name="l00604"></a>00604 } |
| 460 | <a name="l00606"></a><a class="code" href="classbdm_1_1euni.html#46caa8c13aba2e6228f964208918b226">00606</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;} |
| 461 | <a name="l00607"></a><a class="code" href="classbdm_1_1euni.html#951f932155111f6053c980f672b4c22c">00607</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;} |
| 462 | <a name="l00618"></a><a class="code" href="classbdm_1_1euni.html#77f5fef1f006fe056066da23b9e5f042">00618</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1euni.html#77f5fef1f006fe056066da23b9e5f042">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
| 463 | <a name="l00619"></a>00619 <a class="code" href="classbdm_1_1euni.html#77f5fef1f006fe056066da23b9e5f042">epdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv and rvc</span> |
| 464 | <a name="l00620"></a>00620 |
| 465 | <a name="l00621"></a>00621 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>, <span class="keyword">set</span>, <span class="stringliteral">"high"</span>, UI::compulsory); |
| 466 | <a name="l00622"></a>00622 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>, <span class="keyword">set</span>, <span class="stringliteral">"low"</span>, UI::compulsory); |
| 467 | <a name="l00623"></a>00623 set_parameters(<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>,<a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>); |
| 468 | <a name="l00624"></a>00624 <a class="code" href="classbdm_1_1euni.html#70c5a7dcf7cb0f7ea83b9165f31868e9" title="This method TODO.">validate</a>(); |
| 469 | <a name="l00625"></a>00625 } |
| 470 | <a name="l00626"></a><a class="code" href="classbdm_1_1euni.html#70c5a7dcf7cb0f7ea83b9165f31868e9">00626</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1euni.html#70c5a7dcf7cb0f7ea83b9165f31868e9" title="This method TODO.">validate</a>() { |
| 471 | <a name="l00627"></a>00627 <a class="code" href="bdmerror_8h.html#7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a>(<a class="code" href="classbdm_1_1euni.html#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>.length()==<a class="code" href="classbdm_1_1euni.html#ff7ce6a2ef5ef0015bbd1398bed12f32" title="lower bound on support">low</a>.length(), <span class="stringliteral">"Incompatible high and low vectors"</span>); |
| 472 | <a name="l00628"></a>00628 <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#cfad2dea4a62db6872bda8abd75f0de1" title="upper bound on support">high</a>.length(); |
| 473 | <a name="l00629"></a>00629 <a class="code" href="bdmerror_8h.html#7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (min (<a class="code" href="classbdm_1_1euni.html#d3c27e331f90c754d80228108de8ed4c" title="internal">distance</a>) > 0.0, <span class="stringliteral">"bad support"</span>); |
| 474 | <a name="l00630"></a>00630 } |
| 475 | <a name="l00631"></a>00631 }; |
| 476 | <a name="l00632"></a>00632 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(euni); |
| 477 | <a name="l00633"></a>00633 |
| 478 | <a name="l00639"></a>00639 <span class="keyword">template</span> < <span class="keyword">class</span> sq_T, <span class="keyword">template</span> <<span class="keyword">typename</span>> <span class="keyword">class </span>TEpdf = enorm > |
| 479 | <a name="l00640"></a><a class="code" href="classbdm_1_1mlnorm.html">00640</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< TEpdf<sq_T> > |
| 480 | <a name="l00641"></a>00641 { |
| 481 | <a name="l00642"></a>00642 <span class="keyword">protected</span>: |
| 482 | <a name="l00644"></a><a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42">00644</a> mat <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>; |
| 483 | <a name="l00646"></a><a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6">00646</a> vec <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>; |
| 484 | <a name="l00647"></a>00647 <span class="comment">// vec& _mu; //cached epdf.mu; !!!!!! WHY NOT?</span> |
| 485 | <a name="l00648"></a>00648 <span class="keyword">public</span>: |
| 486 | <a name="l00651"></a>00651 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< TEpdf<sq_T> >() {}; |
| 487 | <a name="l00652"></a>00652 <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a> (<span class="keyword">const</span> mat &<a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &R) : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< TEpdf<sq_T> >() { |
| 488 | <a name="l00653"></a>00653 <a class="code" href="classbdm_1_1mlnorm.html#04f7c6cda7b2f95161dd5fbcf15d1fd5" title="Set A and R.">set_parameters</a> (A, mu0, R); |
| 489 | <a name="l00654"></a>00654 } |
| 490 | <a name="l00655"></a>00655 |
| 491 | <a name="l00657"></a><a class="code" href="classbdm_1_1mlnorm.html#04f7c6cda7b2f95161dd5fbcf15d1fd5">00657</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#04f7c6cda7b2f95161dd5fbcf15d1fd5" title="Set A and R.">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) { |
| 492 | <a name="l00658"></a>00658 this-><a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.set_parameters (zeros (A0.rows()), R0); |
| 493 | <a name="l00659"></a>00659 <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> = A0; |
| 494 | <a name="l00660"></a>00660 <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a> = mu0; |
| 495 | <a name="l00661"></a>00661 this-><a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = A0.cols(); |
| 496 | <a name="l00662"></a>00662 } |
| 497 | <a name="l00665"></a><a class="code" href="classbdm_1_1mlnorm.html#c2895ae549ee76d961be98d7061bd110">00665</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#c2895ae549ee76d961be98d7061bd110">condition</a> (<span class="keyword">const</span> vec &cond) { |
| 498 | <a name="l00666"></a>00666 this-><a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._mu() = <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> * cond + <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>; |
| 499 | <a name="l00667"></a>00667 <span class="comment">//R is already assigned;</span> |
| 500 | <a name="l00668"></a>00668 } |
| 501 | <a name="l00669"></a>00669 |
| 502 | <a name="l00671"></a><a class="code" href="classbdm_1_1mlnorm.html#f6b0b4b0b17271525ad02660a4087cf7">00671</a> <span class="keyword">const</span> vec& <a class="code" href="classbdm_1_1mlnorm.html#f6b0b4b0b17271525ad02660a4087cf7" title="access function">_mu_const</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>;} |
| 503 | <a name="l00673"></a><a class="code" href="classbdm_1_1mlnorm.html#55e1bd7fa70b852bd7fe50ce72fb8f23">00673</a> <span class="keyword">const</span> mat& <a class="code" href="classbdm_1_1mlnorm.html#55e1bd7fa70b852bd7fe50ce72fb8f23" title="access function">_A</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>;} |
| 504 | <a name="l00675"></a><a class="code" href="classbdm_1_1mlnorm.html#9af0714b7b29ab1162ebc3291b7c4a43">00675</a> mat <a class="code" href="classbdm_1_1mlnorm.html#9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> this-><a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._R().to_mat(); } |
| 505 | <a name="l00676"></a>00676 |
| 506 | <a name="l00678"></a>00678 <span class="keyword">template</span><<span class="keyword">typename</span> sq_M> |
| 507 | <a name="l00679"></a>00679 <span class="keyword">friend</span> std::ostream &operator<< (std::ostream &os, mlnorm<sq_M, enorm> &ml); |
| 508 | <a name="l00680"></a>00680 |
| 509 | <a name="l00691"></a><a class="code" href="classbdm_1_1mlnorm.html#52980f13d80162d00b30d5864343f564">00691</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#52980f13d80162d00b30d5864343f564">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
| 510 | <a name="l00692"></a>00692 <a class="code" href="classbdm_1_1mlnorm.html#52980f13d80162d00b30d5864343f564">mpdf::from_setting</a> (<span class="keyword">set</span>); |
| 511 | <a name="l00693"></a>00693 |
| 512 | <a name="l00694"></a>00694 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>, <span class="keyword">set</span>, <span class="stringliteral">"A"</span>, UI::compulsory); |
| 513 | <a name="l00695"></a>00695 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>, <span class="keyword">set</span>, <span class="stringliteral">"const"</span>, UI::compulsory); |
| 514 | <a name="l00696"></a>00696 mat R0; |
| 515 | <a name="l00697"></a>00697 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (R0, <span class="keyword">set</span>, <span class="stringliteral">"R"</span>, UI::compulsory); |
| 516 | <a name="l00698"></a>00698 <a class="code" href="classbdm_1_1mlnorm.html#04f7c6cda7b2f95161dd5fbcf15d1fd5" title="Set A and R.">set_parameters</a> (<a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>, <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>, R0); |
| 517 | <a name="l00699"></a>00699 <a class="code" href="classbdm_1_1mlnorm.html#cafcb3fb9bad8ff5fd51897f6eb10924" title="This method TODO.">validate</a>(); |
| 518 | <a name="l00700"></a>00700 }; |
| 519 | <a name="l00701"></a><a class="code" href="classbdm_1_1mlnorm.html#cafcb3fb9bad8ff5fd51897f6eb10924">00701</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlnorm.html#cafcb3fb9bad8ff5fd51897f6eb10924" title="This method TODO.">validate</a>() { |
| 520 | <a name="l00702"></a>00702 <a class="code" href="bdmerror_8h.html#7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>.rows() == <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>.length(), <span class="stringliteral">"mlnorm: A vs. mu mismatch"</span>); |
| 521 | <a name="l00703"></a>00703 <a class="code" href="bdmerror_8h.html#7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>.rows() == <a class="code" href="classbdm_1_1mlnorm.html#9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a>().rows(), <span class="stringliteral">"mlnorm: A vs. R mismatch"</span>); |
| 522 | <a name="l00704"></a>00704 |
| 523 | <a name="l00705"></a>00705 } |
| 524 | <a name="l00706"></a>00706 }; |
| 525 | <a name="l00707"></a>00707 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mlnorm,ldmat); |
| 526 | <a name="l00708"></a>00708 SHAREDPTR2 ( mlnorm, ldmat ); |
| 527 | <a name="l00709"></a>00709 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mlnorm,fsqmat); |
| 528 | <a name="l00710"></a>00710 SHAREDPTR2 ( mlnorm, fsqmat ); |
| 529 | <a name="l00711"></a>00711 <a class="code" href="user__info_8h.html#b06f1e7c44a8306e321f62a0099210b9" title="Variant of UIREGISTER for templated classes.">UIREGISTER2</a> (mlnorm, chmat); |
| 530 | <a name="l00712"></a>00712 SHAREDPTR2 ( mlnorm, chmat ); |
| 531 | <a name="l00713"></a>00713 |
| 532 | <a name="l00715"></a>00715 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 533 | <a name="l00716"></a><a class="code" href="classbdm_1_1mgnorm.html">00716</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1mgnorm.html" title="Mpdf with general function for mean value.">mgnorm</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a>< enorm< sq_T > > |
| 534 | <a name="l00717"></a>00717 { |
| 535 | <a name="l00718"></a>00718 <span class="keyword">private</span>: |
| 536 | <a name="l00719"></a>00719 <span class="comment">// vec &mu; WHY NOT?</span> |
| 537 | <a name="l00720"></a>00720 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<fnc></a> g; |
| 538 | <a name="l00721"></a>00721 |
| 539 | <a name="l00722"></a>00722 <span class="keyword">public</span>: |
| 540 | <a name="l00724"></a><a class="code" href="classbdm_1_1mgnorm.html#1b014915d74470d3efab74e07cacb97d">00724</a> <a class="code" href="classbdm_1_1mgnorm.html#1b014915d74470d3efab74e07cacb97d" title="default constructor">mgnorm</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a><sq_T> >() { } |
| 541 | <a name="l00726"></a>00726 <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#b736332d20e418bf50d45836e129f339" title="set mean function">set_parameters</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<fnc></a> &g0, <span class="keyword">const</span> sq_T &R0); |
| 542 | <a name="l00727"></a>00727 <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#b31d63472cf6a1030cd8dbd8094c1f6d" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">condition</a> (<span class="keyword">const</span> vec &cond); |
570 | | <a name="l00777"></a><a class="code" href="classbdm_1_1mlstudent.html">00777</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, enorm> |
571 | | <a name="l00778"></a>00778 { |
572 | | <a name="l00779"></a>00779 <span class="keyword">protected</span>: |
573 | | <a name="l00781"></a><a class="code" href="classbdm_1_1mlstudent.html#a41595144a79594acbe288c6b59412657">00781</a> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1mlstudent.html#a41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>; |
574 | | <a name="l00783"></a><a class="code" href="classbdm_1_1mlstudent.html#a72e9bda4d6684e07faafc4b2192daf39">00783</a> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &<a class="code" href="classbdm_1_1mlnorm.html#a9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a>; |
575 | | <a name="l00785"></a><a class="code" href="classbdm_1_1mlstudent.html#a1c063ad6cb6e079ee11bc4128c2c9fe8">00785</a> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1mlstudent.html#a1c063ad6cb6e079ee11bc4128c2c9fe8" title="Variable .">Re</a>; |
576 | | <a name="l00786"></a>00786 <span class="keyword">public</span>: |
577 | | <a name="l00787"></a>00787 <a class="code" href="classbdm_1_1mlstudent.html">mlstudent</a> () : <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a><<a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>, <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a>> (), |
578 | | <a name="l00788"></a>00788 <a class="code" href="classbdm_1_1mlstudent.html#a41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a> (), <a class="code" href="classbdm_1_1mlnorm.html#a9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1mlnorm.html#a9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a>()) {} |
579 | | <a name="l00790"></a><a class="code" href="classbdm_1_1mlstudent.html#a4cdf79aac1b2165c0290e73810a0e4a3">00790</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#a4cdf79aac1b2165c0290e73810a0e4a3" title="constructor function">set_parameters</a> (<span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &R0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& Lambda0) { |
580 | | <a name="l00791"></a>00791 <a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.set_parameters (mu0, R0);<span class="comment">// was Lambda, why?</span> |
581 | | <a name="l00792"></a>00792 <a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> = A0; |
582 | | <a name="l00793"></a>00793 <a class="code" href="classbdm_1_1mlnorm.html#a831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a> = mu0; |
583 | | <a name="l00794"></a>00794 <a class="code" href="classbdm_1_1mlstudent.html#a1c063ad6cb6e079ee11bc4128c2c9fe8" title="Variable .">Re</a> = R0; |
584 | | <a name="l00795"></a>00795 <a class="code" href="classbdm_1_1mlstudent.html#a41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a> = Lambda0; |
585 | | <a name="l00796"></a>00796 } |
586 | | <a name="l00797"></a><a class="code" href="classbdm_1_1mlstudent.html#aefd37560585c8613897f30d3c2f58d0d">00797</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#aefd37560585c8613897f30d3c2f58d0d">condition</a> (<span class="keyword">const</span> vec &cond) { |
587 | | <a name="l00798"></a>00798 <a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._mu() = <a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> * cond + <a class="code" href="classbdm_1_1mlnorm.html#a831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>; |
588 | | <a name="l00799"></a>00799 <span class="keywordtype">double</span> zeta; |
589 | | <a name="l00800"></a>00800 <span class="comment">//ugly hack!</span> |
590 | | <a name="l00801"></a>00801 <span class="keywordflow">if</span> ( (cond.length() + 1) == <a class="code" href="classbdm_1_1mlstudent.html#a41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>.<a class="code" href="classbdm_1_1sqmat.html#a73e639221343dcce76c3305524d67590" title="Reimplementing common functions of mat: rows().">rows</a>()) { |
591 | | <a name="l00802"></a>00802 zeta = <a class="code" href="classbdm_1_1mlstudent.html#a41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>.<a class="code" href="classbdm_1_1ldmat.html#af743de194aadb8515cf18226fadf365f" title="Evaluates quadratic form ;.">invqform</a> (concat (cond, vec_1 (1.0))); |
592 | | <a name="l00803"></a>00803 } <span class="keywordflow">else</span> { |
593 | | <a name="l00804"></a>00804 zeta = <a class="code" href="classbdm_1_1mlstudent.html#a41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>.<a class="code" href="classbdm_1_1ldmat.html#af743de194aadb8515cf18226fadf365f" title="Evaluates quadratic form ;.">invqform</a> (cond); |
594 | | <a name="l00805"></a>00805 } |
595 | | <a name="l00806"></a>00806 <a class="code" href="classbdm_1_1mlnorm.html#a9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a> = <a class="code" href="classbdm_1_1mlstudent.html#a1c063ad6cb6e079ee11bc4128c2c9fe8" title="Variable .">Re</a>; |
596 | | <a name="l00807"></a>00807 <a class="code" href="classbdm_1_1mlnorm.html#a9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a> *= (1 + zeta);<span class="comment">// / ( nu ); << nu is in Re!!!!!!</span> |
597 | | <a name="l00808"></a>00808 }; |
598 | | <a name="l00809"></a>00809 |
599 | | <a name="l00810"></a><a class="code" href="classbdm_1_1mlstudent.html#a55869e091bca0e2af1c3667c05ba6261">00810</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#a55869e091bca0e2af1c3667c05ba6261" title="This method TODO.">validate</a>() { |
600 | | <a name="l00811"></a>00811 <a class="code" href="bdmerror_8h.html#a7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>.rows() == <a class="code" href="classbdm_1_1mlnorm.html#a831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>.length(), <span class="stringliteral">"mlstudent: A vs. mu mismatch"</span>); |
601 | | <a name="l00812"></a>00812 <a class="code" href="bdmerror_8h.html#a7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<a class="code" href="classbdm_1_1mlnorm.html#a9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a>.rows() == <a class="code" href="classbdm_1_1mlnorm.html#ac71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>.rows(), <span class="stringliteral">"mlstudent: A vs. R mismatch"</span>); |
602 | | <a name="l00813"></a>00813 |
603 | | <a name="l00814"></a>00814 } |
604 | | <a name="l00815"></a>00815 }; |
605 | | <a name="l00825"></a><a class="code" href="classbdm_1_1mgamma.html">00825</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_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><egamma> |
606 | | <a name="l00826"></a>00826 { |
607 | | <a name="l00827"></a>00827 <span class="keyword">protected</span>: |
608 | | <a name="l00828"></a>00828 |
609 | | <a name="l00830"></a><a class="code" href="classbdm_1_1mgamma.html#ab20cf88cca1fe9b0b8f2a412608bfd09">00830</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#ab20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>; |
610 | | <a name="l00831"></a>00831 |
611 | | <a name="l00833"></a><a class="code" href="classbdm_1_1mgamma.html#a3d95f4dde9214ff6dba265e18af60312">00833</a> vec &<a class="code" href="classbdm_1_1mgamma.html#a3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a>; |
612 | | <a name="l00834"></a>00834 |
613 | | <a name="l00835"></a>00835 <span class="keyword">public</span>: |
614 | | <a name="l00837"></a><a class="code" href="classbdm_1_1mgamma.html#a1a9dc8661e5b214a8185d6e6b9956eb1">00837</a> <a class="code" href="classbdm_1_1mgamma.html#a1a9dc8661e5b214a8185d6e6b9956eb1" title="Constructor.">mgamma</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a>>(), <a class="code" href="classbdm_1_1mgamma.html#ab20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a> (0), |
615 | | <a name="l00838"></a>00838 <a class="code" href="classbdm_1_1mgamma.html#a3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1mgamma.html#a3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a>()) { |
616 | | <a name="l00839"></a>00839 } |
617 | | <a name="l00840"></a>00840 |
618 | | <a name="l00842"></a>00842 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#aa0f21c2557b233a85838b497d040ab14" title="Set value of k.">set_parameters</a> (<span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#ab20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, <span class="keyword">const</span> vec &beta0); |
619 | | <a name="l00843"></a>00843 |
620 | | <a name="l00844"></a><a class="code" href="classbdm_1_1mgamma.html#a8996500f1885e39cde30221b20900bff">00844</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#a8996500f1885e39cde30221b20900bff" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">condition</a> (<span class="keyword">const</span> vec &val) {<a class="code" href="classbdm_1_1mgamma.html#a3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a> = <a class="code" href="classbdm_1_1mgamma.html#ab20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a> / val;}; |
621 | | <a name="l00856"></a><a class="code" href="classbdm_1_1mgamma.html#ada2af0f327e5452bee71d1bf97452ae4">00856</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#ada2af0f327e5452bee71d1bf97452ae4">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
622 | | <a name="l00857"></a>00857 <a class="code" href="classbdm_1_1mgamma.html#ada2af0f327e5452bee71d1bf97452ae4">mpdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv and rvc</span> |
623 | | <a name="l00858"></a>00858 vec betatmp; <span class="comment">// ugly but necessary</span> |
624 | | <a name="l00859"></a>00859 <a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (betatmp, <span class="keyword">set</span>, <span class="stringliteral">"beta"</span>, UI::compulsory); |
625 | | <a name="l00860"></a>00860 <a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mgamma.html#ab20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, <span class="keyword">set</span>, <span class="stringliteral">"k"</span>, UI::compulsory); |
626 | | <a name="l00861"></a>00861 <a class="code" href="classbdm_1_1mgamma.html#aa0f21c2557b233a85838b497d040ab14" title="Set value of k.">set_parameters</a> (<a class="code" href="classbdm_1_1mgamma.html#ab20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, betatmp); |
627 | | <a name="l00862"></a>00862 } |
628 | | <a name="l00863"></a>00863 }; |
629 | | <a name="l00864"></a>00864 <a class="code" href="user__info_8h.html#a4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a> (mgamma); |
630 | | <a name="l00865"></a>00865 SHAREDPTR (mgamma); |
631 | | <a name="l00866"></a>00866 |
632 | | <a name="l00876"></a><a class="code" href="classbdm_1_1migamma.html">00876</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_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><eigamma> |
633 | | <a name="l00877"></a>00877 { |
634 | | <a name="l00878"></a>00878 <span class="keyword">protected</span>: |
635 | | <a name="l00880"></a><a class="code" href="classbdm_1_1migamma.html#adc56bc9da542e0103ec16b9be8e5e38c">00880</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma.html#adc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>; |
636 | | <a name="l00881"></a>00881 |
637 | | <a name="l00883"></a><a class="code" href="classbdm_1_1migamma.html#ac9847093da59a9ba0ebb68d2c592f5dc">00883</a> vec &<a class="code" href="classbdm_1_1migamma.html#ac9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a>; |
638 | | <a name="l00884"></a>00884 |
639 | | <a name="l00886"></a><a class="code" href="classbdm_1_1migamma.html#a0d854c047001b5465cf1ba21f52904b5">00886</a> vec &<a class="code" href="classbdm_1_1migamma.html#a0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a>; |
640 | | <a name="l00887"></a>00887 |
641 | | <a name="l00888"></a>00888 <span class="keyword">public</span>: |
642 | | <a name="l00891"></a>00891 <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a>>(), |
643 | | <a name="l00892"></a>00892 <a class="code" href="classbdm_1_1migamma.html#adc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a> (0), |
644 | | <a name="l00893"></a>00893 <a class="code" href="classbdm_1_1migamma.html#ac9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1migamma.html#ac9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a>()), |
645 | | <a name="l00894"></a>00894 <a class="code" href="classbdm_1_1migamma.html#a0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1migamma.html#a0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a>()) { |
646 | | <a name="l00895"></a>00895 } |
647 | | <a name="l00896"></a>00896 |
648 | | <a name="l00897"></a>00897 <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_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a>>(), |
649 | | <a name="l00898"></a>00898 <a class="code" href="classbdm_1_1migamma.html#adc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a> (0), |
650 | | <a name="l00899"></a>00899 <a class="code" href="classbdm_1_1migamma.html#ac9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1migamma.html#ac9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a>()), |
651 | | <a name="l00900"></a>00900 <a class="code" href="classbdm_1_1migamma.html#a0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1migamma.html#a0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a>()) { |
652 | | <a name="l00901"></a>00901 } |
653 | | <a name="l00903"></a>00903 |
654 | | <a name="l00905"></a><a class="code" href="classbdm_1_1migamma.html#a8b10ab922e2a7bae2fb6bb3efc7b6151">00905</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma.html#a8b10ab922e2a7bae2fb6bb3efc7b6151" title="Set value of k.">set_parameters</a> (<span class="keywordtype">int</span> len, <span class="keywordtype">double</span> k0) { |
655 | | <a name="l00906"></a>00906 <a class="code" href="classbdm_1_1migamma.html#adc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a> = k0; |
656 | | <a name="l00907"></a>00907 <a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.set_parameters ( (1.0 / (<a class="code" href="classbdm_1_1migamma.html#adc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>*<a class="code" href="classbdm_1_1migamma.html#adc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>) + 2.0) *ones (len) <span class="comment">/*alpha*/</span>, ones (len) <span class="comment">/*beta*/</span>); |
657 | | <a name="l00908"></a>00908 <a class="code" href="classbdm_1_1mpdf.html#a7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
658 | | <a name="l00909"></a>00909 }; |
659 | | <a name="l00910"></a><a class="code" href="classbdm_1_1migamma.html#a7a34b1e2e3aa2250d7c0ed7df1665b8c">00910</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma.html#a7a34b1e2e3aa2250d7c0ed7df1665b8c" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">condition</a> (<span class="keyword">const</span> vec &val) { |
660 | | <a name="l00911"></a>00911 <a class="code" href="classbdm_1_1migamma.html#a0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a> = elem_mult (val, (<a class="code" href="classbdm_1_1migamma.html#ac9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a> - 1.0)); |
661 | | <a name="l00912"></a>00912 }; |
662 | | <a name="l00913"></a>00913 }; |
663 | | <a name="l00914"></a>00914 |
| 567 | <a name="l00770"></a>00770 |
| 568 | <a name="l00778"></a><a class="code" href="classbdm_1_1mlstudent.html">00778</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, enorm> |
| 569 | <a name="l00779"></a>00779 { |
| 570 | <a name="l00780"></a>00780 <span class="keyword">protected</span>: |
| 571 | <a name="l00782"></a><a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657">00782</a> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>; |
| 572 | <a name="l00784"></a><a class="code" href="classbdm_1_1mlstudent.html#72e9bda4d6684e07faafc4b2192daf39">00784</a> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &<a class="code" href="classbdm_1_1mlnorm.html#9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a>; |
| 573 | <a name="l00786"></a><a class="code" href="classbdm_1_1mlstudent.html#1c063ad6cb6e079ee11bc4128c2c9fe8">00786</a> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> <a class="code" href="classbdm_1_1mlstudent.html#1c063ad6cb6e079ee11bc4128c2c9fe8" title="Variable .">Re</a>; |
| 574 | <a name="l00787"></a>00787 <span class="keyword">public</span>: |
| 575 | <a name="l00788"></a>00788 <a class="code" href="classbdm_1_1mlstudent.html">mlstudent</a> () : <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm</a><<a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>, <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a>> (), |
| 576 | <a name="l00789"></a>00789 <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a> (), <a class="code" href="classbdm_1_1mlnorm.html#9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1mlnorm.html#9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a>()) {} |
| 577 | <a name="l00791"></a><a class="code" href="classbdm_1_1mlstudent.html#4cdf79aac1b2165c0290e73810a0e4a3">00791</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#4cdf79aac1b2165c0290e73810a0e4a3" title="constructor function">set_parameters</a> (<span class="keyword">const</span> mat &A0, <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a> &R0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>& Lambda0) { |
| 578 | <a name="l00792"></a>00792 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.set_parameters (mu0, R0);<span class="comment">// was Lambda, why?</span> |
| 579 | <a name="l00793"></a>00793 <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> = A0; |
| 580 | <a name="l00794"></a>00794 <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a> = mu0; |
| 581 | <a name="l00795"></a>00795 <a class="code" href="classbdm_1_1mlstudent.html#1c063ad6cb6e079ee11bc4128c2c9fe8" title="Variable .">Re</a> = R0; |
| 582 | <a name="l00796"></a>00796 <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a> = Lambda0; |
| 583 | <a name="l00797"></a>00797 } |
| 584 | <a name="l00798"></a><a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">00798</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#efd37560585c8613897f30d3c2f58d0d">condition</a> (<span class="keyword">const</span> vec &cond) { |
| 585 | <a name="l00799"></a>00799 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._mu() = <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a> * cond + <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>; |
| 586 | <a name="l00800"></a>00800 <span class="keywordtype">double</span> zeta; |
| 587 | <a name="l00801"></a>00801 <span class="comment">//ugly hack!</span> |
| 588 | <a name="l00802"></a>00802 <span class="keywordflow">if</span> ( (cond.length() + 1) == <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>.<a class="code" href="classbdm_1_1sqmat.html#73e639221343dcce76c3305524d67590" title="Reimplementing common functions of mat: rows().">rows</a>()) { |
| 589 | <a name="l00803"></a>00803 zeta = <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>.<a class="code" href="classbdm_1_1ldmat.html#f743de194aadb8515cf18226fadf365f" title="Evaluates quadratic form ;.">invqform</a> (concat (cond, vec_1 (1.0))); |
| 590 | <a name="l00804"></a>00804 } <span class="keywordflow">else</span> { |
| 591 | <a name="l00805"></a>00805 zeta = <a class="code" href="classbdm_1_1mlstudent.html#41595144a79594acbe288c6b59412657" title="Variable from theory.">Lambda</a>.<a class="code" href="classbdm_1_1ldmat.html#f743de194aadb8515cf18226fadf365f" title="Evaluates quadratic form ;.">invqform</a> (cond); |
| 592 | <a name="l00806"></a>00806 } |
| 593 | <a name="l00807"></a>00807 <a class="code" href="classbdm_1_1mlnorm.html#9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a> = <a class="code" href="classbdm_1_1mlstudent.html#1c063ad6cb6e079ee11bc4128c2c9fe8" title="Variable .">Re</a>; |
| 594 | <a name="l00808"></a>00808 <a class="code" href="classbdm_1_1mlnorm.html#9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a> *= (1 + zeta);<span class="comment">// / ( nu ); << nu is in Re!!!!!!</span> |
| 595 | <a name="l00809"></a>00809 }; |
| 596 | <a name="l00810"></a>00810 |
| 597 | <a name="l00811"></a><a class="code" href="classbdm_1_1mlstudent.html#55869e091bca0e2af1c3667c05ba6261">00811</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlstudent.html#55869e091bca0e2af1c3667c05ba6261" title="This method TODO.">validate</a>() { |
| 598 | <a name="l00812"></a>00812 <a class="code" href="bdmerror_8h.html#7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>.rows() == <a class="code" href="classbdm_1_1mlnorm.html#831b50121cad10aa03a16682bd0c3ed6" title="Constant additive term.">mu_const</a>.length(), <span class="stringliteral">"mlstudent: A vs. mu mismatch"</span>); |
| 599 | <a name="l00813"></a>00813 <a class="code" href="bdmerror_8h.html#7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<a class="code" href="classbdm_1_1mlnorm.html#9af0714b7b29ab1162ebc3291b7c4a43" title="access function">_R</a>.rows() == <a class="code" href="classbdm_1_1mlnorm.html#c71bbf59fc732beb2b459d7117bd6e42" title="Internal epdf that arise by conditioning on rvc.">A</a>.rows(), <span class="stringliteral">"mlstudent: A vs. R mismatch"</span>); |
| 600 | <a name="l00814"></a>00814 |
| 601 | <a name="l00815"></a>00815 } |
| 602 | <a name="l00816"></a>00816 }; |
| 603 | <a name="l00826"></a><a class="code" href="classbdm_1_1mgamma.html">00826</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_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><egamma> |
| 604 | <a name="l00827"></a>00827 { |
| 605 | <a name="l00828"></a>00828 <span class="keyword">protected</span>: |
| 606 | <a name="l00829"></a>00829 |
| 607 | <a name="l00831"></a><a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09">00831</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>; |
| 608 | <a name="l00832"></a>00832 |
| 609 | <a name="l00834"></a><a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312">00834</a> vec &<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a>; |
| 610 | <a name="l00835"></a>00835 |
| 611 | <a name="l00836"></a>00836 <span class="keyword">public</span>: |
| 612 | <a name="l00838"></a><a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1">00838</a> <a class="code" href="classbdm_1_1mgamma.html#1a9dc8661e5b214a8185d6e6b9956eb1" title="Constructor.">mgamma</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1egamma.html" title="Gamma posterior density.">egamma</a>>(), <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a> (0), |
| 613 | <a name="l00839"></a>00839 <a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a>()) { |
| 614 | <a name="l00840"></a>00840 } |
| 615 | <a name="l00841"></a>00841 |
| 616 | <a name="l00843"></a>00843 <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); |
| 617 | <a name="l00844"></a>00844 |
| 618 | <a name="l00845"></a><a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff">00845</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#8996500f1885e39cde30221b20900bff" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">condition</a> (<span class="keyword">const</span> vec &val) {<a class="code" href="classbdm_1_1mgamma.html#3d95f4dde9214ff6dba265e18af60312" title="cache of iepdf.beta">_beta</a> = <a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a> / val;}; |
| 619 | <a name="l00857"></a><a class="code" href="classbdm_1_1mgamma.html#da2af0f327e5452bee71d1bf97452ae4">00857</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgamma.html#da2af0f327e5452bee71d1bf97452ae4">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
| 620 | <a name="l00858"></a>00858 <a class="code" href="classbdm_1_1mgamma.html#da2af0f327e5452bee71d1bf97452ae4">mpdf::from_setting</a> (<span class="keyword">set</span>); <span class="comment">// reads rv and rvc</span> |
| 621 | <a name="l00859"></a>00859 vec betatmp; <span class="comment">// ugly but necessary</span> |
| 622 | <a name="l00860"></a>00860 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (betatmp, <span class="keyword">set</span>, <span class="stringliteral">"beta"</span>, UI::compulsory); |
| 623 | <a name="l00861"></a>00861 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, <span class="keyword">set</span>, <span class="stringliteral">"k"</span>, UI::compulsory); |
| 624 | <a name="l00862"></a>00862 <a class="code" href="classbdm_1_1mgamma.html#a0f21c2557b233a85838b497d040ab14" title="Set value of k.">set_parameters</a> (<a class="code" href="classbdm_1_1mgamma.html#b20cf88cca1fe9b0b8f2a412608bfd09" title="Constant .">k</a>, betatmp); |
| 625 | <a name="l00863"></a>00863 } |
| 626 | <a name="l00864"></a>00864 }; |
| 627 | <a name="l00865"></a>00865 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a> (mgamma); |
| 628 | <a name="l00866"></a>00866 SHAREDPTR (mgamma); |
| 629 | <a name="l00867"></a>00867 |
| 630 | <a name="l00877"></a><a class="code" href="classbdm_1_1migamma.html">00877</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_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><eigamma> |
| 631 | <a name="l00878"></a>00878 { |
| 632 | <a name="l00879"></a>00879 <span class="keyword">protected</span>: |
| 633 | <a name="l00881"></a><a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c">00881</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a>; |
| 634 | <a name="l00882"></a>00882 |
| 635 | <a name="l00884"></a><a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc">00884</a> vec &<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a>; |
| 636 | <a name="l00885"></a>00885 |
| 637 | <a name="l00887"></a><a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5">00887</a> vec &<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a>; |
| 638 | <a name="l00888"></a>00888 |
| 639 | <a name="l00889"></a>00889 <span class="keyword">public</span>: |
| 640 | <a name="l00892"></a>00892 <a class="code" href="classbdm_1_1migamma.html" title="Inverse-Gamma random walk.">migamma</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a>>(), |
| 641 | <a name="l00893"></a>00893 <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a> (0), |
| 642 | <a name="l00894"></a>00894 <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a>()), |
| 643 | <a name="l00895"></a>00895 <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a>()) { |
| 644 | <a name="l00896"></a>00896 } |
| 645 | <a name="l00897"></a>00897 |
| 646 | <a name="l00898"></a>00898 <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_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1eigamma.html" title="Inverse-Gamma posterior density.">eigamma</a>>(), |
| 647 | <a name="l00899"></a>00899 <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a> (0), |
| 648 | <a name="l00900"></a>00900 <a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a>()), |
| 649 | <a name="l00901"></a>00901 <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a>()) { |
| 650 | <a name="l00902"></a>00902 } |
| 651 | <a name="l00904"></a>00904 |
| 652 | <a name="l00906"></a><a class="code" href="classbdm_1_1migamma.html#8b10ab922e2a7bae2fb6bb3efc7b6151">00906</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) { |
| 653 | <a name="l00907"></a>00907 <a class="code" href="classbdm_1_1migamma.html#dc56bc9da542e0103ec16b9be8e5e38c" title="Constant .">k</a> = k0; |
| 654 | <a name="l00908"></a>00908 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</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>); |
| 655 | <a name="l00909"></a>00909 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = dimension(); |
| 656 | <a name="l00910"></a>00910 }; |
| 657 | <a name="l00911"></a><a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c">00911</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1migamma.html#7a34b1e2e3aa2250d7c0ed7df1665b8c" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">condition</a> (<span class="keyword">const</span> vec &val) { |
| 658 | <a name="l00912"></a>00912 <a class="code" href="classbdm_1_1migamma.html#0d854c047001b5465cf1ba21f52904b5" title="cache of iepdf.beta">_beta</a> = elem_mult (val, (<a class="code" href="classbdm_1_1migamma.html#c9847093da59a9ba0ebb68d2c592f5dc" title="cache of iepdf.alpha">_alpha</a> - 1.0)); |
| 659 | <a name="l00913"></a>00913 }; |
| 660 | <a name="l00914"></a>00914 }; |
708 | | <a name="l01002"></a>01002 <a class="code" href="user__info_8h.html#a4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a> (migamma_ref); |
709 | | <a name="l01003"></a>01003 SHAREDPTR (migamma_ref); |
710 | | <a name="l01004"></a>01004 |
711 | | <a name="l01015"></a><a class="code" href="classbdm_1_1elognorm.html">01015</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> |
712 | | <a name="l01016"></a>01016 { |
713 | | <a name="l01017"></a>01017 <span class="keyword">public</span>: |
714 | | <a name="l01018"></a><a class="code" href="classbdm_1_1elognorm.html#a8b948e2bce1253765a2542199913aaba">01018</a> vec <a class="code" href="classbdm_1_1elognorm.html#a8b948e2bce1253765a2542199913aaba" 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>());}; |
715 | | <a name="l01019"></a><a class="code" href="classbdm_1_1elognorm.html#aadb41e4f4d6600dec6f8c1dbc5ed9eea">01019</a> vec <a class="code" href="classbdm_1_1elognorm.html#aadb41e4f4d6600dec6f8c1dbc5ed9eea" title="return expected value">mean</a>()<span class="keyword"> const </span>{vec var = <a class="code" href="classbdm_1_1enorm.html#a729c75ef0fa8abae03d58ad1f81e6773" title="return expected variance (not covariance!)">enorm<ldmat>::variance</a>();<span class="keywordflow">return</span> exp (<a class="code" href="classbdm_1_1enorm.html#ac702a194720853570d08b65482f842c7" title="mean value">mu</a> - 0.5*var);}; |
716 | | <a name="l01020"></a>01020 |
717 | | <a name="l01021"></a>01021 }; |
718 | | <a name="l01022"></a>01022 |
719 | | <a name="l01029"></a><a class="code" href="classbdm_1_1mlognorm.html">01029</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__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><elognorm> |
720 | | <a name="l01030"></a>01030 { |
721 | | <a name="l01031"></a>01031 <span class="keyword">protected</span>: |
722 | | <a name="l01033"></a><a class="code" href="classbdm_1_1mlognorm.html#aa51128a2e503b8b2ce698244b9e0db1a">01033</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mlognorm.html#aa51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>; |
723 | | <a name="l01034"></a>01034 |
724 | | <a name="l01036"></a><a class="code" href="classbdm_1_1mlognorm.html#a7d0063f77d899ef22e8c5edd642176d2">01036</a> vec &<a class="code" href="classbdm_1_1mlognorm.html#a7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a>; |
725 | | <a name="l01037"></a>01037 <span class="keyword">public</span>: |
726 | | <a name="l01039"></a><a class="code" href="classbdm_1_1mlognorm.html#aa5d6eb2688d02e0348b96c4fbd7bde41">01039</a> <a class="code" href="classbdm_1_1mlognorm.html#aa5d6eb2688d02e0348b96c4fbd7bde41" title="Constructor.">mlognorm</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1elognorm.html">elognorm</a>>(), |
727 | | <a name="l01040"></a>01040 <a class="code" href="classbdm_1_1mlognorm.html#aa51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a> (0), |
728 | | <a name="l01041"></a>01041 <a class="code" href="classbdm_1_1mlognorm.html#a7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._mu()) { |
729 | | <a name="l01042"></a>01042 } |
730 | | <a name="l01043"></a>01043 |
731 | | <a name="l01045"></a><a class="code" href="classbdm_1_1mlognorm.html#a604cab0e8a76f9041dc3c606043bb39f">01045</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#a604cab0e8a76f9041dc3c606043bb39f" title="Set value of k.">set_parameters</a> (<span class="keywordtype">int</span> size, <span class="keywordtype">double</span> k) { |
732 | | <a name="l01046"></a>01046 <a class="code" href="classbdm_1_1mlognorm.html#aa51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a> = 0.5 * log (k * k + 1); |
733 | | <a name="l01047"></a>01047 <a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.set_parameters (zeros (size), 2*<a class="code" href="classbdm_1_1mlognorm.html#aa51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>*eye (size)); |
734 | | <a name="l01048"></a>01048 |
735 | | <a name="l01049"></a>01049 <a class="code" href="classbdm_1_1mpdf.html#a7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = size; |
736 | | <a name="l01050"></a>01050 }; |
737 | | <a name="l01051"></a>01051 |
738 | | <a name="l01052"></a><a class="code" href="classbdm_1_1mlognorm.html#a9106d8fd8bdf2b6be675ffd8f3ca584e">01052</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#a9106d8fd8bdf2b6be675ffd8f3ca584e" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">condition</a> (<span class="keyword">const</span> vec &val) { |
739 | | <a name="l01053"></a>01053 <a class="code" href="classbdm_1_1mlognorm.html#a7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a> = log (val) - <a class="code" href="classbdm_1_1mlognorm.html#aa51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>;<span class="comment">//elem_mult ( refl,pow ( val,l ) );</span> |
740 | | <a name="l01054"></a>01054 }; |
741 | | <a name="l01055"></a>01055 |
742 | | <a name="l01067"></a>01067 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#a49e45ea13a869da607ef9be7a229128a">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>); |
743 | | <a name="l01068"></a>01068 |
744 | | <a name="l01069"></a>01069 <span class="comment">// TODO dodelat void to_setting( Setting &set ) const;</span> |
745 | | <a name="l01070"></a>01070 |
746 | | <a name="l01071"></a>01071 }; |
747 | | <a name="l01072"></a>01072 |
748 | | <a name="l01073"></a>01073 <a class="code" href="user__info_8h.html#a4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a> (mlognorm); |
749 | | <a name="l01074"></a>01074 SHAREDPTR (mlognorm); |
750 | | <a name="l01075"></a>01075 |
751 | | <a name="l01079"></a><a class="code" href="classbdm_1_1eWishartCh.html">01079</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> |
752 | | <a name="l01080"></a>01080 { |
753 | | <a name="l01081"></a>01081 <span class="keyword">protected</span>: |
754 | | <a name="l01083"></a><a class="code" href="classbdm_1_1eWishartCh.html#a1b42f9284a32f23b0b253a628cda7490">01083</a> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> <a class="code" href="classbdm_1_1eWishartCh.html#a1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>; |
755 | | <a name="l01085"></a><a class="code" href="classbdm_1_1eWishartCh.html#ab745c73faef785009484180582050a1f">01085</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eWishartCh.html#ab745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>; |
756 | | <a name="l01087"></a><a class="code" href="classbdm_1_1eWishartCh.html#a1879a14d7d2bb05062523b189baa11c3">01087</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eWishartCh.html#a1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a>; |
757 | | <a name="l01088"></a>01088 <span class="keyword">public</span>: |
758 | | <a name="l01090"></a><a class="code" href="classbdm_1_1eWishartCh.html#a183d961532ee97b7dc5ec81701aa59a0">01090</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#a183d961532ee97b7dc5ec81701aa59a0" title="Set internal structures.">set_parameters</a> (<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#a1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a> = <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> (Y0);<a class="code" href="classbdm_1_1eWishartCh.html#a1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a> = delta0; <a class="code" href="classbdm_1_1eWishartCh.html#ab745c73faef785009484180582050a1f" title="dimension of matrix ">p</a> = <a class="code" href="classbdm_1_1eWishartCh.html#a1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classbdm_1_1sqmat.html#a73e639221343dcce76c3305524d67590" title="Reimplementing common functions of mat: rows().">rows</a>(); <a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eWishartCh.html#ab745c73faef785009484180582050a1f" title="dimension of matrix ">p</a> * <a class="code" href="classbdm_1_1eWishartCh.html#ab745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>; } |
759 | | <a name="l01092"></a><a class="code" href="classbdm_1_1eWishartCh.html#acc664035d70d2622bf264a29270f8339">01092</a> mat <a class="code" href="classbdm_1_1eWishartCh.html#acc664035d70d2622bf264a29270f8339" title="Sample matrix argument.">sample_mat</a>()<span class="keyword"> const </span>{ |
760 | | <a name="l01093"></a>01093 mat X = zeros (<a class="code" href="classbdm_1_1eWishartCh.html#ab745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>, <a class="code" href="classbdm_1_1eWishartCh.html#ab745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>); |
761 | | <a name="l01094"></a>01094 |
762 | | <a name="l01095"></a>01095 <span class="comment">//sample diagonal</span> |
763 | | <a name="l01096"></a>01096 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eWishartCh.html#ab745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>;i++) { |
764 | | <a name="l01097"></a>01097 GamRNG.setup (0.5* (<a class="code" href="classbdm_1_1eWishartCh.html#a1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a> - i) , 0.5); <span class="comment">// no +1 !! index if from 0</span> |
765 | | <a name="l01098"></a>01098 <span class="preprocessor">#pragma omp critical</span> |
766 | | <a name="l01099"></a>01099 <span class="preprocessor"></span> X (i, i) = sqrt (GamRNG()); |
767 | | <a name="l01100"></a>01100 } |
768 | | <a name="l01101"></a>01101 <span class="comment">//do the rest</span> |
769 | | <a name="l01102"></a>01102 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < p;i++) { |
770 | | <a name="l01103"></a>01103 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = i + 1;j < p;j++) { |
771 | | <a name="l01104"></a>01104 <span class="preprocessor">#pragma omp critical</span> |
772 | | <a name="l01105"></a>01105 <span class="preprocessor"></span> X (i, j) = NorRNG.sample(); |
773 | | <a name="l01106"></a>01106 } |
774 | | <a name="l01107"></a>01107 } |
775 | | <a name="l01108"></a>01108 <span class="keywordflow">return</span> X*<a class="code" href="classbdm_1_1eWishartCh.html#a1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classbdm_1_1chmat.html#a17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>();<span class="comment">// return upper triangular part of the decomposition</span> |
776 | | <a name="l01109"></a>01109 } |
777 | | <a name="l01110"></a><a class="code" href="classbdm_1_1eWishartCh.html#a8f2154b8b5be8f4c5788f261b6d57b9a">01110</a> vec <a class="code" href="classbdm_1_1eWishartCh.html#a8f2154b8b5be8f4c5788f261b6d57b9a" title="Returns a sample, from density .">sample</a> ()<span class="keyword"> const </span>{ |
778 | | <a name="l01111"></a>01111 <span class="keywordflow">return</span> vec (<a class="code" href="classbdm_1_1eWishartCh.html#acc664035d70d2622bf264a29270f8339" title="Sample matrix argument.">sample_mat</a>()._data(), <a class="code" href="classbdm_1_1eWishartCh.html#ab745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>*<a class="code" href="classbdm_1_1eWishartCh.html#ab745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>); |
779 | | <a name="l01112"></a>01112 } |
780 | | <a name="l01114"></a><a class="code" href="classbdm_1_1eWishartCh.html#a4eee757c0535c2a88bb20f0767c64981">01114</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#a4eee757c0535c2a88bb20f0767c64981" 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#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, Ch0._data(), <a class="code" href="classbdm_1_1eWishartCh.html#a1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classbdm_1_1chmat.html#a17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>()._data());} |
781 | | <a name="l01116"></a><a class="code" href="classbdm_1_1eWishartCh.html#a7eac414ec10b85aa5536b0092c57bc4a">01116</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#a7eac414ec10b85aa5536b0092c57bc4a" 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#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, ch0._data(), <a class="code" href="classbdm_1_1eWishartCh.html#a1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>.<a class="code" href="classbdm_1_1chmat.html#a17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>()._data()); } |
782 | | <a name="l01118"></a><a class="code" href="classbdm_1_1eWishartCh.html#a1708cacb5d8cb1b96395d35f5327cb7e">01118</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a>& <a class="code" href="classbdm_1_1eWishartCh.html#a1708cacb5d8cb1b96395d35f5327cb7e" title="access function">getY</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eWishartCh.html#a1b42f9284a32f23b0b253a628cda7490" title="Upper-Triagle of Choleski decomposition of .">Y</a>;} |
783 | | <a name="l01119"></a>01119 }; |
784 | | <a name="l01120"></a>01120 |
785 | | <a name="l01122"></a>01122 |
786 | | <a name="l01124"></a><a class="code" href="classbdm_1_1eiWishartCh.html">01124</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eiWishartCh.html" title="Inverse Wishart on Choleski decomposition.">eiWishartCh</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> |
787 | | <a name="l01125"></a>01125 { |
788 | | <a name="l01126"></a>01126 <span class="keyword">protected</span>: |
789 | | <a name="l01128"></a><a class="code" href="classbdm_1_1eiWishartCh.html#ac6b684b52dc62b8d46e67d5992f98b9a">01128</a> <a class="code" href="classbdm_1_1eWishartCh.html">eWishartCh</a> <a class="code" href="classbdm_1_1eiWishartCh.html#ac6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>; |
790 | | <a name="l01130"></a><a class="code" href="classbdm_1_1eiWishartCh.html#ac11f1c41183f743b97fbb73a4e9ba6cd">01130</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eiWishartCh.html#ac11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>; |
791 | | <a name="l01132"></a><a class="code" href="classbdm_1_1eiWishartCh.html#aca3035f7bd5e4597cc1843cf07af8464">01132</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eiWishartCh.html#aca3035f7bd5e4597cc1843cf07af8464" title="parameter delta">delta</a>; |
792 | | <a name="l01133"></a>01133 <span class="keyword">public</span>: |
793 | | <a name="l01135"></a><a class="code" href="classbdm_1_1eiWishartCh.html#af463caed9d22d9949f3ee67614e7dcd3">01135</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eiWishartCh.html#af463caed9d22d9949f3ee67614e7dcd3" title="constructor function">set_parameters</a> (<span class="keyword">const</span> mat &Y0, <span class="keyword">const</span> <span class="keywordtype">double</span> delta0) { |
794 | | <a name="l01136"></a>01136 <a class="code" href="classbdm_1_1eiWishartCh.html#aca3035f7bd5e4597cc1843cf07af8464" title="parameter delta">delta</a> = delta0; |
795 | | <a name="l01137"></a>01137 <a class="code" href="classbdm_1_1eiWishartCh.html#ac6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#a183d961532ee97b7dc5ec81701aa59a0" title="Set internal structures.">set_parameters</a> (inv (Y0), delta0); |
796 | | <a name="l01138"></a>01138 <a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eiWishartCh.html#ac6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1epdf.html#a7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>(); <a class="code" href="classbdm_1_1eiWishartCh.html#ac11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a> = Y0.rows(); |
797 | | <a name="l01139"></a>01139 } |
798 | | <a name="l01140"></a><a class="code" href="classbdm_1_1eiWishartCh.html#a2f668192cc9c2e3a5b7e608164685a3e">01140</a> vec <a class="code" href="classbdm_1_1eiWishartCh.html#a2f668192cc9c2e3a5b7e608164685a3e" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{mat iCh; iCh = inv (<a class="code" href="classbdm_1_1eiWishartCh.html#ac6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#acc664035d70d2622bf264a29270f8339" title="Sample matrix argument.">sample_mat</a>()); <span class="keywordflow">return</span> vec (iCh._data(), <a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>);} |
799 | | <a name="l01142"></a><a class="code" href="classbdm_1_1eiWishartCh.html#ad9947933dfc94546cbd6a81f95ec5af5">01142</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eiWishartCh.html#ad9947933dfc94546cbd6a81f95ec5af5" title="access function">_setY</a> (<span class="keyword">const</span> vec &y0) { |
800 | | <a name="l01143"></a>01143 mat Ch (<a class="code" href="classbdm_1_1eiWishartCh.html#ac11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>, <a class="code" href="classbdm_1_1eiWishartCh.html#ac11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>); |
801 | | <a name="l01144"></a>01144 mat iCh (<a class="code" href="classbdm_1_1eiWishartCh.html#ac11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>, <a class="code" href="classbdm_1_1eiWishartCh.html#ac11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>); |
802 | | <a name="l01145"></a>01145 copy_vector (<a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, y0._data(), Ch._data()); |
803 | | <a name="l01146"></a>01146 |
804 | | <a name="l01147"></a>01147 iCh = inv (Ch); |
805 | | <a name="l01148"></a>01148 <a class="code" href="classbdm_1_1eiWishartCh.html#ac6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#a4eee757c0535c2a88bb20f0767c64981" title="fast access function y0 will be copied into Y.Ch.">setY</a> (iCh); |
806 | | <a name="l01149"></a>01149 } |
807 | | <a name="l01150"></a><a class="code" href="classbdm_1_1eiWishartCh.html#aa6ddbd815b8b666dd542e97f009f89bb">01150</a> <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eiWishartCh.html#aa6ddbd815b8b666dd542e97f009f89bb" title="Compute log-probability of argument val In case the argument is out of suport return...">evallog</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
808 | | <a name="l01151"></a>01151 <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> X (<a class="code" href="classbdm_1_1eiWishartCh.html#ac11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>); |
809 | | <a name="l01152"></a>01152 <span class="keyword">const</span> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a>& Y = <a class="code" href="classbdm_1_1eiWishartCh.html#ac6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#a1708cacb5d8cb1b96395d35f5327cb7e" title="access function">getY</a>(); |
810 | | <a name="l01153"></a>01153 |
811 | | <a name="l01154"></a>01154 copy_vector (<a class="code" href="classbdm_1_1eiWishartCh.html#ac11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>*<a class="code" href="classbdm_1_1eiWishartCh.html#ac11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>, val._data(), X.<a class="code" href="classbdm_1_1chmat.html#a17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>()._data()); |
812 | | <a name="l01155"></a>01155 <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> iX (p);X.<a class="code" href="classbdm_1_1chmat.html#acbf3389db96dff41fb2e9532d59b13c0" title="Inversion in the same form, i.e. cholesky.">inv</a> (iX); |
813 | | <a name="l01156"></a>01156 <span class="comment">// compute</span> |
814 | | <a name="l01157"></a>01157 <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> |
815 | | <a name="l01158"></a>01158 mat M = Y.<a class="code" href="classbdm_1_1chmat.html#a4b4c5d4dbb8a3d585b68d936cb6df31b" title="Conversion to full matrix.">to_mat</a>() * iX.to_mat(); |
816 | | <a name="l01159"></a>01159 |
817 | | <a name="l01160"></a>01160 <span class="keywordtype">double</span> log1 = 0.5 * p * (2 * Y.<a class="code" href="classbdm_1_1chmat.html#a949ccd174ed19f9cfe36366cbd5c56a4" title="Logarithm of a determinant.">logdet</a>()) - 0.5 * (<a class="code" href="classbdm_1_1eiWishartCh.html#aca3035f7bd5e4597cc1843cf07af8464" title="parameter delta">delta</a> + p + 1) * (2 * X.<a class="code" href="classbdm_1_1chmat.html#a949ccd174ed19f9cfe36366cbd5c56a4" title="Logarithm of a determinant.">logdet</a>()) - 0.5 * trace (M); |
818 | | <a name="l01161"></a>01161 <span class="comment">//Fixme! Multivariate gamma omitted!! it is ok for sampling, but not otherwise!!</span> |
819 | | <a name="l01162"></a>01162 |
820 | | <a name="l01163"></a>01163 <span class="comment">/* if (0) {</span> |
821 | | <a name="l01164"></a>01164 <span class="comment"> mat XX=X.to_mat();</span> |
822 | | <a name="l01165"></a>01165 <span class="comment"> mat YY=Y.to_mat();</span> |
823 | | <a name="l01166"></a>01166 <span class="comment"></span> |
824 | | <a name="l01167"></a>01167 <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> |
825 | | <a name="l01168"></a>01168 <span class="comment"> cout << log1 << "," << log2 << endl;</span> |
826 | | <a name="l01169"></a>01169 <span class="comment"> }*/</span> |
827 | | <a name="l01170"></a>01170 <span class="keywordflow">return</span> log1; |
828 | | <a name="l01171"></a>01171 }; |
829 | | <a name="l01172"></a>01172 |
830 | | <a name="l01173"></a>01173 }; |
831 | | <a name="l01174"></a>01174 |
832 | | <a name="l01176"></a><a class="code" href="classbdm_1_1rwiWishartCh.html">01176</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1rwiWishartCh.html" title="Random Walk on inverse Wishart.">rwiWishartCh</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><eiWishartCh> |
833 | | <a name="l01177"></a>01177 { |
834 | | <a name="l01178"></a>01178 <span class="keyword">protected</span>: |
835 | | <a name="l01180"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#a2004675b37f712abe3913057bae97cfb">01180</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#a2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a>; |
836 | | <a name="l01182"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#a239b26c71ebcc118ba6925dfb6efc50a">01182</a> vec <a class="code" href="classbdm_1_1rwiWishartCh.html#a239b26c71ebcc118ba6925dfb6efc50a" title="reference point for diagonal">refl</a>; |
837 | | <a name="l01184"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#a758cd05efa67c60b4bf4f7554b9ba861">01184</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#a758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a>; |
838 | | <a name="l01186"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#a7ba06d431995c347d2fce30a59c20663">01186</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#a7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>; |
839 | | <a name="l01187"></a>01187 |
840 | | <a name="l01188"></a>01188 <span class="keyword">public</span>: |
841 | | <a name="l01189"></a>01189 <a class="code" href="classbdm_1_1rwiWishartCh.html" title="Random Walk on inverse Wishart.">rwiWishartCh</a>() : <a class="code" href="classbdm_1_1rwiWishartCh.html#a2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a> (0), <a class="code" href="classbdm_1_1rwiWishartCh.html#a758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a> (0), <a class="code" href="classbdm_1_1rwiWishartCh.html#a7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> (0) {} |
842 | | <a name="l01191"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#a28549ee3ce1ff8509360171ea3cf717c">01191</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#a28549ee3ce1ff8509360171ea3cf717c" title="constructor function">set_parameters</a> (<span class="keywordtype">int</span> p0, <span class="keywordtype">double</span> k, vec ref0, <span class="keywordtype">double</span> l0) { |
843 | | <a name="l01192"></a>01192 <a class="code" href="classbdm_1_1rwiWishartCh.html#a7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> = p0; |
844 | | <a name="l01193"></a>01193 <span class="keywordtype">double</span> delta = 2 / (k * k) + <a class="code" href="classbdm_1_1rwiWishartCh.html#a7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> + 3; |
845 | | <a name="l01194"></a>01194 <a class="code" href="classbdm_1_1rwiWishartCh.html#a2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a> = sqrt (delta - <a class="code" href="classbdm_1_1rwiWishartCh.html#a7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> - 1); |
846 | | <a name="l01195"></a>01195 <a class="code" href="classbdm_1_1rwiWishartCh.html#a758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a> = l0; |
847 | | <a name="l01196"></a>01196 <a class="code" href="classbdm_1_1rwiWishartCh.html#a239b26c71ebcc118ba6925dfb6efc50a" title="reference point for diagonal">refl</a> = pow (ref0, 1 - <a class="code" href="classbdm_1_1rwiWishartCh.html#a758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a>); |
848 | | <a name="l01197"></a>01197 |
849 | | <a name="l01198"></a>01198 <a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1eiWishartCh.html#af463caed9d22d9949f3ee67614e7dcd3" title="constructor function">set_parameters</a> (eye (<a class="code" href="classbdm_1_1rwiWishartCh.html#a7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>), delta); |
850 | | <a name="l01199"></a>01199 <a class="code" href="classbdm_1_1mpdf.html#a7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = <a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1epdf.html#a7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>(); |
851 | | <a name="l01200"></a>01200 } |
852 | | <a name="l01201"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#aac087ba6c885d3faeda9171229f9b4e6">01201</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#aac087ba6c885d3faeda9171229f9b4e6" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">condition</a> (<span class="keyword">const</span> vec &c) { |
853 | | <a name="l01202"></a>01202 vec z = c; |
854 | | <a name="l01203"></a>01203 <span class="keywordtype">int</span> ri = 0; |
855 | | <a name="l01204"></a>01204 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1rwiWishartCh.html#a7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>*<a class="code" href="classbdm_1_1rwiWishartCh.html#a7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>;i += (p + 1)) {<span class="comment">//trace diagonal element</span> |
856 | | <a name="l01205"></a>01205 z (i) = pow (z (i), <a class="code" href="classbdm_1_1rwiWishartCh.html#a758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a>) * <a class="code" href="classbdm_1_1rwiWishartCh.html#a239b26c71ebcc118ba6925dfb6efc50a" title="reference point for diagonal">refl</a> (ri); |
857 | | <a name="l01206"></a>01206 ri++; |
858 | | <a name="l01207"></a>01207 } |
859 | | <a name="l01208"></a>01208 |
860 | | <a name="l01209"></a>01209 <a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1eiWishartCh.html#ad9947933dfc94546cbd6a81f95ec5af5" title="access function">_setY</a> (<a class="code" href="classbdm_1_1rwiWishartCh.html#a2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a>*z); |
861 | | <a name="l01210"></a>01210 } |
862 | | <a name="l01211"></a>01211 }; |
863 | | <a name="l01212"></a>01212 |
864 | | <a name="l01214"></a>01214 <span class="keyword">enum</span> RESAMPLING_METHOD { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; |
865 | | <a name="l01220"></a><a class="code" href="classbdm_1_1eEmp.html">01220</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> |
866 | | <a name="l01221"></a>01221 { |
867 | | <a name="l01222"></a>01222 <span class="keyword">protected</span> : |
868 | | <a name="l01224"></a><a class="code" href="classbdm_1_1eEmp.html#a9798006271ca77629855113f1283a031">01224</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#a9798006271ca77629855113f1283a031" title="Number of particles.">n</a>; |
869 | | <a name="l01226"></a><a class="code" href="classbdm_1_1eEmp.html#a9d39241aab7c4bbeb07c6d516421c67d">01226</a> vec <a class="code" href="classbdm_1_1eEmp.html#a9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>; |
870 | | <a name="l01228"></a><a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3">01228</a> Array<vec> <a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>; |
871 | | <a name="l01229"></a>01229 <span class="keyword">public</span>: |
872 | | <a name="l01232"></a>01232 <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#a9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> (), <a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> () {}; |
873 | | <a name="l01234"></a><a class="code" href="classbdm_1_1eEmp.html#aa3daf6363455af099921715e1233c076">01234</a> <a class="code" href="classbdm_1_1eEmp.html#aa3daf6363455af099921715e1233c076" 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#a9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> (e.<a class="code" href="classbdm_1_1eEmp.html#a9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>), <a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (e.<a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>) {}; |
874 | | <a name="l01236"></a>01236 |
875 | | <a name="l01238"></a>01238 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#ae7f8f98310c1de51bd5c8a1c87528f72" 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); |
876 | | <a name="l01240"></a><a class="code" href="classbdm_1_1eEmp.html#a4f7e6ba7183972e3c7ae399613861b95">01240</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#a4f7e6ba7183972e3c7ae399613861b95" 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#a9798006271ca77629855113f1283a031" title="Number of particles.">n</a>) {<a class="code" href="classbdm_1_1eEmp.html#a4f7e6ba7183972e3c7ae399613861b95" title="Set samples and weights.">set_statistics</a> (ones (n) / n, pdf0);}; |
877 | | <a name="l01242"></a>01242 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#ab62d802b8ef39f7c4dcbeb366c90951a" 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); |
878 | | <a name="l01244"></a><a class="code" href="classbdm_1_1eEmp.html#ac74c281d652356c19b6b079e42ca7ef1">01244</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#ac74c281d652356c19b6b079e42ca7ef1" 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#a9798006271ca77629855113f1283a031" title="Number of particles.">n</a> = n0; <a class="code" href="classbdm_1_1eEmp.html#a9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>.set_size (n0, copy);<a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>.set_size (n0, copy);}; |
879 | | <a name="l01246"></a><a class="code" href="classbdm_1_1eEmp.html#a37937007a3a676cf653a7de412674481">01246</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#a37937007a3a676cf653a7de412674481" title="Set samples.">set_parameters</a> (<span class="keyword">const</span> Array<vec> &Av) { |
880 | | <a name="l01247"></a>01247 <a class="code" href="bdmerror_8h.html#a7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a>(Av.size()>0,<span class="stringliteral">"Empty samples"</span>); |
881 | | <a name="l01248"></a>01248 <a class="code" href="classbdm_1_1eEmp.html#a9798006271ca77629855113f1283a031" title="Number of particles.">n</a> = Av.size(); |
882 | | <a name="l01249"></a>01249 <a class="code" href="classbdm_1_1eEmp.html#ac74c281d652356c19b6b079e42ca7ef1" title="Set sample.">epdf::set_parameters</a>(Av(0).length()); |
883 | | <a name="l01250"></a>01250 <a class="code" href="classbdm_1_1eEmp.html#a9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>=1/n*ones(n); |
884 | | <a name="l01251"></a>01251 <a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>=Av; |
885 | | <a name="l01252"></a>01252 }; |
886 | | <a name="l01254"></a><a class="code" href="classbdm_1_1eEmp.html#ad7f83cc0415cd44ae7cc8b4bdad93aef">01254</a> vec& <a class="code" href="classbdm_1_1eEmp.html#ad7f83cc0415cd44ae7cc8b4bdad93aef" title="Potentially dangerous, use with care.">_w</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#a9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>;}; |
887 | | <a name="l01256"></a><a class="code" href="classbdm_1_1eEmp.html#ab7d7106f486e3fad38590914a693d714">01256</a> <span class="keyword">const</span> vec& <a class="code" href="classbdm_1_1eEmp.html#ab7d7106f486e3fad38590914a693d714" 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#a9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>;}; |
888 | | <a name="l01258"></a><a class="code" href="classbdm_1_1eEmp.html#ac24966b0aaeb767bc8a6b4fd60931be2">01258</a> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#ac24966b0aaeb767bc8a6b4fd60931be2" title="access function">_samples</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>;}; |
889 | | <a name="l01260"></a><a class="code" href="classbdm_1_1eEmp.html#ace568a16cdb4e4cb871ef62d7145f1a5">01260</a> <span class="keyword">const</span> vec& <a class="code" href="classbdm_1_1eEmp.html#ace568a16cdb4e4cb871ef62d7145f1a5" title="access function">_sample</a>(<span class="keywordtype">int</span> i)<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>(i);}; |
890 | | <a name="l01262"></a><a class="code" href="classbdm_1_1eEmp.html#ab59af0efdb009d98ea8ebfa965e74ae2">01262</a> <span class="keyword">const</span> Array<vec>& <a class="code" href="classbdm_1_1eEmp.html#ab59af0efdb009d98ea8ebfa965e74ae2" title="access function">_samples</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>;}; |
891 | | <a name="l01265"></a>01265 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#af59ed50888a31057ac2038d80f607d3d">resample</a> ( ivec &index, RESAMPLING_METHOD method = SYSTEMATIC); |
892 | | <a name="l01266"></a>01266 |
893 | | <a name="l01268"></a><a class="code" href="classbdm_1_1eEmp.html#ab4a150d0a62c08db76d1bc5256909f93">01268</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#ab4a150d0a62c08db76d1bc5256909f93" title="Resampling without returning index of new particles.">resample</a> (RESAMPLING_METHOD method = SYSTEMATIC){ivec ind; <a class="code" href="classbdm_1_1eEmp.html#ab4a150d0a62c08db76d1bc5256909f93" title="Resampling without returning index of new particles.">resample</a>(ind,method);}; |
894 | | <a name="l01269"></a>01269 |
895 | | <a name="l01271"></a><a class="code" href="classbdm_1_1eEmp.html#a97f1e07b5ae6eebc91c7365f0f88d270">01271</a> vec <a class="code" href="classbdm_1_1eEmp.html#a97f1e07b5ae6eebc91c7365f0f88d270" title="inherited operation : NOT implemented">sample</a>()<span class="keyword"> const </span>{ |
896 | | <a name="l01272"></a>01272 <a class="code" href="bdmerror_8h.html#a7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> (<span class="stringliteral">"Not implemented"</span>); |
897 | | <a name="l01273"></a>01273 <span class="keywordflow">return</span> vec(); |
898 | | <a name="l01274"></a>01274 } |
899 | | <a name="l01275"></a>01275 |
900 | | <a name="l01277"></a><a class="code" href="classbdm_1_1eEmp.html#a01654c014d3aa068f8d4ecba4be86d09">01277</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eEmp.html#a01654c014d3aa068f8d4ecba4be86d09" title="inherited operation : NOT implemented">evallog</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
901 | | <a name="l01278"></a>01278 <a class="code" href="bdmerror_8h.html#a7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> (<span class="stringliteral">"Not implemented"</span>); |
902 | | <a name="l01279"></a>01279 <span class="keywordflow">return</span> 0.0; |
903 | | <a name="l01280"></a>01280 } |
904 | | <a name="l01281"></a>01281 |
905 | | <a name="l01282"></a><a class="code" href="classbdm_1_1eEmp.html#abbfcb4f868c7381298c281a256d8c4b9">01282</a> vec <a class="code" href="classbdm_1_1eEmp.html#abbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
906 | | <a name="l01283"></a>01283 vec pom = zeros (<a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
907 | | <a name="l01284"></a>01284 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eEmp.html#a9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++) {pom += <a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) * <a class="code" href="classbdm_1_1eEmp.html#a9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> (i);} |
908 | | <a name="l01285"></a>01285 <span class="keywordflow">return</span> pom; |
909 | | <a name="l01286"></a>01286 } |
910 | | <a name="l01287"></a><a class="code" href="classbdm_1_1eEmp.html#a05e9ebf467ede737cb6a3621d7fd3c87">01287</a> vec <a class="code" href="classbdm_1_1eEmp.html#a05e9ebf467ede737cb6a3621d7fd3c87" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
911 | | <a name="l01288"></a>01288 vec pom = zeros (<a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
912 | | <a name="l01289"></a>01289 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eEmp.html#a9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++) {pom += pow (<a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i), 2) * <a class="code" href="classbdm_1_1eEmp.html#a9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a> (i);} |
913 | | <a name="l01290"></a>01290 <span class="keywordflow">return</span> pom -pow (<a class="code" href="classbdm_1_1eEmp.html#abbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>(), 2); |
914 | | <a name="l01291"></a>01291 } |
915 | | <a name="l01293"></a><a class="code" href="classbdm_1_1eEmp.html#ab1c9df656144edf79ba2d885613f661f">01293</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#ab1c9df656144edf79ba2d885613f661f" 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>{ |
916 | | <a name="l01294"></a>01294 <span class="comment">// lb in inf so than it will be pushed below;</span> |
917 | | <a name="l01295"></a>01295 lb.set_size (<a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
918 | | <a name="l01296"></a>01296 ub.set_size (<a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
919 | | <a name="l01297"></a>01297 lb = std::numeric_limits<double>::infinity(); |
920 | | <a name="l01298"></a>01298 ub = -std::numeric_limits<double>::infinity(); |
921 | | <a name="l01299"></a>01299 <span class="keywordtype">int</span> j; |
922 | | <a name="l01300"></a>01300 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1eEmp.html#a9798006271ca77629855113f1283a031" title="Number of particles.">n</a>;i++) { |
923 | | <a name="l01301"></a>01301 <span class="keywordflow">for</span> (j = 0;j < <a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>; j++) { |
924 | | <a name="l01302"></a>01302 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) (j) < lb (j)) {lb (j) = <a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) (j);} |
925 | | <a name="l01303"></a>01303 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) (j) > ub (j)) {ub (j) = <a class="code" href="classbdm_1_1eEmp.html#a73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a> (i) (j);} |
926 | | <a name="l01304"></a>01304 } |
927 | | <a name="l01305"></a>01305 } |
928 | | <a name="l01306"></a>01306 } |
929 | | <a name="l01307"></a>01307 }; |
930 | | <a name="l01308"></a>01308 |
| 705 | <a name="l01002"></a>01002 |
| 706 | <a name="l01003"></a>01003 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a> (migamma_ref); |
| 707 | <a name="l01004"></a>01004 SHAREDPTR (migamma_ref); |
| 708 | <a name="l01005"></a>01005 |
| 709 | <a name="l01016"></a><a class="code" href="classbdm_1_1elognorm.html">01016</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> |
| 710 | <a name="l01017"></a>01017 { |
| 711 | <a name="l01018"></a>01018 <span class="keyword">public</span>: |
| 712 | <a name="l01019"></a><a class="code" href="classbdm_1_1elognorm.html#8b948e2bce1253765a2542199913aaba">01019</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>());}; |
| 713 | <a name="l01020"></a><a class="code" href="classbdm_1_1elognorm.html#adb41e4f4d6600dec6f8c1dbc5ed9eea">01020</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);}; |
| 714 | <a name="l01021"></a>01021 |
| 715 | <a name="l01022"></a>01022 }; |
| 716 | <a name="l01023"></a>01023 |
| 717 | <a name="l01030"></a><a class="code" href="classbdm_1_1mlognorm.html">01030</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__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><elognorm> |
| 718 | <a name="l01031"></a>01031 { |
| 719 | <a name="l01032"></a>01032 <span class="keyword">protected</span>: |
| 720 | <a name="l01034"></a><a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a">01034</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>; |
| 721 | <a name="l01035"></a>01035 |
| 722 | <a name="l01037"></a><a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2">01037</a> vec &<a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a>; |
| 723 | <a name="l01038"></a>01038 <span class="keyword">public</span>: |
| 724 | <a name="l01040"></a><a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41">01040</a> <a class="code" href="classbdm_1_1mlognorm.html#a5d6eb2688d02e0348b96c4fbd7bde41" title="Constructor.">mlognorm</a>() : <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><<a class="code" href="classbdm_1_1elognorm.html">elognorm</a>>(), |
| 725 | <a name="l01041"></a>01041 <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a> (0), |
| 726 | <a name="l01042"></a>01042 <a class="code" href="classbdm_1_1mlognorm.html#7d0063f77d899ef22e8c5edd642176d2" title="access">mu</a> (<a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._mu()) { |
| 727 | <a name="l01043"></a>01043 } |
| 728 | <a name="l01044"></a>01044 |
| 729 | <a name="l01046"></a><a class="code" href="classbdm_1_1mlognorm.html#604cab0e8a76f9041dc3c606043bb39f">01046</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) { |
| 730 | <a name="l01047"></a>01047 <a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a> = 0.5 * log (k * k + 1); |
| 731 | <a name="l01048"></a>01048 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.set_parameters (zeros (size), 2*<a class="code" href="classbdm_1_1mlognorm.html#a51128a2e503b8b2ce698244b9e0db1a" title="parameter 1/2*sigma^2">sig2</a>*eye (size)); |
| 732 | <a name="l01049"></a>01049 |
| 733 | <a name="l01050"></a>01050 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = size; |
| 734 | <a name="l01051"></a>01051 }; |
| 735 | <a name="l01052"></a>01052 |
| 736 | <a name="l01053"></a><a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e">01053</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#9106d8fd8bdf2b6be675ffd8f3ca584e" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">condition</a> (<span class="keyword">const</span> vec &val) { |
| 737 | <a name="l01054"></a>01054 <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> |
| 738 | <a name="l01055"></a>01055 }; |
| 739 | <a name="l01056"></a>01056 |
| 740 | <a name="l01068"></a>01068 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mlognorm.html#49e45ea13a869da607ef9be7a229128a">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>); |
| 741 | <a name="l01069"></a>01069 |
| 742 | <a name="l01070"></a>01070 <span class="comment">// TODO dodelat void to_setting( Setting &set ) const;</span> |
| 743 | <a name="l01071"></a>01071 |
| 744 | <a name="l01072"></a>01072 }; |
| 745 | <a name="l01073"></a>01073 |
| 746 | <a name="l01074"></a>01074 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a> (mlognorm); |
| 747 | <a name="l01075"></a>01075 SHAREDPTR (mlognorm); |
| 748 | <a name="l01076"></a>01076 |
| 749 | <a name="l01080"></a><a class="code" href="classbdm_1_1eWishartCh.html">01080</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> |
| 750 | <a name="l01081"></a>01081 { |
| 751 | <a name="l01082"></a>01082 <span class="keyword">protected</span>: |
| 752 | <a name="l01084"></a><a class="code" href="classbdm_1_1eWishartCh.html#1b42f9284a32f23b0b253a628cda7490">01084</a> <a class="code" href="classbdm_1_1chmat.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>; |
| 753 | <a name="l01086"></a><a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f">01086</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eWishartCh.html#b745c73faef785009484180582050a1f" title="dimension of matrix ">p</a>; |
| 754 | <a name="l01088"></a><a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3">01088</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eWishartCh.html#1879a14d7d2bb05062523b189baa11c3" title="degrees of freedom ">delta</a>; |
| 755 | <a name="l01089"></a>01089 <span class="keyword">public</span>: |
| 756 | <a name="l01091"></a><a class="code" href="classbdm_1_1eWishartCh.html#183d961532ee97b7dc5ec81701aa59a0">01091</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eWishartCh.html#183d961532ee97b7dc5ec81701aa59a0" title="Set internal structures.">set_parameters</a> (<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="classbdm_1_1chmat.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="classbdm_1_1sqmat.html#73e639221343dcce76c3305524d67590" title="Reimplementing common functions of mat: rows().">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>; } |
| 757 | <a name="l01093"></a><a class="code" href="classbdm_1_1eWishartCh.html#cc664035d70d2622bf264a29270f8339">01093</a> mat <a class="code" href="classbdm_1_1eWishartCh.html#cc664035d70d2622bf264a29270f8339" title="Sample matrix argument.">sample_mat</a>()<span class="keyword"> const </span>{ |
| 758 | <a name="l01094"></a>01094 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>); |
| 759 | <a name="l01095"></a>01095 |
| 760 | <a name="l01096"></a>01096 <span class="comment">//sample diagonal</span> |
| 761 | <a name="l01097"></a>01097 <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++) { |
| 762 | <a name="l01098"></a>01098 GamRNG.<a class="code" href="classitpp_1_1Gamma__RNG.html#dfaae19411e39aa87e1f72e409b6babe" title="Set lambda.">setup</a> (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> |
| 763 | <a name="l01099"></a>01099 <span class="preprocessor">#pragma omp critical</span> |
| 764 | <a name="l01100"></a>01100 <span class="preprocessor"></span> X (i, i) = sqrt (GamRNG()); |
| 765 | <a name="l01101"></a>01101 } |
| 766 | <a name="l01102"></a>01102 <span class="comment">//do the rest</span> |
| 767 | <a name="l01103"></a>01103 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < p;i++) { |
| 768 | <a name="l01104"></a>01104 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = i + 1;j < p;j++) { |
| 769 | <a name="l01105"></a>01105 <span class="preprocessor">#pragma omp critical</span> |
| 770 | <a name="l01106"></a>01106 <span class="preprocessor"></span> X (i, j) = NorRNG.sample(); |
| 771 | <a name="l01107"></a>01107 } |
| 772 | <a name="l01108"></a>01108 } |
| 773 | <a name="l01109"></a>01109 <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="classbdm_1_1chmat.html#17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>();<span class="comment">// return upper triangular part of the decomposition</span> |
| 774 | <a name="l01110"></a>01110 } |
| 775 | <a name="l01111"></a><a class="code" href="classbdm_1_1eWishartCh.html#8f2154b8b5be8f4c5788f261b6d57b9a">01111</a> vec <a class="code" href="classbdm_1_1eWishartCh.html#8f2154b8b5be8f4c5788f261b6d57b9a" title="Returns a sample, from density .">sample</a> ()<span class="keyword"> const </span>{ |
| 776 | <a name="l01112"></a>01112 <span class="keywordflow">return</span> vec (<a class="code" href="classbdm_1_1eWishartCh.html#cc664035d70d2622bf264a29270f8339" title="Sample matrix argument.">sample_mat</a>()._data(), <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>); |
| 777 | <a name="l01113"></a>01113 } |
| 778 | <a name="l01115"></a><a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981">01115</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="classbdm_1_1chmat.html#17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>()._data());} |
| 779 | <a name="l01117"></a><a class="code" href="classbdm_1_1eWishartCh.html#7eac414ec10b85aa5536b0092c57bc4a">01117</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="classbdm_1_1chmat.html#17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>()._data()); } |
| 780 | <a name="l01119"></a><a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e">01119</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1chmat.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>;} |
| 781 | <a name="l01120"></a>01120 }; |
| 782 | <a name="l01121"></a>01121 |
| 783 | <a name="l01123"></a>01123 |
| 784 | <a name="l01125"></a><a class="code" href="classbdm_1_1eiWishartCh.html">01125</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1eiWishartCh.html" title="Inverse Wishart on Choleski decomposition.">eiWishartCh</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> |
| 785 | <a name="l01126"></a>01126 { |
| 786 | <a name="l01127"></a>01127 <span class="keyword">protected</span>: |
| 787 | <a name="l01129"></a><a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a">01129</a> <a class="code" href="classbdm_1_1eWishartCh.html">eWishartCh</a> <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>; |
| 788 | <a name="l01131"></a><a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd">01131</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>; |
| 789 | <a name="l01133"></a><a class="code" href="classbdm_1_1eiWishartCh.html#ca3035f7bd5e4597cc1843cf07af8464">01133</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eiWishartCh.html#ca3035f7bd5e4597cc1843cf07af8464" title="parameter delta">delta</a>; |
| 790 | <a name="l01134"></a>01134 <span class="keyword">public</span>: |
| 791 | <a name="l01136"></a><a class="code" href="classbdm_1_1eiWishartCh.html#f463caed9d22d9949f3ee67614e7dcd3">01136</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eiWishartCh.html#f463caed9d22d9949f3ee67614e7dcd3" title="constructor function">set_parameters</a> (<span class="keyword">const</span> mat &Y0, <span class="keyword">const</span> <span class="keywordtype">double</span> delta0) { |
| 792 | <a name="l01137"></a>01137 <a class="code" href="classbdm_1_1eiWishartCh.html#ca3035f7bd5e4597cc1843cf07af8464" title="parameter delta">delta</a> = delta0; |
| 793 | <a name="l01138"></a>01138 <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#183d961532ee97b7dc5ec81701aa59a0" title="Set internal structures.">set_parameters</a> (inv (Y0), delta0); |
| 794 | <a name="l01139"></a>01139 <a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1epdf.html#7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>(); <a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a> = Y0.rows(); |
| 795 | <a name="l01140"></a>01140 } |
| 796 | <a name="l01141"></a><a class="code" href="classbdm_1_1eiWishartCh.html#2f668192cc9c2e3a5b7e608164685a3e">01141</a> vec <a class="code" href="classbdm_1_1eiWishartCh.html#2f668192cc9c2e3a5b7e608164685a3e" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{mat iCh; iCh = inv (<a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#cc664035d70d2622bf264a29270f8339" title="Sample matrix argument.">sample_mat</a>()); <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>);} |
| 797 | <a name="l01143"></a><a class="code" href="classbdm_1_1eiWishartCh.html#d9947933dfc94546cbd6a81f95ec5af5">01143</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eiWishartCh.html#d9947933dfc94546cbd6a81f95ec5af5" title="access function">_setY</a> (<span class="keyword">const</span> vec &y0) { |
| 798 | <a name="l01144"></a>01144 mat Ch (<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>, <a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>); |
| 799 | <a name="l01145"></a>01145 mat iCh (<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>, <a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>); |
| 800 | <a name="l01146"></a>01146 copy_vector (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>, y0._data(), Ch._data()); |
| 801 | <a name="l01147"></a>01147 |
| 802 | <a name="l01148"></a>01148 iCh = inv (Ch); |
| 803 | <a name="l01149"></a>01149 <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#4eee757c0535c2a88bb20f0767c64981" title="fast access function y0 will be copied into Y.Ch.">setY</a> (iCh); |
| 804 | <a name="l01150"></a>01150 } |
| 805 | <a name="l01151"></a><a class="code" href="classbdm_1_1eiWishartCh.html#a6ddbd815b8b666dd542e97f009f89bb">01151</a> <span class="keyword">virtual</span> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eiWishartCh.html#a6ddbd815b8b666dd542e97f009f89bb" title="Compute log-probability of argument val In case the argument is out of suport return...">evallog</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
| 806 | <a name="l01152"></a>01152 <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> X (<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>); |
| 807 | <a name="l01153"></a>01153 <span class="keyword">const</span> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a>& Y = <a class="code" href="classbdm_1_1eiWishartCh.html#c6b684b52dc62b8d46e67d5992f98b9a" title="Internal instance of Wishart density.">W</a>.<a class="code" href="classbdm_1_1eWishartCh.html#1708cacb5d8cb1b96395d35f5327cb7e" title="access function">getY</a>(); |
| 808 | <a name="l01154"></a>01154 |
| 809 | <a name="l01155"></a>01155 copy_vector (<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>*<a class="code" href="classbdm_1_1eiWishartCh.html#c11f1c41183f743b97fbb73a4e9ba6cd" title="size of Ch">p</a>, val._data(), X.<a class="code" href="classbdm_1_1chmat.html#17daa8c5c5914bd3194cb3053c5793a5" title="Access function.">_Ch</a>()._data()); |
| 810 | <a name="l01156"></a>01156 <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> iX (p);X.<a class="code" href="classbdm_1_1chmat.html#cbf3389db96dff41fb2e9532d59b13c0" title="Inversion in the same form, i.e. cholesky.">inv</a> (iX); |
| 811 | <a name="l01157"></a>01157 <span class="comment">// compute</span> |
| 812 | <a name="l01158"></a>01158 <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> |
| 813 | <a name="l01159"></a>01159 mat M = Y.<a class="code" href="classbdm_1_1chmat.html#4b4c5d4dbb8a3d585b68d936cb6df31b" title="Conversion to full matrix.">to_mat</a>() * iX.to_mat(); |
| 814 | <a name="l01160"></a>01160 |
| 815 | <a name="l01161"></a>01161 <span class="keywordtype">double</span> log1 = 0.5 * p * (2 * Y.<a class="code" href="classbdm_1_1chmat.html#949ccd174ed19f9cfe36366cbd5c56a4" title="Logarithm of a determinant.">logdet</a>()) - 0.5 * (<a class="code" href="classbdm_1_1eiWishartCh.html#ca3035f7bd5e4597cc1843cf07af8464" title="parameter delta">delta</a> + p + 1) * (2 * X.<a class="code" href="classbdm_1_1chmat.html#949ccd174ed19f9cfe36366cbd5c56a4" title="Logarithm of a determinant.">logdet</a>()) - 0.5 * trace (M); |
| 816 | <a name="l01162"></a>01162 <span class="comment">//Fixme! Multivariate gamma omitted!! it is ok for sampling, but not otherwise!!</span> |
| 817 | <a name="l01163"></a>01163 |
| 818 | <a name="l01164"></a>01164 <span class="comment">/* if (0) {</span> |
| 819 | <a name="l01165"></a>01165 <span class="comment"> mat XX=X.to_mat();</span> |
| 820 | <a name="l01166"></a>01166 <span class="comment"> mat YY=Y.to_mat();</span> |
| 821 | <a name="l01167"></a>01167 <span class="comment"></span> |
| 822 | <a name="l01168"></a>01168 <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> |
| 823 | <a name="l01169"></a>01169 <span class="comment"> cout << log1 << "," << log2 << endl;</span> |
| 824 | <a name="l01170"></a>01170 <span class="comment"> }*/</span> |
| 825 | <a name="l01171"></a>01171 <span class="keywordflow">return</span> log1; |
| 826 | <a name="l01172"></a>01172 }; |
| 827 | <a name="l01173"></a>01173 |
| 828 | <a name="l01174"></a>01174 }; |
| 829 | <a name="l01175"></a>01175 |
| 830 | <a name="l01177"></a><a class="code" href="classbdm_1_1rwiWishartCh.html">01177</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1rwiWishartCh.html" title="Random Walk on inverse Wishart.">rwiWishartCh</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1mpdf__internal.html" title="Mpdf with internal epdf that is modified by function condition.">mpdf_internal</a><eiWishartCh> |
| 831 | <a name="l01178"></a>01178 { |
| 832 | <a name="l01179"></a>01179 <span class="keyword">protected</span>: |
| 833 | <a name="l01181"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb">01181</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a>; |
| 834 | <a name="l01183"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#239b26c71ebcc118ba6925dfb6efc50a">01183</a> vec <a class="code" href="classbdm_1_1rwiWishartCh.html#239b26c71ebcc118ba6925dfb6efc50a" title="reference point for diagonal">refl</a>; |
| 835 | <a name="l01185"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861">01185</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a>; |
| 836 | <a name="l01187"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663">01187</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>; |
| 837 | <a name="l01188"></a>01188 |
| 838 | <a name="l01189"></a>01189 <span class="keyword">public</span>: |
| 839 | <a name="l01190"></a>01190 <a class="code" href="classbdm_1_1rwiWishartCh.html" title="Random Walk on inverse Wishart.">rwiWishartCh</a>() : <a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a> (0), <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a> (0), <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> (0) {} |
| 840 | <a name="l01192"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#28549ee3ce1ff8509360171ea3cf717c">01192</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#28549ee3ce1ff8509360171ea3cf717c" title="constructor function">set_parameters</a> (<span class="keywordtype">int</span> p0, <span class="keywordtype">double</span> k, vec ref0, <span class="keywordtype">double</span> l0) { |
| 841 | <a name="l01193"></a>01193 <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> = p0; |
| 842 | <a name="l01194"></a>01194 <span class="keywordtype">double</span> delta = 2 / (k * k) + <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> + 3; |
| 843 | <a name="l01195"></a>01195 <a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a> = sqrt (delta - <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a> - 1); |
| 844 | <a name="l01196"></a>01196 <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a> = l0; |
| 845 | <a name="l01197"></a>01197 <a class="code" href="classbdm_1_1rwiWishartCh.html#239b26c71ebcc118ba6925dfb6efc50a" title="reference point for diagonal">refl</a> = pow (ref0, 1 - <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a>); |
| 846 | <a name="l01198"></a>01198 |
| 847 | <a name="l01199"></a>01199 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1eiWishartCh.html#f463caed9d22d9949f3ee67614e7dcd3" title="constructor function">set_parameters</a> (eye (<a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>), delta); |
| 848 | <a name="l01200"></a>01200 <a class="code" href="classbdm_1_1mpdf.html#7c1900976ff13dbc09c9729b3bbff9e6" title="dimension of the condition">dimc</a> = <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1epdf.html#7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>(); |
| 849 | <a name="l01201"></a>01201 } |
| 850 | <a name="l01202"></a><a class="code" href="classbdm_1_1rwiWishartCh.html#ac087ba6c885d3faeda9171229f9b4e6">01202</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1rwiWishartCh.html#ac087ba6c885d3faeda9171229f9b4e6" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">condition</a> (<span class="keyword">const</span> vec &c) { |
| 851 | <a name="l01203"></a>01203 vec z = c; |
| 852 | <a name="l01204"></a>01204 <span class="keywordtype">int</span> ri = 0; |
| 853 | <a name="l01205"></a>01205 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0;i < <a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>*<a class="code" href="classbdm_1_1rwiWishartCh.html#7ba06d431995c347d2fce30a59c20663" title="dimension">p</a>;i += (p + 1)) {<span class="comment">//trace diagonal element</span> |
| 854 | <a name="l01206"></a>01206 z (i) = pow (z (i), <a class="code" href="classbdm_1_1rwiWishartCh.html#758cd05efa67c60b4bf4f7554b9ba861" title="power of the reference">l</a>) * <a class="code" href="classbdm_1_1rwiWishartCh.html#239b26c71ebcc118ba6925dfb6efc50a" title="reference point for diagonal">refl</a> (ri); |
| 855 | <a name="l01207"></a>01207 ri++; |
| 856 | <a name="l01208"></a>01208 } |
| 857 | <a name="l01209"></a>01209 |
| 858 | <a name="l01210"></a>01210 <a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.<a class="code" href="classbdm_1_1eiWishartCh.html#d9947933dfc94546cbd6a81f95ec5af5" title="access function">_setY</a> (<a class="code" href="classbdm_1_1rwiWishartCh.html#2004675b37f712abe3913057bae97cfb" title="square root of - needed for computation of from conditions">sqd</a>*z); |
| 859 | <a name="l01211"></a>01211 } |
| 860 | <a name="l01212"></a>01212 }; |
| 861 | <a name="l01213"></a>01213 |
| 862 | <a name="l01215"></a>01215 <span class="keyword">enum</span> RESAMPLING_METHOD { MULTINOMIAL = 0, STRATIFIED = 1, SYSTEMATIC = 3 }; |
| 863 | <a name="l01221"></a><a class="code" href="classbdm_1_1eEmp.html">01221</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> |
| 864 | <a name="l01222"></a>01222 { |
| 865 | <a name="l01223"></a>01223 <span class="keyword">protected</span> : |
| 866 | <a name="l01225"></a><a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031">01225</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a>; |
| 867 | <a name="l01227"></a><a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d">01227</a> vec <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>; |
| 868 | <a name="l01229"></a><a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3">01229</a> Array<vec> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>; |
| 869 | <a name="l01230"></a>01230 <span class="keyword">public</span>: |
| 870 | <a name="l01233"></a>01233 <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> () {}; |
| 871 | <a name="l01235"></a><a class="code" href="classbdm_1_1eEmp.html#a3daf6363455af099921715e1233c076">01235</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>) {}; |
| 872 | <a name="l01237"></a>01237 |
| 873 | <a name="l01239"></a>01239 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#e7f8f98310c1de51bd5c8a1c87528f72" 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); |
| 874 | <a name="l01241"></a><a class="code" href="classbdm_1_1eEmp.html#4f7e6ba7183972e3c7ae399613861b95">01241</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#4f7e6ba7183972e3c7ae399613861b95" 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#4f7e6ba7183972e3c7ae399613861b95" title="Set samples and weights.">set_statistics</a> (ones (n) / n, pdf0);}; |
| 875 | <a name="l01243"></a>01243 <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); |
| 876 | <a name="l01245"></a><a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1">01245</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);}; |
| 877 | <a name="l01247"></a><a class="code" href="classbdm_1_1eEmp.html#37937007a3a676cf653a7de412674481">01247</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#37937007a3a676cf653a7de412674481" title="Set samples.">set_parameters</a> (<span class="keyword">const</span> Array<vec> &Av) { |
| 878 | <a name="l01248"></a>01248 <a class="code" href="bdmerror_8h.html#7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a>(Av.size()>0,<span class="stringliteral">"Empty samples"</span>); |
| 879 | <a name="l01249"></a>01249 <a class="code" href="classbdm_1_1eEmp.html#9798006271ca77629855113f1283a031" title="Number of particles.">n</a> = Av.size(); |
| 880 | <a name="l01250"></a>01250 <a class="code" href="classbdm_1_1eEmp.html#c74c281d652356c19b6b079e42ca7ef1" title="Set sample.">epdf::set_parameters</a>(Av(0).length()); |
| 881 | <a name="l01251"></a>01251 <a class="code" href="classbdm_1_1eEmp.html#9d39241aab7c4bbeb07c6d516421c67d" title="Sample weights .">w</a>=1/n*ones(n); |
| 882 | <a name="l01252"></a>01252 <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>=Av; |
| 883 | <a name="l01253"></a>01253 }; |
| 884 | <a name="l01255"></a><a class="code" href="classbdm_1_1eEmp.html#d7f83cc0415cd44ae7cc8b4bdad93aef">01255</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>;}; |
| 885 | <a name="l01257"></a><a class="code" href="classbdm_1_1eEmp.html#b7d7106f486e3fad38590914a693d714">01257</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>;}; |
| 886 | <a name="l01259"></a><a class="code" href="classbdm_1_1eEmp.html#c24966b0aaeb767bc8a6b4fd60931be2">01259</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>;}; |
| 887 | <a name="l01261"></a><a class="code" href="classbdm_1_1eEmp.html#ce568a16cdb4e4cb871ef62d7145f1a5">01261</a> <span class="keyword">const</span> vec& <a class="code" href="classbdm_1_1eEmp.html#ce568a16cdb4e4cb871ef62d7145f1a5" title="access function">_sample</a>(<span class="keywordtype">int</span> i)<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1eEmp.html#73d819553a0f268b055a087d2d4486f3" title="Samples .">samples</a>(i);}; |
| 888 | <a name="l01263"></a><a class="code" href="classbdm_1_1eEmp.html#b59af0efdb009d98ea8ebfa965e74ae2">01263</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>;}; |
| 889 | <a name="l01266"></a>01266 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#f59ed50888a31057ac2038d80f607d3d">resample</a> ( ivec &index, RESAMPLING_METHOD method = SYSTEMATIC); |
| 890 | <a name="l01267"></a>01267 |
| 891 | <a name="l01269"></a><a class="code" href="classbdm_1_1eEmp.html#b4a150d0a62c08db76d1bc5256909f93">01269</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1eEmp.html#b4a150d0a62c08db76d1bc5256909f93" title="Resampling without returning index of new particles.">resample</a> (RESAMPLING_METHOD method = SYSTEMATIC){ivec ind; <a class="code" href="classbdm_1_1eEmp.html#b4a150d0a62c08db76d1bc5256909f93" title="Resampling without returning index of new particles.">resample</a>(ind,method);}; |
| 892 | <a name="l01270"></a>01270 |
| 893 | <a name="l01272"></a><a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270">01272</a> vec <a class="code" href="classbdm_1_1eEmp.html#97f1e07b5ae6eebc91c7365f0f88d270" title="inherited operation : NOT implemented">sample</a>()<span class="keyword"> const </span>{ |
| 894 | <a name="l01273"></a>01273 <a class="code" href="bdmerror_8h.html#7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> (<span class="stringliteral">"Not implemented"</span>); |
| 895 | <a name="l01274"></a>01274 <span class="keywordflow">return</span> vec(); |
| 896 | <a name="l01275"></a>01275 } |
| 897 | <a name="l01276"></a>01276 |
| 898 | <a name="l01278"></a><a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09">01278</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1eEmp.html#01654c014d3aa068f8d4ecba4be86d09" title="inherited operation : NOT implemented">evallog</a> (<span class="keyword">const</span> vec &val)<span class="keyword"> const </span>{ |
| 899 | <a name="l01279"></a>01279 <a class="code" href="bdmerror_8h.html#7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> (<span class="stringliteral">"Not implemented"</span>); |
| 900 | <a name="l01280"></a>01280 <span class="keywordflow">return</span> 0.0; |
| 901 | <a name="l01281"></a>01281 } |
| 902 | <a name="l01282"></a>01282 |
| 903 | <a name="l01283"></a><a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9">01283</a> vec <a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
| 904 | <a name="l01284"></a>01284 vec pom = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
| 905 | <a name="l01285"></a>01285 <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);} |
| 906 | <a name="l01286"></a>01286 <span class="keywordflow">return</span> pom; |
| 907 | <a name="l01287"></a>01287 } |
| 908 | <a name="l01288"></a><a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87">01288</a> vec <a class="code" href="classbdm_1_1eEmp.html#05e9ebf467ede737cb6a3621d7fd3c87" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
| 909 | <a name="l01289"></a>01289 vec pom = zeros (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
| 910 | <a name="l01290"></a>01290 <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);} |
| 911 | <a name="l01291"></a>01291 <span class="keywordflow">return</span> pom -pow (<a class="code" href="classbdm_1_1eEmp.html#bbfcb4f868c7381298c281a256d8c4b9" title="return expected value">mean</a>(), 2); |
| 912 | <a name="l01292"></a>01292 } |
| 913 | <a name="l01294"></a><a class="code" href="classbdm_1_1eEmp.html#b1c9df656144edf79ba2d885613f661f">01294</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>{ |
| 914 | <a name="l01295"></a>01295 <span class="comment">// lb in inf so than it will be pushed below;</span> |
| 915 | <a name="l01296"></a>01296 lb.set_size (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
| 916 | <a name="l01297"></a>01297 ub.set_size (<a class="code" href="classbdm_1_1epdf.html#16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a>); |
| 917 | <a name="l01298"></a>01298 lb = std::numeric_limits<double>::infinity(); |
| 918 | <a name="l01299"></a>01299 ub = -std::numeric_limits<double>::infinity(); |
| 919 | <a name="l01300"></a>01300 <span class="keywordtype">int</span> j; |
| 920 | <a name="l01301"></a>01301 <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++) { |
| 921 | <a name="l01302"></a>01302 <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++) { |
| 922 | <a name="l01303"></a>01303 <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);} |
| 923 | <a name="l01304"></a>01304 <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);} |
| 924 | <a name="l01305"></a>01305 } |
| 925 | <a name="l01306"></a>01306 } |
| 926 | <a name="l01307"></a>01307 } |
| 927 | <a name="l01308"></a>01308 }; |
1028 | | <a name="l01407"></a>01407 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
1029 | | <a name="l01408"></a><a class="code" href="classbdm_1_1enorm.html#adcb739443669ba0a8faf634196284c08">01408</a> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<epdf></a> <a class="code" href="classbdm_1_1enorm.html#adcb739443669ba0a8faf634196284c08" 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> |
1030 | | <a name="l01409"></a>01409 <span class="keyword"></span>{ |
1031 | | <a name="l01410"></a>01410 <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> (); |
1032 | | <a name="l01411"></a>01411 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<epdf></a> narrow(tmp); |
1033 | | <a name="l01412"></a>01412 <a class="code" href="classbdm_1_1enorm.html#adcb739443669ba0a8faf634196284c08" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> ( rvn, *tmp ); |
1034 | | <a name="l01413"></a>01413 <span class="keywordflow">return</span> narrow; |
1035 | | <a name="l01414"></a>01414 } |
1036 | | <a name="l01415"></a>01415 |
1037 | | <a name="l01416"></a>01416 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
1038 | | <a name="l01417"></a>01417 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#adcb739443669ba0a8faf634196284c08" 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, <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a> &target )<span class="keyword"> const</span> |
1039 | | <a name="l01418"></a>01418 <span class="keyword"></span>{ |
1040 | | <a name="l01419"></a>01419 <a class="code" href="bdmerror_8h.html#a7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<a class="code" href="classbdm_1_1epdf.html#ac4b863ff84c7a4882fb3ad18556027f9" title="True if rv is assigned.">isnamed</a>(), <span class="stringliteral">"rv description is not assigned"</span>); |
1041 | | <a name="l01420"></a>01420 ivec irvn = rvn.<a class="code" href="classbdm_1_1RV.html#acbebdb5e0d30101a6eb63550ef701c55" title="when this rv is a part of bigger rv, this function returns indices of self in the...">dataind</a> (<a class="code" href="classbdm_1_1epdf.html#a62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>); |
1042 | | <a name="l01421"></a>01421 |
1043 | | <a name="l01422"></a>01422 sq_T Rn (<a class="code" href="classbdm_1_1enorm.html#a2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>, irvn); <span class="comment">// select rows and columns of R</span> |
1044 | | <a name="l01423"></a>01423 |
1045 | | <a name="l01424"></a>01424 target.<a class="code" href="classbdm_1_1epdf.html#af423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a> ( rvn ); |
1046 | | <a name="l01425"></a>01425 target.set_parameters (<a class="code" href="classbdm_1_1enorm.html#ac702a194720853570d08b65482f842c7" title="mean value">mu</a> (irvn), Rn); |
1047 | | <a name="l01426"></a>01426 } |
1048 | | <a name="l01427"></a>01427 |
1049 | | <a name="l01428"></a>01428 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
1050 | | <a name="l01429"></a><a class="code" href="classbdm_1_1enorm.html#a40201ca12c6900f7aeb493bb7c582e20">01429</a> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></a> <a class="code" href="classbdm_1_1enorm.html#a40201ca12c6900f7aeb493bb7c582e20" 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> |
1051 | | <a name="l01430"></a>01430 <span class="keyword"></span>{ |
1052 | | <a name="l01431"></a>01431 <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> (); |
1053 | | <a name="l01432"></a>01432 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></a> narrow(tmp); |
1054 | | <a name="l01433"></a>01433 <a class="code" href="classbdm_1_1enorm.html#a40201ca12c6900f7aeb493bb7c582e20" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">condition</a> ( rvn, *tmp ); |
1055 | | <a name="l01434"></a>01434 <span class="keywordflow">return</span> narrow; |
1056 | | <a name="l01435"></a>01435 } |
1057 | | <a name="l01436"></a>01436 |
1058 | | <a name="l01437"></a>01437 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
1059 | | <a name="l01438"></a>01438 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#a40201ca12c6900f7aeb493bb7c582e20" 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, <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling , where is random variable, rv, and...">mpdf</a> &target )<span class="keyword"> const</span> |
1060 | | <a name="l01439"></a>01439 <span class="keyword"></span>{ |
1061 | | <a name="l01440"></a>01440 <span class="keyword">typedef</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T></a> TMlnorm; |
1062 | | <a name="l01441"></a>01441 |
1063 | | <a name="l01442"></a>01442 <a class="code" href="bdmerror_8h.html#a7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<a class="code" href="classbdm_1_1epdf.html#ac4b863ff84c7a4882fb3ad18556027f9" title="True if rv is assigned.">isnamed</a>(), <span class="stringliteral">"rvs are not assigned"</span>); |
1064 | | <a name="l01443"></a>01443 TMlnorm &uptarget = <span class="keyword">dynamic_cast<</span>TMlnorm &<span class="keyword">></span>(target); |
1065 | | <a name="l01444"></a>01444 |
1066 | | <a name="l01445"></a>01445 <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#a62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#aaec44dabdf0a6d90fbae95e1356eda39" title="Subtract another variable from the current one.">subt</a> (rvn); |
1067 | | <a name="l01446"></a>01446 <a class="code" href="bdmerror_8h.html#a7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> ( (rvc.<a class="code" href="classbdm_1_1RV.html#ade30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>() + rvn.<a class="code" href="classbdm_1_1RV.html#ade30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>() == <a class="code" href="classbdm_1_1epdf.html#a62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#ade30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>()), <span class="stringliteral">"wrong rvn"</span>); |
1068 | | <a name="l01447"></a>01447 <span class="comment">//Permutation vector of the new R</span> |
1069 | | <a name="l01448"></a>01448 ivec irvn = rvn.<a class="code" href="classbdm_1_1RV.html#acbebdb5e0d30101a6eb63550ef701c55" title="when this rv is a part of bigger rv, this function returns indices of self in the...">dataind</a> (<a class="code" href="classbdm_1_1epdf.html#a62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>); |
1070 | | <a name="l01449"></a>01449 ivec irvc = rvc.<a class="code" href="classbdm_1_1RV.html#acbebdb5e0d30101a6eb63550ef701c55" title="when this rv is a part of bigger rv, this function returns indices of self in the...">dataind</a> (<a class="code" href="classbdm_1_1epdf.html#a62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>); |
1071 | | <a name="l01450"></a>01450 ivec perm = concat (irvn , irvc); |
1072 | | <a name="l01451"></a>01451 sq_T Rn (<a class="code" href="classbdm_1_1enorm.html#a2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>, perm); |
1073 | | <a name="l01452"></a>01452 |
1074 | | <a name="l01453"></a>01453 <span class="comment">//fixme - could this be done in general for all sq_T?</span> |
1075 | | <a name="l01454"></a>01454 mat S = Rn.to_mat(); |
1076 | | <a name="l01455"></a>01455 <span class="comment">//fixme</span> |
1077 | | <a name="l01456"></a>01456 <span class="keywordtype">int</span> n = rvn.<a class="code" href="classbdm_1_1RV.html#ade30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>() - 1; |
1078 | | <a name="l01457"></a>01457 <span class="keywordtype">int</span> end = <a class="code" href="classbdm_1_1enorm.html#a2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>.rows() - 1; |
1079 | | <a name="l01458"></a>01458 mat S11 = S.get (0, n, 0, n); |
1080 | | <a name="l01459"></a>01459 mat S12 = S.get (0, n , rvn.<a class="code" href="classbdm_1_1RV.html#ade30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>(), end); |
1081 | | <a name="l01460"></a>01460 mat S22 = S.get (rvn.<a class="code" href="classbdm_1_1RV.html#ade30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>(), end, rvn.<a class="code" href="classbdm_1_1RV.html#ade30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>(), end); |
1082 | | <a name="l01461"></a>01461 |
1083 | | <a name="l01462"></a>01462 vec mu1 = <a class="code" href="classbdm_1_1enorm.html#ac702a194720853570d08b65482f842c7" title="mean value">mu</a> (irvn); |
1084 | | <a name="l01463"></a>01463 vec mu2 = <a class="code" href="classbdm_1_1enorm.html#ac702a194720853570d08b65482f842c7" title="mean value">mu</a> (irvc); |
1085 | | <a name="l01464"></a>01464 mat A = S12 * inv (S22); |
1086 | | <a name="l01465"></a>01465 sq_T R_n (S11 - A *S12.T()); |
1087 | | <a name="l01466"></a>01466 |
1088 | | <a name="l01467"></a>01467 uptarget.set_rv (rvn); |
1089 | | <a name="l01468"></a>01468 uptarget.set_rvc (rvc); |
1090 | | <a name="l01469"></a>01469 uptarget.set_parameters (A, mu1 - A*mu2, R_n); |
1091 | | <a name="l01470"></a>01470 } |
1092 | | <a name="l01471"></a>01471 |
1093 | | <a name="l01474"></a>01474 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
1094 | | <a name="l01475"></a><a class="code" href="classbdm_1_1mgnorm.html#ab736332d20e418bf50d45836e129f339">01475</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#ab736332d20e418bf50d45836e129f339" title="set mean function">mgnorm<sq_T >::set_parameters</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<fnc></a> &g0, <span class="keyword">const</span> sq_T &R0) { |
1095 | | <a name="l01476"></a>01476 g = g0; |
1096 | | <a name="l01477"></a>01477 this-><a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.set_parameters (zeros (g->dimension()), R0); |
1097 | | <a name="l01478"></a>01478 } |
1098 | | <a name="l01479"></a>01479 |
1099 | | <a name="l01480"></a>01480 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
1100 | | <a name="l01481"></a><a class="code" href="classbdm_1_1mgnorm.html#ab31d63472cf6a1030cd8dbd8094c1f6d">01481</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#ab31d63472cf6a1030cd8dbd8094c1f6d" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">mgnorm<sq_T >::condition</a> (<span class="keyword">const</span> vec &cond) {this-><a class="code" href="classbdm_1_1mpdf__internal.html#a47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._mu() = g->eval (cond);}; |
1101 | | <a name="l01482"></a>01482 |
1102 | | <a name="l01484"></a>01484 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
1103 | | <a name="l01485"></a>01485 std::ostream &operator<< (std::ostream &os, mlnorm<sq_T> &ml) |
1104 | | <a name="l01486"></a>01486 { |
1105 | | <a name="l01487"></a>01487 os << <span class="stringliteral">"A:"</span> << ml.A << endl; |
1106 | | <a name="l01488"></a>01488 os << <span class="stringliteral">"mu:"</span> << ml.mu_const << endl; |
1107 | | <a name="l01489"></a>01489 os << <span class="stringliteral">"R:"</span> << ml._R() << endl; |
1108 | | <a name="l01490"></a>01490 <span class="keywordflow">return</span> os; |
1109 | | <a name="l01491"></a>01491 }; |
1110 | | <a name="l01492"></a>01492 |
1111 | | <a name="l01493"></a>01493 } |
1112 | | <a name="l01494"></a>01494 <span class="preprocessor">#endif //EF_H</span> |
| 1025 | <a name="l01407"></a>01407 |
| 1026 | <a name="l01408"></a>01408 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 1027 | <a name="l01409"></a><a class="code" href="classbdm_1_1enorm.html#dcb739443669ba0a8faf634196284c08">01409</a> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<epdf></a> <a class="code" href="classbdm_1_1enorm.html#dcb739443669ba0a8faf634196284c08" 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> |
| 1028 | <a name="l01410"></a>01410 <span class="keyword"></span>{ |
| 1029 | <a name="l01411"></a>01411 <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> (); |
| 1030 | <a name="l01412"></a>01412 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<epdf></a> narrow(tmp); |
| 1031 | <a name="l01413"></a>01413 <a class="code" href="classbdm_1_1enorm.html#dcb739443669ba0a8faf634196284c08" title="Return marginal density on the given RV, the remainig rvs are intergrated out.">marginal</a> ( rvn, *tmp ); |
| 1032 | <a name="l01414"></a>01414 <span class="keywordflow">return</span> narrow; |
| 1033 | <a name="l01415"></a>01415 } |
| 1034 | <a name="l01416"></a>01416 |
| 1035 | <a name="l01417"></a>01417 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 1036 | <a name="l01418"></a>01418 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#dcb739443669ba0a8faf634196284c08" 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, <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a> &target )<span class="keyword"> const</span> |
| 1037 | <a name="l01419"></a>01419 <span class="keyword"></span>{ |
| 1038 | <a name="l01420"></a>01420 <a class="code" href="bdmerror_8h.html#7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<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>); |
| 1039 | <a name="l01421"></a>01421 ivec irvn = rvn.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55" title="when this rv is a part of bigger rv, this function returns indices of self in the...">dataind</a> (<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>); |
| 1040 | <a name="l01422"></a>01422 |
| 1041 | <a name="l01423"></a>01423 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> |
| 1042 | <a name="l01424"></a>01424 |
| 1043 | <a name="l01425"></a>01425 target.<a class="code" href="classbdm_1_1epdf.html#f423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a> ( rvn ); |
| 1044 | <a name="l01426"></a>01426 target.set_parameters (<a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> (irvn), Rn); |
| 1045 | <a name="l01427"></a>01427 } |
| 1046 | <a name="l01428"></a>01428 |
| 1047 | <a name="l01429"></a>01429 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 1048 | <a name="l01430"></a><a class="code" href="classbdm_1_1enorm.html#40201ca12c6900f7aeb493bb7c582e20">01430</a> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></a> <a class="code" href="classbdm_1_1enorm.html#40201ca12c6900f7aeb493bb7c582e20" 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> |
| 1049 | <a name="l01431"></a>01431 <span class="keyword"></span>{ |
| 1050 | <a name="l01432"></a>01432 <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> (); |
| 1051 | <a name="l01433"></a>01433 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></a> narrow(tmp); |
| 1052 | <a name="l01434"></a>01434 <a class="code" href="classbdm_1_1enorm.html#40201ca12c6900f7aeb493bb7c582e20" title="Return conditional density on the given RV, the remaining rvs will be in conditioning...">condition</a> ( rvn, *tmp ); |
| 1053 | <a name="l01435"></a>01435 <span class="keywordflow">return</span> narrow; |
| 1054 | <a name="l01436"></a>01436 } |
| 1055 | <a name="l01437"></a>01437 |
| 1056 | <a name="l01438"></a>01438 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 1057 | <a name="l01439"></a>01439 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1enorm.html#40201ca12c6900f7aeb493bb7c582e20" 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, <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling , where is random variable, rv, and...">mpdf</a> &target )<span class="keyword"> const</span> |
| 1058 | <a name="l01440"></a>01440 <span class="keyword"></span>{ |
| 1059 | <a name="l01441"></a>01441 <span class="keyword">typedef</span> <a class="code" href="classbdm_1_1mlnorm.html" title="Normal distributed linear function with linear function of mean value;.">mlnorm<sq_T></a> TMlnorm; |
| 1060 | <a name="l01442"></a>01442 |
| 1061 | <a name="l01443"></a>01443 <a class="code" href="bdmerror_8h.html#7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> (<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>); |
| 1062 | <a name="l01444"></a>01444 TMlnorm &uptarget = <span class="keyword">dynamic_cast<</span>TMlnorm &<span class="keyword">></span>(target); |
| 1063 | <a name="l01445"></a>01445 |
| 1064 | <a name="l01446"></a>01446 <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); |
| 1065 | <a name="l01447"></a>01447 <a class="code" href="bdmerror_8h.html#7a3399d182b8e3065532596e76f84849" title="Throw std::runtime_exception if t is not true.">bdm_assert</a> ( (rvc.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>() + rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089" title="total size of a random variable">_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" title="total size of a random variable">_dsize</a>()), <span class="stringliteral">"wrong rvn"</span>); |
| 1066 | <a name="l01448"></a>01448 <span class="comment">//Permutation vector of the new R</span> |
| 1067 | <a name="l01449"></a>01449 ivec irvn = rvn.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55" title="when this rv is a part of bigger rv, this function returns indices of self in the...">dataind</a> (<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>); |
| 1068 | <a name="l01450"></a>01450 ivec irvc = rvc.<a class="code" href="classbdm_1_1RV.html#cbebdb5e0d30101a6eb63550ef701c55" title="when this rv is a part of bigger rv, this function returns indices of self in the...">dataind</a> (<a class="code" href="classbdm_1_1epdf.html#62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>); |
| 1069 | <a name="l01451"></a>01451 ivec perm = concat (irvn , irvc); |
| 1070 | <a name="l01452"></a>01452 sq_T Rn (<a class="code" href="classbdm_1_1enorm.html#2d92dde696b2a7a5b10ddef5d22ba2c2" title="Covariance matrix in decomposed form.">R</a>, perm); |
| 1071 | <a name="l01453"></a>01453 |
| 1072 | <a name="l01454"></a>01454 <span class="comment">//fixme - could this be done in general for all sq_T?</span> |
| 1073 | <a name="l01455"></a>01455 mat S = Rn.to_mat(); |
| 1074 | <a name="l01456"></a>01456 <span class="comment">//fixme</span> |
| 1075 | <a name="l01457"></a>01457 <span class="keywordtype">int</span> n = rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>() - 1; |
| 1076 | <a name="l01458"></a>01458 <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; |
| 1077 | <a name="l01459"></a>01459 mat S11 = S.get (0, n, 0, n); |
| 1078 | <a name="l01460"></a>01460 mat S12 = S.get (0, n , rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>(), end); |
| 1079 | <a name="l01461"></a>01461 mat S22 = S.get (rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>(), end, rvn.<a class="code" href="classbdm_1_1RV.html#de30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>(), end); |
| 1080 | <a name="l01462"></a>01462 |
| 1081 | <a name="l01463"></a>01463 vec mu1 = <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> (irvn); |
| 1082 | <a name="l01464"></a>01464 vec mu2 = <a class="code" href="classbdm_1_1enorm.html#c702a194720853570d08b65482f842c7" title="mean value">mu</a> (irvc); |
| 1083 | <a name="l01465"></a>01465 mat A = S12 * inv (S22); |
| 1084 | <a name="l01466"></a>01466 sq_T R_n (S11 - A *S12.T()); |
| 1085 | <a name="l01467"></a>01467 |
| 1086 | <a name="l01468"></a>01468 uptarget.set_rv (rvn); |
| 1087 | <a name="l01469"></a>01469 uptarget.set_rvc (rvc); |
| 1088 | <a name="l01470"></a>01470 uptarget.set_parameters (A, mu1 - A*mu2, R_n); |
| 1089 | <a name="l01471"></a>01471 } |
| 1090 | <a name="l01472"></a>01472 |
| 1091 | <a name="l01475"></a>01475 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 1092 | <a name="l01476"></a><a class="code" href="classbdm_1_1mgnorm.html#b736332d20e418bf50d45836e129f339">01476</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#b736332d20e418bf50d45836e129f339" title="set mean function">mgnorm<sq_T >::set_parameters</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<fnc></a> &g0, <span class="keyword">const</span> sq_T &R0) { |
| 1093 | <a name="l01477"></a>01477 g = g0; |
| 1094 | <a name="l01478"></a>01478 this-><a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>.set_parameters (zeros (g->dimension()), R0); |
| 1095 | <a name="l01479"></a>01479 } |
| 1096 | <a name="l01480"></a>01480 |
| 1097 | <a name="l01481"></a>01481 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 1098 | <a name="l01482"></a><a class="code" href="classbdm_1_1mgnorm.html#b31d63472cf6a1030cd8dbd8094c1f6d">01482</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1mgnorm.html#b31d63472cf6a1030cd8dbd8094c1f6d" title="Update iepdf so that it represents this mpdf conditioned on rvc = cond This function...">mgnorm<sq_T >::condition</a> (<span class="keyword">const</span> vec &cond) {this-><a class="code" href="classbdm_1_1mpdf__internal.html#47bab632af15120c88aad647ae129468" title="Internal epdf used for sampling.">iepdf</a>._mu() = g->eval (cond);}; |
| 1099 | <a name="l01483"></a>01483 |
| 1100 | <a name="l01485"></a>01485 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 1101 | <a name="l01486"></a>01486 std::ostream &operator<< (std::ostream &os, mlnorm<sq_T> &ml) |
| 1102 | <a name="l01487"></a>01487 { |
| 1103 | <a name="l01488"></a>01488 os << <span class="stringliteral">"A:"</span> << ml.A << endl; |
| 1104 | <a name="l01489"></a>01489 os << <span class="stringliteral">"mu:"</span> << ml.mu_const << endl; |
| 1105 | <a name="l01490"></a>01490 os << <span class="stringliteral">"R:"</span> << ml._R() << endl; |
| 1106 | <a name="l01491"></a>01491 <span class="keywordflow">return</span> os; |
| 1107 | <a name="l01492"></a>01492 }; |
| 1108 | <a name="l01493"></a>01493 |
| 1109 | <a name="l01494"></a>01494 } |
| 1110 | <a name="l01495"></a>01495 <span class="preprocessor">#endif //EF_H</span> |