Show
Ignore:
Timestamp:
03/05/09 14:03:56 (16 years ago)
Author:
smidl
Message:

doc

Files:
1 modified

Legend:

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

    r280 r287  
    7474<a name="l00038"></a><a class="code" href="classbdm_1_1PF.html#521e9621d3b5e1274275f323691afdaf">00038</a>         <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> *<a class="code" href="classbdm_1_1PF.html#521e9621d3b5e1274275f323691afdaf" title="Parameter evolution model.">par</a>; 
    7575<a name="l00040"></a><a class="code" href="classbdm_1_1PF.html#d6e7a62fba1e0a0d73c9b87f4fb683ec">00040</a>         <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> *<a class="code" href="classbdm_1_1PF.html#d6e7a62fba1e0a0d73c9b87f4fb683ec" title="Observation model.">obs</a>; 
    76 <a name="l00041"></a>00041 <span class="keyword">public</span>: 
    77 <a name="l00044"></a>00044         <a class="code" href="classbdm_1_1PF.html" title="Trivial particle filter with proposal density equal to parameter evolution model...">PF</a> ( ) :<a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>(), <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( <a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>() ),<a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( <a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a>() ) {}; 
    78 <a name="l00045"></a>00045         <a class="code" href="classbdm_1_1PF.html" title="Trivial particle filter with proposal density equal to parameter evolution model...">PF</a>( <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> *par0, <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> *obs0, <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> *epdf0, <span class="keywordtype">int</span> n0 ) : 
    79 <a name="l00046"></a>00046                         <a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a> ( ),<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( <a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>() ),<a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( <a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a>() )  
    80 <a name="l00047"></a>00047                         { <a class="code" href="classbdm_1_1PF.html#521e9621d3b5e1274275f323691afdaf" title="Parameter evolution model.">par</a> = par0; <a class="code" href="classbdm_1_1PF.html#d6e7a62fba1e0a0d73c9b87f4fb683ec" title="Observation model.">obs</a>=obs0; <a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1eEmp.html#82320074a9b0ad7e1bb33a6e885b65d7" title="Set samples and weights.">set_parameters</a> ( ones(n0),epdf0 ); }; 
    81 <a name="l00048"></a>00048         <span class="keywordtype">void</span> set_parameters ( mpdf *par0, mpdf *obs0, <span class="keywordtype">int</span> n0 )  
    82 <a name="l00049"></a>00049                         { <a class="code" href="classbdm_1_1PF.html#521e9621d3b5e1274275f323691afdaf" title="Parameter evolution model.">par</a> = par0; <a class="code" href="classbdm_1_1PF.html#d6e7a62fba1e0a0d73c9b87f4fb683ec" title="Observation model.">obs</a>=obs0; <a class="code" href="classbdm_1_1PF.html#eeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>=n0; <a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.set_n(<a class="code" href="classbdm_1_1PF.html#eeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>);}; 
    83 <a name="l00050"></a>00050         <span class="keywordtype">void</span> set_statistics (<span class="keyword">const</span> vec w0, epdf *epdf0){<a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.set_parameters ( w0,epdf0 );}; 
    84 <a name="l00053"></a>00053         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#6f1988db4c3f602d187a6c15ec89cb1e">set_est</a> ( <span class="keyword">const</span> epdf &amp;epdf0 ); 
    85 <a name="l00054"></a>00054         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#638946eea22d4964bf9350286bb4efd8" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &amp;dt ); 
    86 <a name="l00056"></a><a class="code" href="classbdm_1_1PF.html#78a9f6809827be1d9bfe215d03b1c6ed">00056</a>         vec* <a class="code" href="classbdm_1_1PF.html#78a9f6809827be1d9bfe215d03b1c6ed" title="access function">__w</a>() {<span class="keywordflow">return</span> &amp;<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>;} 
    87 <a name="l00057"></a>00057 }; 
    88 <a name="l00058"></a>00058  
    89 <a name="l00065"></a>00065 <span class="keyword">template</span>&lt;<span class="keyword">class</span> BM_T&gt; 
    90 <a name="l00066"></a>00066  
    91 <a name="l00067"></a><a class="code" href="classbdm_1_1MPF.html">00067</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1MPF.html" title="Marginalized Particle filter.">MPF</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1PF.html" title="Trivial particle filter with proposal density equal to parameter evolution model...">PF</a> { 
    92 <a name="l00068"></a>00068         BM_T* Bms[10000]; 
    93 <a name="l00069"></a>00069  
    94 <a name="l00071"></a>00071  
    95 <a name="l00072"></a>00072 <span class="keyword">class </span>mpfepdf : <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>  { 
    96 <a name="l00073"></a>00073         <span class="keyword">protected</span>: 
    97 <a name="l00074"></a>00074                 <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> &amp;E; 
    98 <a name="l00075"></a>00075                 vec &amp;<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>; 
    99 <a name="l00076"></a>00076                 Array&lt;const epdf*&gt; Coms; 
    100 <a name="l00077"></a>00077         <span class="keyword">public</span>: 
    101 <a name="l00078"></a>00078                 mpfepdf ( <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> &amp;E0) : 
    102 <a name="l00079"></a>00079                                 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ), E ( E0 ),  <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( E._w() ), 
    103 <a name="l00080"></a>00080                                 Coms ( <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length() ) { 
    104 <a name="l00081"></a>00081                 }; 
    105 <a name="l00082"></a>00082                 <span class="keywordtype">void</span> set_elements ( <span class="keywordtype">int</span> &amp;i, <span class="keywordtype">double</span> wi, <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>* ep ) 
    106 <a name="l00083"></a>00083                 {<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ) =wi; Coms ( i ) =ep;}; 
    107 <a name="l00084"></a>00084  
    108 <a name="l00085"></a>00085                 <span class="keywordtype">void</span> set_n(<span class="keywordtype">int</span> <a class="code" href="classbdm_1_1PF.html#eeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>){E.set_n(n); Coms.set_length(n);} 
    109 <a name="l00086"></a>00086                 vec mean()<span class="keyword"> const </span>{ 
    110 <a name="l00087"></a>00087                         <span class="comment">// ugly</span> 
    111 <a name="l00088"></a>00088                         vec pom=zeros ( Coms(0)-&gt;dimension() ); 
    112 <a name="l00089"></a>00089                         <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0; i&lt;<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length(); i++ ) {pom += Coms ( i )-&gt;mean() * <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i );} 
    113 <a name="l00090"></a>00090                         <span class="keywordflow">return</span> concat ( E.mean(),pom ); 
    114 <a name="l00091"></a>00091                 } 
    115 <a name="l00092"></a>00092                 vec variance()<span class="keyword"> const </span>{ 
    116 <a name="l00093"></a>00093                         <span class="comment">// ugly</span> 
    117 <a name="l00094"></a>00094                         vec pom=zeros ( Coms ( 0 )-&gt;dimension() ); 
    118 <a name="l00095"></a>00095                         vec pom2=zeros (  Coms ( 0 )-&gt;dimension() ); 
    119 <a name="l00096"></a>00096                         <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0; i&lt;<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length(); i++ ) { 
    120 <a name="l00097"></a>00097                                 pom += Coms ( i )-&gt;mean() * <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ); 
    121 <a name="l00098"></a>00098                                 pom2 += ( Coms ( i )-&gt;variance() + pow ( Coms ( i )-&gt;mean(),2 ) ) * <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ); 
    122 <a name="l00099"></a>00099                         } 
    123 <a name="l00100"></a>00100                         <span class="keywordflow">return</span> concat ( E.variance(),pom2-pow ( pom,2 ) ); 
    124 <a name="l00101"></a>00101                 } 
    125 <a name="l00102"></a>00102  
    126 <a name="l00103"></a>00103                 vec sample()<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> 0;} 
    127 <a name="l00104"></a>00104  
    128 <a name="l00105"></a>00105                 <span class="keywordtype">double</span> evallog ( <span class="keyword">const</span> vec &amp;val )<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"not implemented"</span> ); <span class="keywordflow">return</span> 0.0;} 
    129 <a name="l00106"></a>00106         }; 
     76<a name="l00041"></a>00041  
     77<a name="l00043"></a><a class="code" href="classbdm_1_1PF.html#9932c7c5865954ef9a438afcbe944e52">00043</a>         RESAMPLING_METHOD <a class="code" href="classbdm_1_1PF.html#9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>; 
     78<a name="l00044"></a>00044  
     79<a name="l00047"></a>00047  
     80<a name="l00049"></a><a class="code" href="classbdm_1_1PF.html#98ef9ff80c394fafd28680b7a3f831b1">00049</a>         <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1PF.html#98ef9ff80c394fafd28680b7a3f831b1" title="Log all samples.">opt_L_smp</a>; 
     81<a name="l00051"></a><a class="code" href="classbdm_1_1PF.html#5a49463a88ee80771a464861df845ff6">00051</a>         <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1PF.html#5a49463a88ee80771a464861df845ff6" title="Log all samples.">opt_L_wei</a>; 
     82<a name="l00053"></a>00053  
     83<a name="l00054"></a>00054 <span class="keyword">public</span>: 
     84<a name="l00057"></a>00057         <a class="code" href="classbdm_1_1PF.html" title="Trivial particle filter with proposal density equal to parameter evolution model...">PF</a> ( ) :<a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>(), <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( <a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>() ),<a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( <a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a>() ), <a class="code" href="classbdm_1_1PF.html#98ef9ff80c394fafd28680b7a3f831b1" title="Log all samples.">opt_L_smp</a> ( false ), <a class="code" href="classbdm_1_1PF.html#5a49463a88ee80771a464861df845ff6" title="Log all samples.">opt_L_wei</a> ( false ) {<a class="code" href="classbdm_1_1BM.html#109c1a626a69031658e3a44e9e500cca" title="IDs of storages in loggers.">LIDs</a>.set_size ( 5 );}; 
     85<a name="l00058"></a>00058         <span class="comment">/*      PF ( mpdf *par0, mpdf *obs0, epdf *epdf0, int n0 ) :</span> 
     86<a name="l00059"></a>00059 <span class="comment">                                est ( ),_w ( est._w() ),_samples ( est._samples() ),opt_L_smp(false), opt_L_wei(false)</span> 
     87<a name="l00060"></a>00060 <span class="comment">                { set_parameters ( par0,obs0,n0 ); set_statistics ( ones ( n0 ),epdf0 ); };*/</span> 
     88<a name="l00061"></a>00061         <span class="keywordtype">void</span> set_parameters ( <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> *par0, <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> *obs0, <span class="keywordtype">int</span> n0, RESAMPLING_METHOD rm=SYSTEMATIC ) 
     89<a name="l00062"></a>00062         { <a class="code" href="classbdm_1_1PF.html#521e9621d3b5e1274275f323691afdaf" title="Parameter evolution model.">par</a> = par0; <a class="code" href="classbdm_1_1PF.html#d6e7a62fba1e0a0d73c9b87f4fb683ec" title="Observation model.">obs</a>=obs0; <a class="code" href="classbdm_1_1PF.html#eeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>=n0; <a class="code" href="classbdm_1_1PF.html#9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>= rm;}; 
     90<a name="l00063"></a>00063         <span class="keywordtype">void</span> set_statistics ( <span class="keyword">const</span> vec w0, epdf *epdf0 ) {<a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.set_statistics ( w0,epdf0 );}; 
     91<a name="l00066"></a>00066 <span class="comment">//      void set_est ( const epdf &amp;epdf0 );</span> 
     92<a name="l00067"></a><a class="code" href="classbdm_1_1PF.html#bf104b869b5df8dd4a14bbe430d40488">00067</a>         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#bf104b869b5df8dd4a14bbe430d40488">set_options</a> ( <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;opt ) { 
     93<a name="l00068"></a>00068                 <a class="code" href="classbdm_1_1BM.html#224dd68a83c1472b43163763fa93c477" title="Set boolean options from a string.">BM::set_options</a>(opt); 
     94<a name="l00069"></a>00069                 <a class="code" href="classbdm_1_1PF.html#5a49463a88ee80771a464861df845ff6" title="Log all samples.">opt_L_wei</a>= ( opt.find ( <span class="stringliteral">"logweights"</span> ) !=string::npos ); 
     95<a name="l00070"></a>00070                 <a class="code" href="classbdm_1_1PF.html#98ef9ff80c394fafd28680b7a3f831b1" title="Log all samples.">opt_L_smp</a>= ( opt.find ( <span class="stringliteral">"logsamples"</span> ) !=string::npos ); 
     96<a name="l00071"></a>00071         } 
     97<a name="l00072"></a>00072         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#638946eea22d4964bf9350286bb4efd8" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &amp;dt ); 
     98<a name="l00074"></a><a class="code" href="classbdm_1_1PF.html#78a9f6809827be1d9bfe215d03b1c6ed">00074</a>         vec* <a class="code" href="classbdm_1_1PF.html#78a9f6809827be1d9bfe215d03b1c6ed" title="access function">__w</a>() {<span class="keywordflow">return</span> &amp;<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>;} 
     99<a name="l00075"></a>00075 }; 
     100<a name="l00076"></a>00076  
     101<a name="l00083"></a>00083 <span class="keyword">template</span>&lt;<span class="keyword">class</span> BM_T&gt; 
     102<a name="l00084"></a><a class="code" href="classbdm_1_1MPF.html">00084</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1MPF.html" title="Marginalized Particle filter.">MPF</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1PF.html" title="Trivial particle filter with proposal density equal to parameter evolution model...">PF</a> { 
     103<a name="l00085"></a>00085         Array&lt;BM_T*&gt; BMs; 
     104<a name="l00086"></a>00086  
     105<a name="l00088"></a>00088  
     106<a name="l00089"></a>00089 <span class="keyword">class </span>mpfepdf : <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>  { 
     107<a name="l00090"></a>00090         <span class="keyword">protected</span>: 
     108<a name="l00091"></a>00091                 <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> &amp;E; 
     109<a name="l00092"></a>00092                 vec &amp;<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>; 
     110<a name="l00093"></a>00093                 Array&lt;const epdf*&gt; Coms; 
     111<a name="l00094"></a>00094         <span class="keyword">public</span>: 
     112<a name="l00095"></a>00095                 mpfepdf ( <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> &amp;E0 ) : 
     113<a name="l00096"></a>00096                                 <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( ), E ( E0 ),  <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( E._w() ), 
     114<a name="l00097"></a>00097                                 Coms ( <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length() ) { 
     115<a name="l00098"></a>00098                 }; 
     116<a name="l00100"></a>00100                 <span class="keywordtype">void</span> read_statistics ( Array&lt;BM_T*&gt; &amp;A ) { 
     117<a name="l00101"></a>00101                         dim = E.dimension() +A ( 0 )-&gt;posterior().dimension(); 
     118<a name="l00102"></a>00102                         <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0; i&lt;<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length() ;i++ ) {Coms ( i ) = A ( i )-&gt;_e();} 
     119<a name="l00103"></a>00103                 } 
     120<a name="l00105"></a>00105                 <span class="keywordtype">void</span> set_elements ( <span class="keywordtype">int</span> &amp;i, <span class="keywordtype">double</span> wi, <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>* ep ) 
     121<a name="l00106"></a>00106                 {<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ) =wi; Coms ( i ) =ep;}; 
    130122<a name="l00107"></a>00107  
    131 <a name="l00109"></a>00109         mpfepdf jest; 
    132 <a name="l00110"></a>00110  
    133 <a name="l00111"></a>00111 <span class="keyword">public</span>: 
    134 <a name="l00113"></a><a class="code" href="classbdm_1_1MPF.html#ca0e773df05fd70cf8ef3a7f1b3e42ef">00113</a>         <a class="code" href="classbdm_1_1MPF.html#ca0e773df05fd70cf8ef3a7f1b3e42ef" title="Default constructor.">MPF</a> ( <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> *par0, <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> *obs0, <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1PF.html#eeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>, <span class="keyword">const</span> BM_T &amp;BMcond0 ) : <a class="code" href="classbdm_1_1PF.html" title="Trivial particle filter with proposal density equal to parameter evolution model...">PF</a> (), jest ( <a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a> ) { 
    135 <a name="l00114"></a>00114                 PF::set_parameters(par0,obs0,n); 
    136 <a name="l00115"></a>00115                 jest.set_n(n); 
    137 <a name="l00116"></a>00116                 <span class="comment">//</span> 
    138 <a name="l00117"></a>00117                 <span class="comment">//TODO test if rv and BMcond.rv are compatible.</span> 
    139 <a name="l00118"></a>00118 <span class="comment">//              rv.add ( rvlin );</span> 
    140 <a name="l00119"></a>00119                 <span class="comment">//</span> 
    141 <a name="l00120"></a>00120  
    142 <a name="l00121"></a>00121                 <span class="keywordflow">if</span> ( n&gt;10000 ) {it_error ( <span class="stringliteral">"increase 10000 here!"</span> );} 
    143 <a name="l00122"></a>00122  
    144 <a name="l00123"></a>00123                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i&lt;n;i++ ) { 
    145 <a name="l00124"></a>00124                         Bms[i] = <span class="keyword">new</span> BM_T ( BMcond0 ); <span class="comment">//copy constructor</span> 
    146 <a name="l00125"></a>00125                         <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>&amp; pom=Bms[i]-&gt;posterior(); 
    147 <a name="l00126"></a>00126                         jest.set_elements ( i,1.0/n,&amp;pom ); 
     123<a name="l00108"></a>00108                 <span class="keywordtype">void</span> set_parameters ( <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1PF.html#eeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a> ) { 
     124<a name="l00109"></a>00109                         E.set_parameters ( n, <span class="keyword">false</span> ); 
     125<a name="l00110"></a>00110                         Coms.set_length ( n ); 
     126<a name="l00111"></a>00111                 } 
     127<a name="l00112"></a>00112                 vec mean()<span class="keyword"> const </span>{ 
     128<a name="l00113"></a>00113                         <span class="comment">// ugly</span> 
     129<a name="l00114"></a>00114                         vec pom=zeros ( Coms ( 0 )-&gt;dimension() ); 
     130<a name="l00115"></a>00115                         <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0; i&lt;<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length(); i++ ) {pom += Coms ( i )-&gt;mean() * <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i );} 
     131<a name="l00116"></a>00116                         <span class="keywordflow">return</span> concat ( E.mean(),pom ); 
     132<a name="l00117"></a>00117                 } 
     133<a name="l00118"></a>00118                 vec variance()<span class="keyword"> const </span>{ 
     134<a name="l00119"></a>00119                         <span class="comment">// ugly</span> 
     135<a name="l00120"></a>00120                         vec pom=zeros ( Coms ( 0 )-&gt;dimension() ); 
     136<a name="l00121"></a>00121                         vec pom2=zeros ( Coms ( 0 )-&gt;dimension() ); 
     137<a name="l00122"></a>00122                         <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0; i&lt;<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length(); i++ ) { 
     138<a name="l00123"></a>00123                                 pom += Coms ( i )-&gt;mean() * <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ); 
     139<a name="l00124"></a>00124                                 pom2 += ( Coms ( i )-&gt;variance() + pow ( Coms ( i )-&gt;mean(),2 ) ) * <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ); 
     140<a name="l00125"></a>00125                         } 
     141<a name="l00126"></a>00126                         <span class="keywordflow">return</span> concat ( E.variance(),pom2-pow ( pom,2 ) ); 
    148142<a name="l00127"></a>00127                 } 
    149 <a name="l00128"></a>00128         }; 
    150 <a name="l00129"></a>00129  
    151 <a name="l00130"></a>00130         ~<a class="code" href="classbdm_1_1MPF.html" title="Marginalized Particle filter.">MPF</a>() { 
    152 <a name="l00131"></a>00131         } 
    153 <a name="l00132"></a>00132  
    154 <a name="l00133"></a>00133         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#286d040770d08bd7ff416cea617b1b14" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &amp;dt ); 
    155 <a name="l00134"></a>00134         <span class="keyword">const</span> epdf&amp; posterior()<span class="keyword"> const </span>{<span class="keywordflow">return</span> jest;} 
    156 <a name="l00135"></a>00135         <span class="keyword">const</span> epdf* _e()<span class="keyword"> const </span>{<span class="keywordflow">return</span> &amp;jest;} <span class="comment">//Fixme: is it useful?</span> 
    157 <a name="l00137"></a><a class="code" href="classbdm_1_1MPF.html#dcecdaf2acbbee51acf3018a70989a7e">00137</a> <span class="comment"></span>        <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#dcecdaf2acbbee51acf3018a70989a7e" title="Set postrior of rvc to samples from epdf0. Statistics of Bms are not re-computed!...">set_est</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>&amp; epdf0 ) { 
    158 <a name="l00138"></a>00138                 <a class="code" href="classbdm_1_1PF.html#6f1988db4c3f602d187a6c15ec89cb1e">PF::set_est</a> ( epdf0 );  <span class="comment">// sample params in condition</span> 
    159 <a name="l00139"></a>00139                 <span class="comment">// copy conditions to BMs</span> 
    160 <a name="l00140"></a>00140  
    161 <a name="l00141"></a>00141                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i&lt;<a class="code" href="classbdm_1_1PF.html#eeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>;i++ ) {Bms[i]-&gt;condition ( <a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ) );} 
    162 <a name="l00142"></a>00142         } 
    163 <a name="l00143"></a>00143  
    164 <a name="l00145"></a><a class="code" href="classbdm_1_1MPF.html#82b5a34d9ed0e78452f98d2ecbf1e93c">00145</a>         <a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a>* <a class="code" href="classbdm_1_1MPF.html#82b5a34d9ed0e78452f98d2ecbf1e93c" title="Access function.">_BM</a> ( <span class="keywordtype">int</span> i ) {<span class="keywordflow">return</span> Bms[i];} 
    165 <a name="l00146"></a>00146 }; 
    166 <a name="l00147"></a>00147  
    167 <a name="l00148"></a>00148 <span class="keyword">template</span>&lt;<span class="keyword">class</span> BM_T&gt; 
    168 <a name="l00149"></a><a class="code" href="classbdm_1_1MPF.html#286d040770d08bd7ff416cea617b1b14">00149</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html" title="Marginalized Particle filter.">MPF&lt;BM_T&gt;::bayes</a> ( <span class="keyword">const</span> vec &amp;dt ) { 
    169 <a name="l00150"></a>00150         <span class="keywordtype">int</span> i; 
    170 <a name="l00151"></a>00151         vec lls ( <a class="code" href="classbdm_1_1PF.html#eeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a> ); 
    171 <a name="l00152"></a>00152         vec llsP ( <a class="code" href="classbdm_1_1PF.html#eeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a> ); 
    172 <a name="l00153"></a>00153         ivec ind; 
    173 <a name="l00154"></a>00154         <span class="keywordtype">double</span> mlls=-std::numeric_limits&lt;double&gt;::infinity(); 
    174 <a name="l00155"></a>00155  
    175 <a name="l00156"></a>00156 <span class="preprocessor">#pragma omp parallel for</span> 
    176 <a name="l00157"></a>00157 <span class="preprocessor"></span>        <span class="keywordflow">for</span> ( i=0;i&lt;<a class="code" href="classbdm_1_1PF.html#eeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>;i++ ) { 
    177 <a name="l00158"></a>00158                 <span class="comment">//generate new samples from paramater evolution model;</span> 
    178 <a name="l00159"></a>00159                 <a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ) = <a class="code" href="classbdm_1_1PF.html#521e9621d3b5e1274275f323691afdaf" title="Parameter evolution model.">par</a>-&gt;<a class="code" href="classbdm_1_1mpdf.html#f0c1db6fcbb3aae2dd6123884457a367" title="Returns a sample from the density conditioned on cond, .">samplecond</a> ( <a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ) ); 
    179 <a name="l00160"></a>00160                 llsP ( i ) = <a class="code" href="classbdm_1_1PF.html#521e9621d3b5e1274275f323691afdaf" title="Parameter evolution model.">par</a>-&gt;<a class="code" href="classbdm_1_1mpdf.html#05e843fd11c410a99dad2b88c55aca80">_e</a>()-&gt;<a class="code" href="classbdm_1_1epdf.html#deab266d63c236c277538867d5c3f249" title="Compute log-probability of argument val.">evallog</a> ( <a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ) ); 
    180 <a name="l00161"></a>00161                 Bms[i]-&gt;condition ( <a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ) ); 
    181 <a name="l00162"></a>00162                 Bms[i]-&gt;bayes ( dt ); 
    182 <a name="l00163"></a>00163                 lls ( i ) = Bms[i]-&gt;_ll(); <span class="comment">// lls above is also in proposal her must be lls(i) =, not +=!!</span> 
    183 <a name="l00164"></a>00164                 <span class="keywordflow">if</span> ( lls ( i ) &gt;mlls ) mlls=lls ( i ); <span class="comment">//find maximum likelihood (for numerical stability)</span> 
    184 <a name="l00165"></a>00165         } 
    185 <a name="l00166"></a>00166  
    186 <a name="l00167"></a>00167         <span class="keywordtype">double</span> sum_w=0.0; 
    187 <a name="l00168"></a>00168         <span class="comment">// compute weights</span> 
    188 <a name="l00169"></a>00169 <span class="preprocessor">#pragma omp parallel for</span> 
    189 <a name="l00170"></a>00170 <span class="preprocessor"></span>        <span class="keywordflow">for</span> ( i=0;i&lt;n;i++ ) { 
    190 <a name="l00171"></a>00171                 <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ) *= exp ( lls ( i ) - mlls ); <span class="comment">// multiply w by likelihood</span> 
    191 <a name="l00172"></a>00172                 sum_w+=<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ); 
    192 <a name="l00173"></a>00173         } 
    193 <a name="l00174"></a>00174  
    194 <a name="l00175"></a>00175         <span class="keywordflow">if</span> ( sum_w  &gt;0.0 ) { 
    195 <a name="l00176"></a>00176                 <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> /=sum_w; <span class="comment">//?</span> 
    196 <a name="l00177"></a>00177         } 
    197 <a name="l00178"></a>00178         <span class="keywordflow">else</span> { 
    198 <a name="l00179"></a>00179                 cout&lt;&lt;<span class="stringliteral">"sum(w)==0"</span>&lt;&lt;endl; 
    199 <a name="l00180"></a>00180         } 
    200 <a name="l00181"></a>00181  
     143<a name="l00128"></a>00128                 <span class="keywordtype">void</span> qbounds ( vec &amp;lb, vec &amp;ub, <span class="keywordtype">double</span> perc=0.95 )<span class="keyword"> const </span>{ 
     144<a name="l00129"></a>00129                         <span class="comment">//bounds on particles</span> 
     145<a name="l00130"></a>00130                         vec lbp; 
     146<a name="l00131"></a>00131                         vec ubp; 
     147<a name="l00132"></a>00132                         E.qbounds ( lbp,ubp ); 
     148<a name="l00133"></a>00133  
     149<a name="l00134"></a>00134                         <span class="comment">//bounds on Components</span> 
     150<a name="l00135"></a>00135                         <span class="keywordtype">int</span> dimC=Coms ( 0 )-&gt;dimension(); 
     151<a name="l00136"></a>00136                         <span class="keywordtype">int</span> j; 
     152<a name="l00137"></a>00137                         <span class="comment">// temporary</span> 
     153<a name="l00138"></a>00138                         vec lbc(dimC); 
     154<a name="l00139"></a>00139                         vec ubc(dimC); 
     155<a name="l00140"></a>00140                         <span class="comment">// minima and maxima</span> 
     156<a name="l00141"></a>00141                         vec Lbc(dimC); 
     157<a name="l00142"></a>00142                         vec Ubc(dimC); 
     158<a name="l00143"></a>00143                         Lbc = std::numeric_limits&lt;double&gt;::infinity(); 
     159<a name="l00144"></a>00144                         Ubc = -std::numeric_limits&lt;double&gt;::infinity(); 
     160<a name="l00145"></a>00145  
     161<a name="l00146"></a>00146                         <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i&lt;<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length();i++ ) { 
     162<a name="l00147"></a>00147                                 <span class="comment">// check Coms</span> 
     163<a name="l00148"></a>00148                                 Coms ( i )-&gt;qbounds ( lbc,ubc ); 
     164<a name="l00149"></a>00149                                 <span class="keywordflow">for</span> ( j=0;j&lt;dimC; j++ ) { 
     165<a name="l00150"></a>00150                                         <span class="keywordflow">if</span> ( lbc ( j ) &lt;Lbc ( j ) ) {Lbc ( j ) =lbc ( j );} 
     166<a name="l00151"></a>00151                                         <span class="keywordflow">if</span> ( ubc ( j ) &gt;Ubc ( j ) ) {Ubc ( j ) =ubc ( j );} 
     167<a name="l00152"></a>00152                                 } 
     168<a name="l00153"></a>00153                         } 
     169<a name="l00154"></a>00154                         lb=concat(lbp,Lbc); 
     170<a name="l00155"></a>00155                         ub=concat(ubp,Ubc); 
     171<a name="l00156"></a>00156                 } 
     172<a name="l00157"></a>00157  
     173<a name="l00158"></a>00158                 vec sample()<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"Not implemented"</span> );<span class="keywordflow">return</span> 0;} 
     174<a name="l00159"></a>00159  
     175<a name="l00160"></a>00160                 <span class="keywordtype">double</span> evallog ( <span class="keyword">const</span> vec &amp;val )<span class="keyword"> const </span>{it_error ( <span class="stringliteral">"not implemented"</span> ); <span class="keywordflow">return</span> 0.0;} 
     176<a name="l00161"></a>00161         }; 
     177<a name="l00162"></a>00162  
     178<a name="l00164"></a>00164         mpfepdf jest; 
     179<a name="l00165"></a>00165  
     180<a name="l00167"></a>00167         <span class="keywordtype">bool</span> opt_L_mea; 
     181<a name="l00168"></a>00168  
     182<a name="l00169"></a>00169 <span class="keyword">public</span>: 
     183<a name="l00171"></a><a class="code" href="classbdm_1_1MPF.html#0068e7ca53d90fa5911eb31a0d657f26">00171</a>         <a class="code" href="classbdm_1_1MPF.html#0068e7ca53d90fa5911eb31a0d657f26" title="Default constructor.">MPF</a> () : <a class="code" href="classbdm_1_1PF.html" title="Trivial particle filter with proposal density equal to parameter evolution model...">PF</a> (), jest ( <a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a> ) {}; 
     184<a name="l00172"></a>00172         <span class="keywordtype">void</span> set_parameters ( <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> *par0, <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> *obs0, <span class="keywordtype">int</span> n0, RESAMPLING_METHOD rm=SYSTEMATIC ) { 
     185<a name="l00173"></a>00173                 PF::set_parameters ( par0, obs0, n0, rm ); 
     186<a name="l00174"></a>00174                 jest.set_parameters ( n0 );<span class="comment">//duplication of rm</span> 
     187<a name="l00175"></a>00175                 BMs.set_length ( n0 ); 
     188<a name="l00176"></a>00176         } 
     189<a name="l00177"></a>00177         <span class="keywordtype">void</span> set_statistics ( epdf *epdf0, <span class="keyword">const</span> BM_T* BMcond0 ) { 
     190<a name="l00178"></a>00178  
     191<a name="l00179"></a>00179                 PF::set_statistics ( ones ( <a class="code" href="classbdm_1_1PF.html#eeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a> ) /<a class="code" href="classbdm_1_1PF.html#eeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>, epdf0 ); 
     192<a name="l00180"></a>00180                 <span class="comment">// copy</span> 
     193<a name="l00181"></a>00181                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i&lt;<a class="code" href="classbdm_1_1PF.html#eeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>;i++ ) { BMs ( i ) = <span class="keyword">new</span> BM_T ( *BMcond0 ); BMs ( i )-&gt;condition ( <a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ) );} 
    201194<a name="l00182"></a>00182  
    202 <a name="l00183"></a>00183         <span class="keywordtype">double</span> eff = 1.0/ ( <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>*<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ); 
    203 <a name="l00184"></a>00184         <span class="keywordflow">if</span> ( eff &lt; ( 0.3*n ) ) { 
    204 <a name="l00185"></a>00185                 ind = <a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1eEmp.html#f06ce255de5dbb2313f52ee51f82ba3d" title="Function performs resampling, i.e. removal of low-weight samples and duplication...">resample</a>(); 
    205 <a name="l00186"></a>00186                 <span class="comment">// Resample Bms!</span> 
    206 <a name="l00187"></a>00187  
    207 <a name="l00188"></a>00188 <span class="preprocessor">#pragma omp parallel for</span> 
    208 <a name="l00189"></a>00189 <span class="preprocessor"></span>                <span class="keywordflow">for</span> ( i=0;i&lt;n;i++ ) { 
    209 <a name="l00190"></a>00190                         <span class="keywordflow">if</span> ( ind ( i ) !=i ) {<span class="comment">//replace the current Bm by a new one</span> 
    210 <a name="l00191"></a>00191                                 <span class="comment">//fixme this would require new assignment operator</span> 
    211 <a name="l00192"></a>00192                                 <span class="comment">// *Bms[i] = *Bms[ind ( i ) ];</span> 
    212 <a name="l00193"></a>00193  
    213 <a name="l00194"></a>00194                                 <span class="comment">// poor-man's solution: replicate constructor here</span> 
    214 <a name="l00195"></a>00195                                 <span class="comment">// copied from MPF::MPF</span> 
    215 <a name="l00196"></a>00196                                 <span class="keyword">delete</span> Bms[i]; 
    216 <a name="l00197"></a>00197                                 Bms[i] = <span class="keyword">new</span> BM_T ( *Bms[ind ( i ) ] ); <span class="comment">//copy constructor</span> 
    217 <a name="l00198"></a>00198                                 <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>&amp; pom=Bms[i]-&gt;posterior(); 
    218 <a name="l00199"></a>00199                                 jest.set_elements ( i,1.0/n,&amp;pom ); 
    219 <a name="l00200"></a>00200                         } 
    220 <a name="l00201"></a>00201                 }; 
    221 <a name="l00202"></a>00202                 cout &lt;&lt; <span class="charliteral">'.'</span>; 
    222 <a name="l00203"></a>00203         } 
    223 <a name="l00204"></a>00204 } 
     195<a name="l00183"></a>00183                 jest.read_statistics ( BMs ); 
     196<a name="l00184"></a>00184                 <span class="comment">//options</span> 
     197<a name="l00185"></a>00185         }; 
     198<a name="l00186"></a>00186  
     199<a name="l00187"></a>00187         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#286d040770d08bd7ff416cea617b1b14" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &amp;dt ); 
     200<a name="l00188"></a>00188         <span class="keyword">const</span> epdf&amp; posterior()<span class="keyword"> const </span>{<span class="keywordflow">return</span> jest;} 
     201<a name="l00189"></a>00189         <span class="keyword">const</span> epdf* _e()<span class="keyword"> const </span>{<span class="keywordflow">return</span> &amp;jest;} <span class="comment">//Fixme: is it useful?</span> 
     202<a name="l00191"></a>00191 <span class="comment"></span>        <span class="comment">/*      void set_est ( const epdf&amp; epdf0 ) {</span> 
     203<a name="l00192"></a>00192 <span class="comment">                        PF::set_est ( epdf0 );  // sample params in condition</span> 
     204<a name="l00193"></a>00193 <span class="comment">                        // copy conditions to BMs</span> 
     205<a name="l00194"></a>00194 <span class="comment"></span> 
     206<a name="l00195"></a>00195 <span class="comment">                        for ( int i=0;i&lt;n;i++ ) {BMs(i)-&gt;condition ( _samples ( i ) );}</span> 
     207<a name="l00196"></a>00196 <span class="comment">                }*/</span> 
     208<a name="l00197"></a><a class="code" href="classbdm_1_1MPF.html#2e95498dec734088ab9f4878ff404144">00197</a>         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#2e95498dec734088ab9f4878ff404144" title="Set postrior of rvc to samples from epdf0. Statistics of BMs are not re-computed!...">set_options</a> ( <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;opt ) { 
     209<a name="l00198"></a>00198                 <a class="code" href="classbdm_1_1PF.html#bf104b869b5df8dd4a14bbe430d40488">PF::set_options</a> ( opt ); 
     210<a name="l00199"></a>00199                 opt_L_mea = ( opt.find ( <span class="stringliteral">"logmeans"</span> ) !=string::npos ); 
     211<a name="l00200"></a>00200         } 
     212<a name="l00201"></a>00201  
     213<a name="l00203"></a><a class="code" href="classbdm_1_1MPF.html#82b5a34d9ed0e78452f98d2ecbf1e93c">00203</a>         <a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a>* <a class="code" href="classbdm_1_1MPF.html#82b5a34d9ed0e78452f98d2ecbf1e93c" title="Access function.">_BM</a> ( <span class="keywordtype">int</span> i ) {<span class="keywordflow">return</span> BMs ( i );} 
     214<a name="l00204"></a>00204 }; 
    224215<a name="l00205"></a>00205  
    225 <a name="l00206"></a>00206 } 
    226 <a name="l00207"></a>00207 <span class="preprocessor">#endif // KF_H</span> 
    227 <a name="l00208"></a>00208 <span class="preprocessor"></span> 
    228 <a name="l00209"></a>00209  
     216<a name="l00206"></a>00206 <span class="keyword">template</span>&lt;<span class="keyword">class</span> BM_T&gt; 
     217<a name="l00207"></a><a class="code" href="classbdm_1_1MPF.html#286d040770d08bd7ff416cea617b1b14">00207</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html" title="Marginalized Particle filter.">MPF&lt;BM_T&gt;::bayes</a> ( <span class="keyword">const</span> vec &amp;dt ) { 
     218<a name="l00208"></a>00208         <span class="keywordtype">int</span> i; 
     219<a name="l00209"></a>00209         vec lls ( n ); 
     220<a name="l00210"></a>00210         vec llsP ( n ); 
     221<a name="l00211"></a>00211         ivec ind; 
     222<a name="l00212"></a>00212         <span class="keywordtype">double</span> mlls=-std::numeric_limits&lt;double&gt;::infinity(); 
     223<a name="l00213"></a>00213  
     224<a name="l00214"></a>00214 <span class="preprocessor">#pragma omp parallel for</span> 
     225<a name="l00215"></a>00215 <span class="preprocessor"></span>        <span class="keywordflow">for</span> ( i=0;i&lt;n;i++ ) { 
     226<a name="l00216"></a>00216                 <span class="comment">//generate new samples from paramater evolution model;</span> 
     227<a name="l00217"></a>00217                 <a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ) = <a class="code" href="classbdm_1_1PF.html#521e9621d3b5e1274275f323691afdaf" title="Parameter evolution model.">par</a>-&gt;<a class="code" href="classbdm_1_1mpdf.html#f0c1db6fcbb3aae2dd6123884457a367" title="Returns a sample from the density conditioned on cond, .">samplecond</a> ( <a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ) ); 
     228<a name="l00218"></a>00218                 llsP ( i ) = <a class="code" href="classbdm_1_1PF.html#521e9621d3b5e1274275f323691afdaf" title="Parameter evolution model.">par</a>-&gt;<a class="code" href="classbdm_1_1mpdf.html#05e843fd11c410a99dad2b88c55aca80">_e</a>()-&gt;<a class="code" href="classbdm_1_1epdf.html#deab266d63c236c277538867d5c3f249" title="Compute log-probability of argument val.">evallog</a> ( <a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ) ); 
     229<a name="l00219"></a>00219                 BMs ( i )-&gt;condition ( <a class="code" href="classbdm_1_1PF.html#914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ) ); 
     230<a name="l00220"></a>00220                 BMs ( i )-&gt;bayes ( dt ); 
     231<a name="l00221"></a>00221                 lls ( i ) = BMs ( i )-&gt;_ll(); <span class="comment">// lls above is also in proposal her must be lls(i) =, not +=!!</span> 
     232<a name="l00222"></a>00222                 <span class="keywordflow">if</span> ( lls ( i ) &gt;mlls ) mlls=lls ( i ); <span class="comment">//find maximum likelihood (for numerical stability)</span> 
     233<a name="l00223"></a>00223         } 
     234<a name="l00224"></a>00224  
     235<a name="l00225"></a>00225         <span class="keywordtype">double</span> sum_w=0.0; 
     236<a name="l00226"></a>00226         <span class="comment">// compute weights</span> 
     237<a name="l00227"></a>00227 <span class="preprocessor">#pragma omp parallel for</span> 
     238<a name="l00228"></a>00228 <span class="preprocessor"></span>        <span class="keywordflow">for</span> ( i=0;i&lt;n;i++ ) { 
     239<a name="l00229"></a>00229                 <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ) *= exp ( lls ( i ) - mlls ); <span class="comment">// multiply w by likelihood</span> 
     240<a name="l00230"></a>00230                 sum_w+=<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ); 
     241<a name="l00231"></a>00231         } 
     242<a name="l00232"></a>00232  
     243<a name="l00233"></a>00233         <span class="keywordflow">if</span> ( sum_w  &gt;0.0 ) { 
     244<a name="l00234"></a>00234                 <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> /=sum_w; <span class="comment">//?</span> 
     245<a name="l00235"></a>00235         } 
     246<a name="l00236"></a>00236         <span class="keywordflow">else</span> { 
     247<a name="l00237"></a>00237                 cout&lt;&lt;<span class="stringliteral">"sum(w)==0"</span>&lt;&lt;endl; 
     248<a name="l00238"></a>00238         } 
     249<a name="l00239"></a>00239  
     250<a name="l00240"></a>00240  
     251<a name="l00241"></a>00241         <span class="keywordtype">double</span> eff = 1.0/ ( <a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>*<a class="code" href="classbdm_1_1PF.html#f5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ); 
     252<a name="l00242"></a>00242         <span class="keywordflow">if</span> ( eff &lt; ( 0.3*n ) ) { 
     253<a name="l00243"></a>00243                 ind = <a class="code" href="classbdm_1_1PF.html#dc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1eEmp.html#f06ce255de5dbb2313f52ee51f82ba3d" title="Function performs resampling, i.e. removal of low-weight samples and duplication...">resample</a> ( <a class="code" href="classbdm_1_1PF.html#9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a> ); 
     254<a name="l00244"></a>00244                 <span class="comment">// Resample Bms!</span> 
     255<a name="l00245"></a>00245  
     256<a name="l00246"></a>00246 <span class="preprocessor">#pragma omp parallel for</span> 
     257<a name="l00247"></a>00247 <span class="preprocessor"></span>                <span class="keywordflow">for</span> ( i=0;i&lt;n;i++ ) { 
     258<a name="l00248"></a>00248                         <span class="keywordflow">if</span> ( ind ( i ) !=i ) {<span class="comment">//replace the current Bm by a new one</span> 
     259<a name="l00249"></a>00249                                 <span class="comment">//fixme this would require new assignment operator</span> 
     260<a name="l00250"></a>00250                                 <span class="comment">// *Bms[i] = *Bms[ind ( i ) ];</span> 
     261<a name="l00251"></a>00251  
     262<a name="l00252"></a>00252                                 <span class="comment">// poor-man's solution: replicate constructor here</span> 
     263<a name="l00253"></a>00253                                 <span class="comment">// copied from MPF::MPF</span> 
     264<a name="l00254"></a>00254                                 <span class="keyword">delete</span> BMs ( i ); 
     265<a name="l00255"></a>00255                                 BMs ( i ) = <span class="keyword">new</span> BM_T ( *BMs ( ind ( i ) ) ); <span class="comment">//copy constructor</span> 
     266<a name="l00256"></a>00256                                 <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>&amp; pom=BMs ( i )-&gt;posterior(); 
     267<a name="l00257"></a>00257                                 jest.set_elements ( i,1.0/n,&amp;pom ); 
     268<a name="l00258"></a>00258                         } 
     269<a name="l00259"></a>00259                 }; 
     270<a name="l00260"></a>00260                 cout &lt;&lt; <span class="charliteral">'.'</span>; 
     271<a name="l00261"></a>00261         } 
     272<a name="l00262"></a>00262 } 
     273<a name="l00263"></a>00263  
     274<a name="l00264"></a>00264 } 
     275<a name="l00265"></a>00265 <span class="preprocessor">#endif // KF_H</span> 
     276<a name="l00266"></a>00266 <span class="preprocessor"></span> 
     277<a name="l00267"></a>00267  
    229278</pre></div></div> 
    230 <hr size="1"><address style="text-align: right;"><small>Generated on Wed Feb 18 17:38:40 2009 for mixpp by&nbsp; 
     279<hr size="1"><address style="text-align: right;"><small>Generated on Wed Mar 4 18:50:11 2009 for mixpp by&nbsp; 
    231280<a href="http://www.doxygen.org/index.html"> 
    232281<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>