Show
Ignore:
Timestamp:
09/27/09 00:58:34 (15 years ago)
Author:
smidl
Message:

doc

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/doc/html/particles_8h_source.html

    r632 r641  
    8080<a name="l00034"></a><a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3">00034</a>         vec &amp;<a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>; 
    8181<a name="l00036"></a><a class="code" href="classbdm_1_1PF.html#a914bd66025692c4018dbd482cb3c47c1">00036</a>         Array&lt;vec&gt; &amp;<a class="code" href="classbdm_1_1PF.html#a914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a>; 
    82 <a name="l00038"></a><a class="code" href="classbdm_1_1PF.html#a521e9621d3b5e1274275f323691afdaf">00038</a>         <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling , where  is random variable, rv, and...">mpdf</a> *<a class="code" href="classbdm_1_1PF.html#a521e9621d3b5e1274275f323691afdaf" title="Parameter evolution model.">par</a>; 
    83 <a name="l00040"></a><a class="code" href="classbdm_1_1PF.html#ad6e7a62fba1e0a0d73c9b87f4fb683ec">00040</a>         <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling , where  is random variable, rv, and...">mpdf</a> *<a class="code" href="classbdm_1_1PF.html#ad6e7a62fba1e0a0d73c9b87f4fb683ec" title="Observation model.">obs</a>; 
    84 <a name="l00041"></a>00041  
    85 <a name="l00043"></a><a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52">00043</a>         RESAMPLING_METHOD <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>; 
    86 <a name="l00044"></a>00044  
    87 <a name="l00047"></a>00047  
    88 <a name="l00049"></a><a class="code" href="classbdm_1_1PF.html#a98ef9ff80c394fafd28680b7a3f831b1">00049</a>         <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1PF.html#a98ef9ff80c394fafd28680b7a3f831b1" title="Log all samples.">opt_L_smp</a>; 
    89 <a name="l00051"></a><a class="code" href="classbdm_1_1PF.html#a5a49463a88ee80771a464861df845ff6">00051</a>         <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1PF.html#a5a49463a88ee80771a464861df845ff6" title="Log all samples.">opt_L_wei</a>; 
    90 <a name="l00053"></a>00053  
    91 <a name="l00054"></a>00054 <span class="keyword">public</span>: 
    92 <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#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>(), <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( <a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>() ), <a class="code" href="classbdm_1_1PF.html#a914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( <a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1PF.html#a914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a>() ), <a class="code" href="classbdm_1_1PF.html#a98ef9ff80c394fafd28680b7a3f831b1" title="Log all samples.">opt_L_smp</a> ( false ), <a class="code" href="classbdm_1_1PF.html#a5a49463a88ee80771a464861df845ff6" title="Log all samples.">opt_L_wei</a> ( false ) { 
    93 <a name="l00058"></a>00058                 <a class="code" href="classbdm_1_1BM.html#a109c1a626a69031658e3a44e9e500cca" title="IDs of storages in loggers 4:[1=mean,2=lb,3=ub,4=ll].">LIDs</a>.set_size ( 5 ); 
    94 <a name="l00059"></a>00059         }; 
    95 <a name="l00060"></a>00060         <span class="comment">/*      PF ( mpdf *par0, mpdf *obs0, epdf *epdf0, int n0 ) :</span> 
    96 <a name="l00061"></a>00061 <span class="comment">                                est ( ),_w ( est._w() ),_samples ( est._samples() ),opt_L_smp(false), opt_L_wei(false)</span> 
    97 <a name="l00062"></a>00062 <span class="comment">                { set_parameters ( par0,obs0,n0 ); set_statistics ( ones ( n0 ),epdf0 ); };*/</span> 
    98 <a name="l00063"></a>00063         <span class="keywordtype">void</span> set_parameters ( <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling , where  is random variable, rv, and...">mpdf</a> *par0, <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling , where  is random variable, rv, and...">mpdf</a> *obs0, <span class="keywordtype">int</span> n0, RESAMPLING_METHOD rm = SYSTEMATIC ) { 
    99 <a name="l00064"></a>00064                 <a class="code" href="classbdm_1_1PF.html#a521e9621d3b5e1274275f323691afdaf" title="Parameter evolution model.">par</a> = par0; 
    100 <a name="l00065"></a>00065                 <a class="code" href="classbdm_1_1PF.html#ad6e7a62fba1e0a0d73c9b87f4fb683ec" title="Observation model.">obs</a> = obs0; 
    101 <a name="l00066"></a>00066                 <a class="code" href="classbdm_1_1PF.html#aeeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a> = n0; 
    102 <a name="l00067"></a>00067                 <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a> = rm; 
    103 <a name="l00068"></a>00068         }; 
    104 <a name="l00069"></a>00069         <span class="keywordtype">void</span> set_statistics ( <span class="keyword">const</span> vec w0, <span class="keyword">const</span> epdf &amp;epdf0 ) { 
    105 <a name="l00070"></a>00070                 <a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.set_statistics ( w0, epdf0 ); 
    106 <a name="l00071"></a>00071         }; 
    107 <a name="l00074"></a>00074 <span class="comment">//      void set_est ( const epdf &amp;epdf0 );</span> 
    108 <a name="l00075"></a><a class="code" href="classbdm_1_1PF.html#abf104b869b5df8dd4a14bbe430d40488">00075</a>         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#abf104b869b5df8dd4a14bbe430d40488">set_options</a> ( <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;opt ) { 
    109 <a name="l00076"></a>00076                 <a class="code" href="classbdm_1_1PF.html#abf104b869b5df8dd4a14bbe430d40488">BM::set_options</a> ( opt ); 
    110 <a name="l00077"></a>00077                 <a class="code" href="classbdm_1_1PF.html#a5a49463a88ee80771a464861df845ff6" title="Log all samples.">opt_L_wei</a> = ( opt.find ( <span class="stringliteral">&quot;logweights&quot;</span> ) != string::npos ); 
    111 <a name="l00078"></a>00078                 <a class="code" href="classbdm_1_1PF.html#a98ef9ff80c394fafd28680b7a3f831b1" title="Log all samples.">opt_L_smp</a> = ( opt.find ( <span class="stringliteral">&quot;logsamples&quot;</span> ) != string::npos ); 
    112 <a name="l00079"></a>00079         } 
    113 <a name="l00080"></a>00080         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#a638946eea22d4964bf9350286bb4efd8" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &amp;dt ); 
    114 <a name="l00082"></a><a class="code" href="classbdm_1_1PF.html#a78a9f6809827be1d9bfe215d03b1c6ed">00082</a>         vec* <a class="code" href="classbdm_1_1PF.html#a78a9f6809827be1d9bfe215d03b1c6ed" title="access function">__w</a>() { 
    115 <a name="l00083"></a>00083                 <span class="keywordflow">return</span> &amp;<a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>; 
    116 <a name="l00084"></a>00084         } 
    117 <a name="l00085"></a>00085 }; 
    118 <a name="l00086"></a>00086  
    119 <a name="l00093"></a>00093 <span class="keyword">template</span>&lt;<span class="keyword">class</span> BM_T&gt; 
    120 <a name="l00094"></a><a class="code" href="classbdm_1_1MPF.html">00094</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> { 
    121 <a name="l00095"></a>00095         Array&lt;BM_T*&gt; BMs; 
    122 <a name="l00096"></a>00096  
    123 <a name="l00098"></a>00098  
    124 <a name="l00099"></a>00099         <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>  { 
    125 <a name="l00100"></a>00100         <span class="keyword">protected</span>: 
    126 <a name="l00101"></a>00101                 <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> &amp;E; 
    127 <a name="l00102"></a>00102                 vec &amp;<a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>; 
    128 <a name="l00103"></a>00103                 Array&lt;const epdf*&gt; Coms; 
    129 <a name="l00104"></a>00104         <span class="keyword">public</span>: 
    130 <a name="l00105"></a>00105                 mpfepdf ( <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> &amp;E0 ) : 
    131 <a name="l00106"></a>00106                                 <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#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( E._w() ), 
    132 <a name="l00107"></a>00107                                 Coms ( <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length() ) { 
    133 <a name="l00108"></a>00108                 }; 
    134 <a name="l00110"></a>00110                 <span class="keywordtype">void</span> read_statistics ( Array&lt;BM_T*&gt; &amp;A ) { 
    135 <a name="l00111"></a>00111                         dim = E.dimension() + A ( 0 )-&gt;posterior().dimension(); 
    136 <a name="l00112"></a>00112                         <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length() ; i++ ) { 
    137 <a name="l00113"></a>00113                                 Coms ( i ) = &amp;(A ( i )-&gt;posterior()); 
    138 <a name="l00114"></a>00114                         } 
    139 <a name="l00115"></a>00115                 } 
    140 <a name="l00117"></a>00117                 <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 ) { 
    141 <a name="l00118"></a>00118                         <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ) = wi; 
    142 <a name="l00119"></a>00119                         Coms ( i ) = ep; 
    143 <a name="l00120"></a>00120                 }; 
    144 <a name="l00121"></a>00121  
    145 <a name="l00122"></a>00122                 <span class="keywordtype">void</span> set_parameters ( <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1PF.html#aeeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a> ) { 
    146 <a name="l00123"></a>00123                         E.set_parameters ( n, <span class="keyword">false</span> ); 
    147 <a name="l00124"></a>00124                         Coms.set_length ( n ); 
    148 <a name="l00125"></a>00125                 } 
    149 <a name="l00126"></a>00126                 vec mean()<span class="keyword"> const </span>{ 
    150 <a name="l00127"></a>00127                         <span class="comment">// ugly</span> 
    151 <a name="l00128"></a>00128                         vec pom = zeros ( Coms ( 0 )-&gt;dimension() ); 
    152 <a name="l00129"></a>00129                         <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length(); i++ ) { 
    153 <a name="l00130"></a>00130                                 pom += Coms ( i )-&gt;mean() * <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ); 
    154 <a name="l00131"></a>00131                         } 
    155 <a name="l00132"></a>00132                         <span class="keywordflow">return</span> concat ( E.mean(), pom ); 
    156 <a name="l00133"></a>00133                 } 
    157 <a name="l00134"></a>00134                 vec variance()<span class="keyword"> const </span>{ 
    158 <a name="l00135"></a>00135                         <span class="comment">// ugly</span> 
    159 <a name="l00136"></a>00136                         vec pom = zeros ( Coms ( 0 )-&gt;dimension() ); 
    160 <a name="l00137"></a>00137                         vec pom2 = zeros ( Coms ( 0 )-&gt;dimension() ); 
    161 <a name="l00138"></a>00138                         <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length(); i++ ) { 
    162 <a name="l00139"></a>00139                                 pom += Coms ( i )-&gt;mean() * <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ); 
    163 <a name="l00140"></a>00140                                 pom2 += ( Coms ( i )-&gt;variance() + pow ( Coms ( i )-&gt;mean(), 2 ) ) * <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ); 
    164 <a name="l00141"></a>00141                         } 
    165 <a name="l00142"></a>00142                         <span class="keywordflow">return</span> concat ( E.variance(), pom2 - pow ( pom, 2 ) ); 
    166 <a name="l00143"></a>00143                 } 
    167 <a name="l00144"></a>00144                 <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>{ 
    168 <a name="l00145"></a>00145                         <span class="comment">//bounds on particles</span> 
    169 <a name="l00146"></a>00146                         vec lbp; 
    170 <a name="l00147"></a>00147                         vec ubp; 
    171 <a name="l00148"></a>00148                         E.qbounds ( lbp, ubp ); 
    172 <a name="l00149"></a>00149  
    173 <a name="l00150"></a>00150                         <span class="comment">//bounds on Components</span> 
    174 <a name="l00151"></a>00151                         <span class="keywordtype">int</span> dimC = Coms ( 0 )-&gt;dimension(); 
    175 <a name="l00152"></a>00152                         <span class="keywordtype">int</span> j; 
    176 <a name="l00153"></a>00153                         <span class="comment">// temporary</span> 
    177 <a name="l00154"></a>00154                         vec lbc ( dimC ); 
    178 <a name="l00155"></a>00155                         vec ubc ( dimC ); 
    179 <a name="l00156"></a>00156                         <span class="comment">// minima and maxima</span> 
    180 <a name="l00157"></a>00157                         vec Lbc ( dimC ); 
    181 <a name="l00158"></a>00158                         vec Ubc ( dimC ); 
    182 <a name="l00159"></a>00159                         Lbc = std::numeric_limits&lt;double&gt;::infinity(); 
    183 <a name="l00160"></a>00160                         Ubc = -std::numeric_limits&lt;double&gt;::infinity(); 
    184 <a name="l00161"></a>00161  
    185 <a name="l00162"></a>00162                         <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length(); i++ ) { 
    186 <a name="l00163"></a>00163                                 <span class="comment">// check Coms</span> 
    187 <a name="l00164"></a>00164                                 Coms ( i )-&gt;qbounds ( lbc, ubc ); 
    188 <a name="l00165"></a>00165                                 <span class="keywordflow">for</span> ( j = 0; j &lt; dimC; j++ ) { 
    189 <a name="l00166"></a>00166                                         <span class="keywordflow">if</span> ( lbc ( j ) &lt; Lbc ( j ) ) { 
    190 <a name="l00167"></a>00167                                                 Lbc ( j ) = lbc ( j ); 
    191 <a name="l00168"></a>00168                                         } 
    192 <a name="l00169"></a>00169                                         <span class="keywordflow">if</span> ( ubc ( j ) &gt; Ubc ( j ) ) { 
    193 <a name="l00170"></a>00170                                                 Ubc ( j ) = ubc ( j ); 
    194 <a name="l00171"></a>00171                                         } 
    195 <a name="l00172"></a>00172                                 } 
    196 <a name="l00173"></a>00173                         } 
    197 <a name="l00174"></a>00174                         lb = concat ( lbp, Lbc ); 
    198 <a name="l00175"></a>00175                         ub = concat ( ubp, Ubc ); 
    199 <a name="l00176"></a>00176                 } 
    200 <a name="l00177"></a>00177  
    201 <a name="l00178"></a>00178                 vec sample()<span class="keyword"> const </span>{ 
    202 <a name="l00179"></a>00179                         <a class="code" href="bdmerror_8h.html#a7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> ( <span class="stringliteral">&quot;Not implemented&quot;</span> ); 
    203 <a name="l00180"></a>00180                         <span class="keywordflow">return</span> vec(); 
    204 <a name="l00181"></a>00181                 } 
    205 <a name="l00182"></a>00182  
    206 <a name="l00183"></a>00183                 <span class="keywordtype">double</span> evallog ( <span class="keyword">const</span> vec &amp;val )<span class="keyword"> const </span>{ 
    207 <a name="l00184"></a>00184                         <a class="code" href="bdmerror_8h.html#a7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> ( <span class="stringliteral">&quot;not implemented&quot;</span> ); 
    208 <a name="l00185"></a>00185                         <span class="keywordflow">return</span> 0.0; 
     82<a name="l00038"></a><a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff">00038</a>         <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr&lt;mpdf&gt;</a> <a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a>; 
     83<a name="l00040"></a><a class="code" href="classbdm_1_1PF.html#a77ed889e1b993df253e93059933d227d">00040</a>         <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr&lt;mpdf&gt;</a> <a class="code" href="classbdm_1_1PF.html#a77ed889e1b993df253e93059933d227d" title="Observation model.">obs</a>; 
     84<a name="l00042"></a><a class="code" href="classbdm_1_1PF.html#a08cffd22d6e9501f283972245aeff8cd">00042</a>         vec <a class="code" href="classbdm_1_1PF.html#a08cffd22d6e9501f283972245aeff8cd" title="internal structure storing loglikelihood of predictions">lls</a>; 
     85<a name="l00043"></a>00043          
     86<a name="l00045"></a><a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52">00045</a>         RESAMPLING_METHOD <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>; 
     87<a name="l00048"></a><a class="code" href="classbdm_1_1PF.html#ab16816e20f97f9bec993d1f25fc3d711">00048</a>         <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1PF.html#ab16816e20f97f9bec993d1f25fc3d711">res_threshold</a>; 
     88<a name="l00049"></a>00049          
     89<a name="l00052"></a>00052  
     90<a name="l00054"></a><a class="code" href="classbdm_1_1PF.html#a98ef9ff80c394fafd28680b7a3f831b1">00054</a>         <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1PF.html#a98ef9ff80c394fafd28680b7a3f831b1" title="Log all samples.">opt_L_smp</a>; 
     91<a name="l00056"></a><a class="code" href="classbdm_1_1PF.html#a5a49463a88ee80771a464861df845ff6">00056</a>         <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1PF.html#a5a49463a88ee80771a464861df845ff6" title="Log all samples.">opt_L_wei</a>; 
     92<a name="l00058"></a>00058  
     93<a name="l00059"></a>00059 <span class="keyword">public</span>: 
     94<a name="l00062"></a>00062         <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#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>(), <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( <a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>() ), <a class="code" href="classbdm_1_1PF.html#a914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( <a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1PF.html#a914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a>() ), <a class="code" href="classbdm_1_1PF.html#a98ef9ff80c394fafd28680b7a3f831b1" title="Log all samples.">opt_L_smp</a> ( false ), <a class="code" href="classbdm_1_1PF.html#a5a49463a88ee80771a464861df845ff6" title="Log all samples.">opt_L_wei</a> ( false ) { 
     95<a name="l00063"></a>00063                 <a class="code" href="classbdm_1_1BM.html#a109c1a626a69031658e3a44e9e500cca" title="IDs of storages in loggers 4:[1=mean,2=lb,3=ub,4=ll].">LIDs</a>.set_size ( 5 ); 
     96<a name="l00064"></a>00064         }; 
     97<a name="l00065"></a>00065          
     98<a name="l00066"></a>00066         <span class="keywordtype">void</span> set_parameters (<span class="keywordtype">int</span> n0, <span class="keywordtype">double</span> res_th0=0.5, RESAMPLING_METHOD rm = SYSTEMATIC ) { 
     99<a name="l00067"></a>00067                 <a class="code" href="classbdm_1_1PF.html#aeeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a> = n0; 
     100<a name="l00068"></a>00068                 <a class="code" href="classbdm_1_1PF.html#ab16816e20f97f9bec993d1f25fc3d711">res_threshold</a> = res_th0; 
     101<a name="l00069"></a>00069                 <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a> = rm; 
     102<a name="l00070"></a>00070         }; 
     103<a name="l00071"></a>00071         <span class="keywordtype">void</span> set_model ( shared_ptr&lt;mpdf&gt; par0, shared_ptr&lt;mpdf&gt; obs0) { 
     104<a name="l00072"></a>00072                 <a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a> = par0; 
     105<a name="l00073"></a>00073                 <a class="code" href="classbdm_1_1PF.html#a77ed889e1b993df253e93059933d227d" title="Observation model.">obs</a> = obs0; 
     106<a name="l00074"></a>00074                 <span class="comment">// set values for posterior</span> 
     107<a name="l00075"></a>00075                 <a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.set_rv(<a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a>-&gt;_rv()); 
     108<a name="l00076"></a>00076         }; 
     109<a name="l00077"></a>00077         <span class="keywordtype">void</span> set_statistics ( <span class="keyword">const</span> vec w0, <span class="keyword">const</span> epdf &amp;epdf0 ) { 
     110<a name="l00078"></a>00078                 <a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.set_statistics ( w0, epdf0 ); 
     111<a name="l00079"></a>00079         }; 
     112<a name="l00080"></a>00080         <span class="keywordtype">void</span> set_statistics ( <span class="keyword">const</span> eEmp &amp;epdf0 ) { 
     113<a name="l00081"></a>00081                 <a class="code" href="bdmerror_8h.html#a89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a>(epdf0._rv().equal(<a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a>-&gt;_rv()),<span class="stringliteral">&quot;Incompatibel input&quot;</span>); 
     114<a name="l00082"></a>00082                 <a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>=epdf0; 
     115<a name="l00083"></a>00083         }; 
     116<a name="l00089"></a><a class="code" href="classbdm_1_1PF.html#abf104b869b5df8dd4a14bbe430d40488">00089</a>         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#abf104b869b5df8dd4a14bbe430d40488">set_options</a> ( <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;opt ) { 
     117<a name="l00090"></a>00090                 <a class="code" href="classbdm_1_1PF.html#abf104b869b5df8dd4a14bbe430d40488">BM::set_options</a> ( opt ); 
     118<a name="l00091"></a>00091                 <a class="code" href="classbdm_1_1PF.html#a5a49463a88ee80771a464861df845ff6" title="Log all samples.">opt_L_wei</a> = ( opt.find ( <span class="stringliteral">&quot;logweights&quot;</span> ) != string::npos ); 
     119<a name="l00092"></a>00092                 <a class="code" href="classbdm_1_1PF.html#a98ef9ff80c394fafd28680b7a3f831b1" title="Log all samples.">opt_L_smp</a> = ( opt.find ( <span class="stringliteral">&quot;logsamples&quot;</span> ) != string::npos ); 
     120<a name="l00093"></a>00093         } 
     121<a name="l00095"></a>00095         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#a63282dc111d1afb32c194c955d966a15" title="bayes I - generate samples and add their weights to lls">bayes_gensmp</a>(); 
     122<a name="l00097"></a>00097         <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#aec76b4d647ac7dc683d8c9a7b7611026" title="bayes II - compute weights of the">bayes_weights</a>(); 
     123<a name="l00099"></a><a class="code" href="classbdm_1_1PF.html#ac3443faad7159e742ef3cb0674a92634">00099</a>         <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1PF.html#ac3443faad7159e742ef3cb0674a92634" title="important part of particle filtering - decide if it is time to perform resampling...">do_resampling</a>(){    
     124<a name="l00100"></a>00100                 <span class="keywordtype">double</span> eff = 1.0 / ( <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> * <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ); 
     125<a name="l00101"></a>00101                 <span class="keywordflow">return</span> eff &lt; ( <a class="code" href="classbdm_1_1PF.html#ab16816e20f97f9bec993d1f25fc3d711">res_threshold</a>*<a class="code" href="classbdm_1_1PF.html#aeeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a> ); 
     126<a name="l00102"></a>00102         } 
     127<a name="l00103"></a>00103         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#a638946eea22d4964bf9350286bb4efd8" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &amp;dt ); 
     128<a name="l00105"></a><a class="code" href="classbdm_1_1PF.html#a37cb95af19c7bd13eb3ec61f25923463">00105</a>         vec&amp; <a class="code" href="classbdm_1_1PF.html#a37cb95af19c7bd13eb3ec61f25923463" title="access function">__w</a>() { <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>; } 
     129<a name="l00107"></a><a class="code" href="classbdm_1_1PF.html#a82d221d771cbc3c15a37cb358d759734">00107</a>         vec&amp; <a class="code" href="classbdm_1_1PF.html#a82d221d771cbc3c15a37cb358d759734" title="access function">_lls</a>() { <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1PF.html#a08cffd22d6e9501f283972245aeff8cd" title="internal structure storing loglikelihood of predictions">lls</a>; } 
     130<a name="l00108"></a>00108         RESAMPLING_METHOD _resmethod()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>; } 
     131<a name="l00110"></a><a class="code" href="classbdm_1_1PF.html#aee9553da1a05671f94f30e0e94ff42cd">00110</a>         <span class="keyword">const</span> <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a>&amp; <a class="code" href="classbdm_1_1PF.html#aee9553da1a05671f94f30e0e94ff42cd" title="access function">posterior</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>;} 
     132<a name="l00111"></a>00111          
     133<a name="l00124"></a><a class="code" href="classbdm_1_1PF.html#a40d74160df73d152a9bcf044eac25663">00124</a>         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#a40d74160df73d152a9bcf044eac25663">from_setting</a>(<span class="keyword">const</span> Setting &amp;<span class="keyword">set</span>){ 
     134<a name="l00125"></a>00125                 <a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a> = UI::build&lt;mpdf&gt;(<span class="keyword">set</span>,<span class="stringliteral">&quot;parameter_pdf&quot;</span>,UI::compulsory); 
     135<a name="l00126"></a>00126                 <a class="code" href="classbdm_1_1PF.html#a77ed889e1b993df253e93059933d227d" title="Observation model.">obs</a> = UI::build&lt;mpdf&gt;(<span class="keyword">set</span>,<span class="stringliteral">&quot;observation_pdf&quot;</span>,UI::compulsory); 
     136<a name="l00127"></a>00127                  
     137<a name="l00128"></a>00128                 <a class="code" href="classbdm_1_1PF.html#a8ac867d4b88c2c6c73ae29d47f37d0bb" title="load prior information from set and set internal structures accordingly">prior_from_set</a>(<span class="keyword">set</span>); 
     138<a name="l00129"></a>00129                 <a class="code" href="classbdm_1_1PF.html#a30f6a71f3e56ce25e4e0ecafa0ffbd8d" title="auxiliary function reading parameter &amp;#39;resmethod&amp;#39; from configuration file">resmethod_from_set</a>(<span class="keyword">set</span>); 
     139<a name="l00130"></a>00130                 <span class="comment">// set resampling method</span> 
     140<a name="l00131"></a>00131                 <span class="comment">//set drv</span> 
     141<a name="l00132"></a>00132                 <span class="comment">//find potential input - what remains in rvc when we subtract rv</span> 
     142<a name="l00133"></a>00133                 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> u = <a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a>-&gt;_rvc().remove_time().subt( <a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a>-&gt;_rv() );  
     143<a name="l00134"></a>00134                 <span class="comment">//find potential input - what remains in rvc when we subtract x_t</span> 
     144<a name="l00135"></a>00135                 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> obs_u = obs-&gt;_rvc().remove_time().subt( <a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a>-&gt;_rv() );  
     145<a name="l00136"></a>00136                  
     146<a name="l00137"></a>00137                 u.<a class="code" href="classbdm_1_1RV.html#a87841b5ee43997b79789c0c22047e224" title="Add (concat) another variable to the current one,.">add</a>(obs_u); <span class="comment">// join both u, and check if they do not overlap</span> 
     147<a name="l00138"></a>00138                  
     148<a name="l00139"></a>00139                 set_drv(concat(obs-&gt;_rv(),u) ); 
     149<a name="l00140"></a>00140         } 
     150<a name="l00142"></a><a class="code" href="classbdm_1_1PF.html#a30f6a71f3e56ce25e4e0ecafa0ffbd8d">00142</a>         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#a30f6a71f3e56ce25e4e0ecafa0ffbd8d" title="auxiliary function reading parameter &amp;#39;resmethod&amp;#39; from configuration file">resmethod_from_set</a>(<span class="keyword">const</span> Setting &amp;<span class="keyword">set</span>){ 
     151<a name="l00143"></a>00143                 <span class="keywordtype">string</span> resmeth; 
     152<a name="l00144"></a>00144                 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a>(resmeth,<span class="keyword">set</span>,<span class="stringliteral">&quot;resmethod&quot;</span>,UI::optional)){ 
     153<a name="l00145"></a>00145                         <span class="keywordflow">if</span> (resmeth==<span class="stringliteral">&quot;systematic&quot;</span>) { 
     154<a name="l00146"></a>00146                                 <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>= SYSTEMATIC; 
     155<a name="l00147"></a>00147                         } <span class="keywordflow">else</span>  { 
     156<a name="l00148"></a>00148                                 <span class="keywordflow">if</span> (resmeth==<span class="stringliteral">&quot;multinomial&quot;</span>){ 
     157<a name="l00149"></a>00149                                         <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>=MULTINOMIAL; 
     158<a name="l00150"></a>00150                                 } <span class="keywordflow">else</span> { 
     159<a name="l00151"></a>00151                                         <span class="keywordflow">if</span> (resmeth==<span class="stringliteral">&quot;stratified&quot;</span>){ 
     160<a name="l00152"></a>00152                                                 <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>= STRATIFIED; 
     161<a name="l00153"></a>00153                                         } <span class="keywordflow">else</span> { 
     162<a name="l00154"></a>00154                                                 <a class="code" href="bdmerror_8h.html#a7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a>(<span class="stringliteral">&quot;Unknown resampling method&quot;</span>); 
     163<a name="l00155"></a>00155                                         } 
     164<a name="l00156"></a>00156                                 } 
     165<a name="l00157"></a>00157                         } 
     166<a name="l00158"></a>00158                 } <span class="keywordflow">else</span> { 
     167<a name="l00159"></a>00159                         <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>=SYSTEMATIC; 
     168<a name="l00160"></a>00160                 }; 
     169<a name="l00161"></a>00161                 <span class="keywordflow">if</span>(!<a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a>(<a class="code" href="classbdm_1_1PF.html#ab16816e20f97f9bec993d1f25fc3d711">res_threshold</a>, <span class="keyword">set</span>, <span class="stringliteral">&quot;res_threshold&quot;</span>, UI::optional)){ 
     170<a name="l00162"></a>00162                         <a class="code" href="classbdm_1_1PF.html#ab16816e20f97f9bec993d1f25fc3d711">res_threshold</a>=0.5; 
     171<a name="l00163"></a>00163                 } 
     172<a name="l00164"></a>00164         } 
     173<a name="l00166"></a><a class="code" href="classbdm_1_1PF.html#a8ac867d4b88c2c6c73ae29d47f37d0bb">00166</a>         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#a8ac867d4b88c2c6c73ae29d47f37d0bb" title="load prior information from set and set internal structures accordingly">prior_from_set</a>(<span class="keyword">const</span> Setting &amp; <span class="keyword">set</span>){ 
     174<a name="l00167"></a>00167                 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr&lt;epdf&gt;</a> pri = UI::build&lt;epdf&gt;(<span class="keyword">set</span>,<span class="stringliteral">&quot;prior&quot;</span>,UI::compulsory); 
     175<a name="l00168"></a>00168                  
     176<a name="l00169"></a>00169                 <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> *test_emp=<span class="keyword">dynamic_cast&lt;</span><a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a>*<span class="keyword">&gt;</span>(&amp;(*pri)); 
     177<a name="l00170"></a>00170                 <span class="keywordflow">if</span> (test_emp) { <span class="comment">// given pdf is sampled</span> 
     178<a name="l00171"></a>00171                         <a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>=*test_emp; 
     179<a name="l00172"></a>00172                 } <span class="keywordflow">else</span> { 
     180<a name="l00173"></a>00173                         <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1PF.html#aeeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>; 
     181<a name="l00174"></a>00174                         <span class="keywordflow">if</span> (!<a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a>(n,<span class="keyword">set</span>,<span class="stringliteral">&quot;n&quot;</span>,UI::optional)){n=10;} 
     182<a name="l00175"></a>00175                         <span class="comment">// sample from prior</span> 
     183<a name="l00176"></a>00176                         set_statistics(ones(n)/n, *pri); 
     184<a name="l00177"></a>00177                 } 
     185<a name="l00178"></a>00178                 <span class="comment">//validate();</span> 
     186<a name="l00179"></a>00179         } 
     187<a name="l00180"></a>00180          
     188<a name="l00181"></a><a class="code" href="classbdm_1_1PF.html#a7ebbb12b5b01e8ac6985af0e04e0f0c2">00181</a>         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#a7ebbb12b5b01e8ac6985af0e04e0f0c2" title="This method TODO.">validate</a>(){ 
     189<a name="l00182"></a>00182                 <a class="code" href="classbdm_1_1PF.html#aeeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>=<a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a>.length(); 
     190<a name="l00183"></a>00183                 <a class="code" href="classbdm_1_1PF.html#a08cffd22d6e9501f283972245aeff8cd" title="internal structure storing loglikelihood of predictions">lls</a>=zeros(<a class="code" href="classbdm_1_1PF.html#aeeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>); 
     191<a name="l00184"></a>00184                 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a>-&gt;_rv()._dsize()&gt;0) { 
     192<a name="l00185"></a>00185                         <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_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a>-&gt;_rv()._dsize()==<a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1epdf.html#a7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>(),<span class="stringliteral">&quot;Mismatch of RV and dimension of posterior&quot;</span> ); 
    209193<a name="l00186"></a>00186                 } 
    210 <a name="l00187"></a>00187         }; 
    211 <a name="l00188"></a>00188  
    212 <a name="l00190"></a>00190         mpfepdf jest; 
    213 <a name="l00191"></a>00191  
    214 <a name="l00193"></a>00193         <span class="keywordtype">bool</span> opt_L_mea; 
     194<a name="l00187"></a>00187         } 
     195<a name="l00189"></a><a class="code" href="classbdm_1_1PF.html#a10fd6402c67ad3ee3a1a9a23fe91d7d7">00189</a>         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#a10fd6402c67ad3ee3a1a9a23fe91d7d7" title="resample posterior density (from outside - see MPF)">resample</a>(ivec &amp;ind){ 
     196<a name="l00190"></a>00190                 <a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1eEmp.html#af59ed50888a31057ac2038d80f607d3d">resample</a>(ind,<a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>); 
     197<a name="l00191"></a>00191         } 
     198<a name="l00192"></a>00192 }; 
     199<a name="l00193"></a>00193 <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>(PF); 
    215200<a name="l00194"></a>00194  
    216 <a name="l00195"></a>00195 <span class="keyword">public</span>: 
    217 <a name="l00197"></a><a class="code" href="classbdm_1_1MPF.html#a0068e7ca53d90fa5911eb31a0d657f26">00197</a>         <a class="code" href="classbdm_1_1MPF.html#a0068e7ca53d90fa5911eb31a0d657f26" 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#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a> ) {}; 
    218 <a name="l00198"></a>00198         <span class="keywordtype">void</span> set_parameters ( <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling , where  is random variable, rv, and...">mpdf</a> *par0, <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling , where  is random variable, rv, and...">mpdf</a> *obs0, <span class="keywordtype">int</span> n0, RESAMPLING_METHOD rm = SYSTEMATIC ) { 
    219 <a name="l00199"></a>00199                 PF::set_parameters ( par0, obs0, n0, rm ); 
    220 <a name="l00200"></a>00200                 jest.set_parameters ( n0 );<span class="comment">//duplication of rm</span> 
    221 <a name="l00201"></a>00201                 BMs.set_length ( n0 ); 
    222 <a name="l00202"></a>00202         } 
    223 <a name="l00203"></a>00203         <span class="keywordtype">void</span> set_statistics ( <span class="keyword">const</span> epdf &amp;epdf0, <span class="keyword">const</span> BM_T* BMcond0 ) { 
    224 <a name="l00204"></a>00204  
    225 <a name="l00205"></a>00205                 PF::set_statistics ( ones ( <a class="code" href="classbdm_1_1PF.html#aeeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a> ) / <a class="code" href="classbdm_1_1PF.html#aeeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>, epdf0 ); 
    226 <a name="l00206"></a>00206                 <span class="comment">// copy</span> 
    227 <a name="l00207"></a>00207                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="classbdm_1_1PF.html#aeeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>; i++ ) { 
    228 <a name="l00208"></a>00208                         BMs ( i ) = <span class="keyword">new</span> BM_T ( *BMcond0 ); 
    229 <a name="l00209"></a>00209                         BMs ( i )-&gt;condition ( <a class="code" href="classbdm_1_1PF.html#a914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ) ); 
    230 <a name="l00210"></a>00210                 } 
    231 <a name="l00211"></a>00211  
    232 <a name="l00212"></a>00212                 jest.read_statistics ( BMs ); 
    233 <a name="l00213"></a>00213                 <span class="comment">//options</span> 
    234 <a name="l00214"></a>00214         }; 
    235 <a name="l00215"></a>00215  
    236 <a name="l00216"></a>00216         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#a286d040770d08bd7ff416cea617b1b14" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &amp;dt ); 
    237 <a name="l00217"></a>00217         <span class="keyword">const</span> epdf&amp; posterior()<span class="keyword"> const </span>{ 
    238 <a name="l00218"></a>00218                 <span class="keywordflow">return</span> jest; 
    239 <a name="l00219"></a>00219         } 
    240 <a name="l00221"></a>00221         <span class="comment">/*      void set_est ( const epdf&amp; epdf0 ) {</span> 
    241 <a name="l00222"></a>00222 <span class="comment">                        PF::set_est ( epdf0 );  // sample params in condition</span> 
    242 <a name="l00223"></a>00223 <span class="comment">                        // copy conditions to BMs</span> 
    243 <a name="l00224"></a>00224 <span class="comment"></span> 
    244 <a name="l00225"></a>00225 <span class="comment">                        for ( int i=0;i&lt;n;i++ ) {BMs(i)-&gt;condition ( _samples ( i ) );}</span> 
    245 <a name="l00226"></a>00226 <span class="comment">                }*/</span> 
    246 <a name="l00227"></a><a class="code" href="classbdm_1_1MPF.html#a2e95498dec734088ab9f4878ff404144">00227</a>         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#a2e95498dec734088ab9f4878ff404144" 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 ) { 
    247 <a name="l00228"></a>00228                 <a class="code" href="classbdm_1_1MPF.html#a2e95498dec734088ab9f4878ff404144" title="Set postrior of rvc to samples from epdf0. Statistics of BMs are not re-computed!...">PF::set_options</a> ( opt ); 
    248 <a name="l00229"></a>00229                 opt_L_mea = ( opt.find ( <span class="stringliteral">&quot;logmeans&quot;</span> ) != string::npos ); 
    249 <a name="l00230"></a>00230         } 
    250 <a name="l00231"></a>00231  
    251 <a name="l00233"></a><a class="code" href="classbdm_1_1MPF.html#ab6e7b094cbe32944b8ccde5df73cd839">00233</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>* <a class="code" href="classbdm_1_1MPF.html#ab6e7b094cbe32944b8ccde5df73cd839" title="Access function.">_BM</a> ( <span class="keywordtype">int</span> i ) { 
    252 <a name="l00234"></a>00234                 <span class="keywordflow">return</span> BMs ( i ); 
    253 <a name="l00235"></a>00235         } 
    254 <a name="l00236"></a>00236 }; 
    255 <a name="l00237"></a>00237  
    256 <a name="l00238"></a>00238 <span class="keyword">template</span>&lt;<span class="keyword">class</span> BM_T&gt; 
    257 <a name="l00239"></a><a class="code" href="classbdm_1_1MPF.html#a286d040770d08bd7ff416cea617b1b14">00239</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#a286d040770d08bd7ff416cea617b1b14" title="Incremental Bayes rule.">MPF&lt;BM_T&gt;::bayes</a> ( <span class="keyword">const</span> vec &amp;dt ) { 
    258 <a name="l00240"></a>00240         <span class="keywordtype">int</span> i; 
    259 <a name="l00241"></a>00241         vec lls ( n ); 
    260 <a name="l00242"></a>00242         vec llsP ( n ); 
    261 <a name="l00243"></a>00243         ivec ind; 
    262 <a name="l00244"></a>00244         <span class="keywordtype">double</span> mlls = -std::numeric_limits&lt;double&gt;::infinity(); 
    263 <a name="l00245"></a>00245  
    264 <a name="l00246"></a>00246 <span class="preprocessor">#pragma omp parallel for</span> 
    265 <a name="l00247"></a>00247 <span class="preprocessor"></span>        <span class="keywordflow">for</span> ( i = 0; i &lt; n; i++ ) { 
    266 <a name="l00248"></a>00248                 <span class="comment">//generate new samples from paramater evolution model;</span> 
    267 <a name="l00249"></a>00249                 vec old_smp=<a class="code" href="classbdm_1_1PF.html#a914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ); 
    268 <a name="l00250"></a>00250                 <a class="code" href="classbdm_1_1PF.html#a914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ) = <a class="code" href="classbdm_1_1PF.html#a521e9621d3b5e1274275f323691afdaf" title="Parameter evolution model.">par</a>-&gt;<a class="code" href="classbdm_1_1mpdf.html#af0c1db6fcbb3aae2dd6123884457a367" title="Returns a sample from the density conditioned on cond, .">samplecond</a> ( old_smp ); 
    269 <a name="l00251"></a>00251                 llsP ( i ) = <a class="code" href="classbdm_1_1PF.html#a521e9621d3b5e1274275f323691afdaf" title="Parameter evolution model.">par</a>-&gt;<a class="code" href="classbdm_1_1mpdf.html#a6336a8a72462e2a56a3989a220f18b1b" title="Shortcut for conditioning and evaluation of the internal epdf. In some cases, this...">evallogcond</a> ( <a class="code" href="classbdm_1_1PF.html#a914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ), old_smp ); 
    270 <a name="l00252"></a>00252                 BMs ( i )-&gt;condition ( <a class="code" href="classbdm_1_1PF.html#a914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a> ( i ) ); 
    271 <a name="l00253"></a>00253                 BMs ( i )-&gt;bayes ( dt ); 
    272 <a name="l00254"></a>00254                 lls ( i ) = BMs ( i )-&gt;_ll(); <span class="comment">// lls above is also in proposal her must be lls(i) =, not +=!!</span> 
    273 <a name="l00255"></a>00255                 <span class="keywordflow">if</span> ( lls ( i ) &gt; mlls ) mlls = lls ( i ); <span class="comment">//find maximum likelihood (for numerical stability)</span> 
    274 <a name="l00256"></a>00256         } 
    275 <a name="l00257"></a>00257  
    276 <a name="l00258"></a>00258         <span class="keywordtype">double</span> sum_w = 0.0; 
    277 <a name="l00259"></a>00259         <span class="comment">// compute weights</span> 
    278 <a name="l00260"></a>00260 <span class="preprocessor">#pragma omp parallel for</span> 
    279 <a name="l00261"></a>00261 <span class="preprocessor"></span>        <span class="keywordflow">for</span> ( i = 0; i &lt; n; i++ ) { 
    280 <a name="l00262"></a>00262                 <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ) *= exp ( lls ( i ) - mlls ); <span class="comment">// multiply w by likelihood</span> 
    281 <a name="l00263"></a>00263                 sum_w += <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ( i ); 
    282 <a name="l00264"></a>00264         } 
    283 <a name="l00265"></a>00265  
    284 <a name="l00266"></a>00266         <span class="keywordflow">if</span> ( sum_w  &gt; 0.0 ) { 
    285 <a name="l00267"></a>00267                 <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> /= sum_w; <span class="comment">//?</span> 
    286 <a name="l00268"></a>00268         } <span class="keywordflow">else</span> { 
    287 <a name="l00269"></a>00269                 cout &lt;&lt; <span class="stringliteral">&quot;sum(w)==0&quot;</span> &lt;&lt; endl; 
    288 <a name="l00270"></a>00270         } 
    289 <a name="l00271"></a>00271  
    290 <a name="l00272"></a>00272  
    291 <a name="l00273"></a>00273         <span class="keywordtype">double</span> eff = 1.0 / ( <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> * <a class="code" href="classbdm_1_1PF.html#af5149d5522d1095d39240c4c607f61a3" title="pointer into eEmp ">_w</a> ); 
    292 <a name="l00274"></a>00274         <span class="keywordflow">if</span> ( eff &lt; ( 0.3*n ) ) { 
    293 <a name="l00275"></a>00275                 ind = <a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>.<a class="code" href="classbdm_1_1eEmp.html#af06ce255de5dbb2313f52ee51f82ba3d" title="Function performs resampling, i.e. removal of low-weight samples and duplication...">resample</a> ( <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a> ); 
    294 <a name="l00276"></a>00276                 <span class="comment">// Resample Bms!</span> 
    295 <a name="l00277"></a>00277  
    296 <a name="l00278"></a>00278 <span class="preprocessor">#pragma omp parallel for</span> 
    297 <a name="l00279"></a>00279 <span class="preprocessor"></span>                <span class="keywordflow">for</span> ( i = 0; i &lt; n; i++ ) { 
    298 <a name="l00280"></a>00280                         <span class="keywordflow">if</span> ( ind ( i ) != i ) {<span class="comment">//replace the current Bm by a new one</span> 
    299 <a name="l00281"></a>00281                                 <span class="comment">//fixme this would require new assignment operator</span> 
    300 <a name="l00282"></a>00282                                 <span class="comment">// *Bms[i] = *Bms[ind ( i ) ];</span> 
    301 <a name="l00283"></a>00283  
    302 <a name="l00284"></a>00284                                 <span class="comment">// poor-man&apos;s solution: replicate constructor here</span> 
    303 <a name="l00285"></a>00285                                 <span class="comment">// copied from MPF::MPF</span> 
    304 <a name="l00286"></a>00286                                 <span class="keyword">delete</span> BMs ( i ); 
    305 <a name="l00287"></a>00287                                 BMs ( i ) = <span class="keyword">new</span> BM_T ( *BMs ( ind ( i ) ) ); <span class="comment">//copy constructor</span> 
    306 <a name="l00288"></a>00288                                 <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(); 
    307 <a name="l00289"></a>00289                                 jest.set_elements ( i, 1.0 / n, &amp;pom ); 
    308 <a name="l00290"></a>00290                         } 
    309 <a name="l00291"></a>00291                 }; 
    310 <a name="l00292"></a>00292                 cout &lt;&lt; <span class="charliteral">&apos;.&apos;</span>; 
    311 <a name="l00293"></a>00293         } 
    312 <a name="l00294"></a>00294 } 
    313 <a name="l00295"></a>00295  
    314 <a name="l00296"></a>00296 } 
    315 <a name="l00297"></a>00297 <span class="preprocessor">#endif // KF_H</span> 
    316 <a name="l00298"></a>00298 <span class="preprocessor"></span> 
    317 <a name="l00299"></a>00299  
     201<a name="l00202"></a><a class="code" href="classbdm_1_1MPF.html">00202</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_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a>  { 
     202<a name="l00203"></a>00203     <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr&lt;PF&gt;</a> pf; 
     203<a name="l00204"></a>00204         Array&lt;BM*&gt; BMs; 
     204<a name="l00205"></a>00205  
     205<a name="l00207"></a>00207  
     206<a name="l00208"></a>00208         <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>  { 
     207<a name="l00209"></a>00209                 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr&lt;PF&gt;</a> &amp;pf; 
     208<a name="l00210"></a>00210                 Array&lt;BM*&gt; &amp;BMs; 
     209<a name="l00211"></a>00211         <span class="keyword">public</span>: 
     210<a name="l00212"></a>00212                 mpfepdf (<a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr&lt;PF&gt;</a> &amp;pf0, Array&lt;BM*&gt; &amp;BMs0): <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>(), pf(pf0), BMs(BMs0) { }; 
     211<a name="l00214"></a>00214                 <span class="keywordtype">void</span> read_parameters(){ 
     212<a name="l00215"></a>00215                         rv = concat(pf-&gt;posterior()._rv(), BMs(0)-&gt;posterior()._rv()); 
     213<a name="l00216"></a>00216                         dim = pf-&gt;posterior().dimension() + BMs(0)-&gt;posterior().dimension(); 
     214<a name="l00217"></a>00217                         <a class="code" href="bdmerror_8h.html#a89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a>(dim == rv.<a class="code" href="classbdm_1_1RV.html#ade30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>(), <span class="stringliteral">&quot;Wrong name &quot;</span>); 
     215<a name="l00218"></a>00218                 } 
     216<a name="l00219"></a>00219                 vec mean()<span class="keyword"> const </span>{ 
     217<a name="l00220"></a>00220                         <span class="keyword">const</span> vec &amp;w = pf-&gt;posterior()._w(); 
     218<a name="l00221"></a>00221                         vec pom = zeros ( BMs(0)-&gt;posterior ().dimension() ); 
     219<a name="l00222"></a>00222                         <span class="comment">//compute mean of BMs</span> 
     220<a name="l00223"></a>00223                         <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; w.length(); i++ ) { 
     221<a name="l00224"></a>00224                                 pom += BMs ( i )-&gt;posterior().mean() * w ( i ); 
     222<a name="l00225"></a>00225                         } 
     223<a name="l00226"></a>00226                         <span class="keywordflow">return</span> concat ( pf-&gt;posterior().mean(), pom ); 
     224<a name="l00227"></a>00227                 } 
     225<a name="l00228"></a>00228                 vec variance()<span class="keyword"> const </span>{ 
     226<a name="l00229"></a>00229                         <span class="keyword">const</span> vec &amp;w = pf-&gt;posterior()._w(); 
     227<a name="l00230"></a>00230                          
     228<a name="l00231"></a>00231                         vec pom = zeros ( BMs(0)-&gt;posterior ().dimension() ); 
     229<a name="l00232"></a>00232                         vec pom2 = zeros ( BMs(0)-&gt;posterior ().dimension() ); 
     230<a name="l00233"></a>00233                         vec mea; 
     231<a name="l00234"></a>00234                          
     232<a name="l00235"></a>00235                         <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; w.length(); i++ ) { 
     233<a name="l00236"></a>00236                                 <span class="comment">// save current mean </span> 
     234<a name="l00237"></a>00237                                 mea = BMs ( i )-&gt;posterior().mean(); 
     235<a name="l00238"></a>00238                                 pom += mea * w ( i ); 
     236<a name="l00239"></a>00239                                 <span class="comment">//compute variance</span> 
     237<a name="l00240"></a>00240                                 pom2 += ( BMs ( i )-&gt;posterior().variance() + pow ( mea, 2 ) ) * w ( i ); 
     238<a name="l00241"></a>00241                         } 
     239<a name="l00242"></a>00242                         <span class="keywordflow">return</span> concat ( pf-&gt;posterior().variance(), pom2 - pow ( pom, 2 ) ); 
     240<a name="l00243"></a>00243                 } 
     241<a name="l00244"></a>00244                  
     242<a name="l00245"></a>00245                 <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>{ 
     243<a name="l00246"></a>00246                         <span class="comment">//bounds on particles</span> 
     244<a name="l00247"></a>00247                         vec lbp; 
     245<a name="l00248"></a>00248                         vec ubp; 
     246<a name="l00249"></a>00249                         pf-&gt;posterior().qbounds ( lbp, ubp ); 
     247<a name="l00250"></a>00250  
     248<a name="l00251"></a>00251                         <span class="comment">//bounds on Components</span> 
     249<a name="l00252"></a>00252                         <span class="keywordtype">int</span> dimC = BMs ( 0 )-&gt;posterior().dimension(); 
     250<a name="l00253"></a>00253                         <span class="keywordtype">int</span> j; 
     251<a name="l00254"></a>00254                         <span class="comment">// temporary</span> 
     252<a name="l00255"></a>00255                         vec lbc ( dimC ); 
     253<a name="l00256"></a>00256                         vec ubc ( dimC ); 
     254<a name="l00257"></a>00257                         <span class="comment">// minima and maxima</span> 
     255<a name="l00258"></a>00258                         vec Lbc ( dimC ); 
     256<a name="l00259"></a>00259                         vec Ubc ( dimC ); 
     257<a name="l00260"></a>00260                         Lbc = std::numeric_limits&lt;double&gt;::infinity(); 
     258<a name="l00261"></a>00261                         Ubc = -std::numeric_limits&lt;double&gt;::infinity(); 
     259<a name="l00262"></a>00262  
     260<a name="l00263"></a>00263                         <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; BMs.length(); i++ ) { 
     261<a name="l00264"></a>00264                                 <span class="comment">// check Coms</span> 
     262<a name="l00265"></a>00265                                 BMs ( i )-&gt;posterior().qbounds ( lbc, ubc ); 
     263<a name="l00266"></a>00266                                 <span class="comment">//save either minima or maxima</span> 
     264<a name="l00267"></a>00267                                 <span class="keywordflow">for</span> ( j = 0; j &lt; dimC; j++ ) { 
     265<a name="l00268"></a>00268                                         <span class="keywordflow">if</span> ( lbc ( j ) &lt; Lbc ( j ) ) { 
     266<a name="l00269"></a>00269                                                 Lbc ( j ) = lbc ( j ); 
     267<a name="l00270"></a>00270                                         } 
     268<a name="l00271"></a>00271                                         <span class="keywordflow">if</span> ( ubc ( j ) &gt; Ubc ( j ) ) { 
     269<a name="l00272"></a>00272                                                 Ubc ( j ) = ubc ( j ); 
     270<a name="l00273"></a>00273                                         } 
     271<a name="l00274"></a>00274                                 } 
     272<a name="l00275"></a>00275                         } 
     273<a name="l00276"></a>00276                         lb = concat ( lbp, Lbc ); 
     274<a name="l00277"></a>00277                         ub = concat ( ubp, Ubc ); 
     275<a name="l00278"></a>00278                 } 
     276<a name="l00279"></a>00279  
     277<a name="l00280"></a>00280                 vec sample()<span class="keyword"> const </span>{ 
     278<a name="l00281"></a>00281                         <a class="code" href="bdmerror_8h.html#a7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> ( <span class="stringliteral">&quot;Not implemented&quot;</span> ); 
     279<a name="l00282"></a>00282                         <span class="keywordflow">return</span> vec(); 
     280<a name="l00283"></a>00283                 } 
     281<a name="l00284"></a>00284  
     282<a name="l00285"></a>00285                 <span class="keywordtype">double</span> evallog ( <span class="keyword">const</span> vec &amp;val )<span class="keyword"> const </span>{ 
     283<a name="l00286"></a>00286                         <a class="code" href="bdmerror_8h.html#a7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> ( <span class="stringliteral">&quot;not implemented&quot;</span> ); 
     284<a name="l00287"></a>00287                         <span class="keywordflow">return</span> 0.0; 
     285<a name="l00288"></a>00288                 } 
     286<a name="l00289"></a>00289         }; 
     287<a name="l00290"></a>00290  
     288<a name="l00292"></a>00292         mpfepdf jest; 
     289<a name="l00293"></a>00293  
     290<a name="l00295"></a>00295         <span class="keywordtype">bool</span> opt_L_mea; 
     291<a name="l00296"></a>00296  
     292<a name="l00297"></a>00297 <span class="keyword">public</span>: 
     293<a name="l00299"></a><a class="code" href="classbdm_1_1MPF.html#af45da512c659b40b21a74492a0c06853">00299</a>         <a class="code" href="classbdm_1_1MPF.html#af45da512c659b40b21a74492a0c06853" title="Default constructor.">MPF</a> () :  jest (pf,BMs) {}; 
     294<a name="l00300"></a>00300         <span class="keywordtype">void</span> set_parameters ( <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr&lt;mpdf&gt;</a> par0, <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr&lt;mpdf&gt;</a> obs0, <span class="keywordtype">int</span> n0, RESAMPLING_METHOD rm = SYSTEMATIC ) { 
     295<a name="l00301"></a>00301                 pf-&gt;set_model ( par0, obs0);  
     296<a name="l00302"></a>00302                 pf-&gt;set_parameters(n0, rm ); 
     297<a name="l00303"></a>00303                 BMs.set_length ( n0 ); 
     298<a name="l00304"></a>00304         } 
     299<a name="l00305"></a>00305         <span class="keywordtype">void</span> set_BM ( <span class="keyword">const</span> BM &amp;BMcond0 ) { 
     300<a name="l00306"></a>00306  
     301<a name="l00307"></a>00307                 <span class="keywordtype">int</span> n=pf-&gt;__w().length(); 
     302<a name="l00308"></a>00308                 BMs.set_length(n); 
     303<a name="l00309"></a>00309                 <span class="comment">// copy</span> 
     304<a name="l00310"></a>00310                 <span class="comment">//BMcond0 .condition ( pf-&gt;posterior()._sample ( 0 ) );</span> 
     305<a name="l00311"></a>00311                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i &lt; n; i++ ) { 
     306<a name="l00312"></a>00312                         BMs ( i ) = BMcond0._copy_(); 
     307<a name="l00313"></a>00313                         BMs ( i )-&gt;condition ( pf-&gt;posterior()._sample ( i ) ); 
     308<a name="l00314"></a>00314                 } 
     309<a name="l00315"></a>00315         }; 
     310<a name="l00316"></a>00316  
     311<a name="l00317"></a>00317         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#a0fbe47b20c491f25030ef2875c148892" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &amp;dt ); 
     312<a name="l00318"></a>00318         <span class="keyword">const</span> epdf&amp; posterior()<span class="keyword"> const </span>{ 
     313<a name="l00319"></a>00319                 <span class="keywordflow">return</span> jest; 
     314<a name="l00320"></a>00320         } 
     315<a name="l00323"></a><a class="code" href="classbdm_1_1MPF.html#aada1bdb117bc78035fbb49765fa7ef10">00323</a>         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#aada1bdb117bc78035fbb49765fa7ef10">set_options</a> ( <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;opt ) { 
     316<a name="l00324"></a>00324                 <a class="code" href="classbdm_1_1MPF.html#aada1bdb117bc78035fbb49765fa7ef10">BM::set_options</a>(opt); 
     317<a name="l00325"></a>00325                 opt_L_mea = ( opt.find ( <span class="stringliteral">&quot;logmeans&quot;</span> ) != string::npos ); 
     318<a name="l00326"></a>00326         } 
     319<a name="l00327"></a>00327  
     320<a name="l00329"></a><a class="code" href="classbdm_1_1MPF.html#a71608a6986f57dcfb935e016b97c0637">00329</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>* <a class="code" href="classbdm_1_1MPF.html#a71608a6986f57dcfb935e016b97c0637" title="Access function.">_BM</a> ( <span class="keywordtype">int</span> i ) { 
     321<a name="l00330"></a>00330                 <span class="keywordflow">return</span> BMs ( i ); 
     322<a name="l00331"></a>00331         } 
     323<a name="l00332"></a>00332          
     324<a name="l00344"></a><a class="code" href="classbdm_1_1MPF.html#a9f74326b9ca3c888cb8eff1355ba3670">00344</a>         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#a9f74326b9ca3c888cb8eff1355ba3670">from_setting</a>(<span class="keyword">const</span> Setting &amp;<span class="keyword">set</span>){ 
     325<a name="l00345"></a>00345                 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr&lt;mpdf&gt;</a> par = UI::build&lt;mpdf&gt;(<span class="keyword">set</span>,<span class="stringliteral">&quot;parameter_pdf&quot;</span>,UI::compulsory); 
     326<a name="l00346"></a>00346                 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr&lt;mpdf&gt;</a> obs= <span class="keyword">new</span> <a class="code" href="classbdm_1_1mpdf.html" title="Conditional probability density, e.g. modeling , where  is random variable, rv, and...">mpdf</a>(); <span class="comment">// not used!!</span> 
     327<a name="l00347"></a>00347  
     328<a name="l00348"></a>00348                 pf = <span class="keyword">new</span> <a class="code" href="classbdm_1_1PF.html" title="Trivial particle filter with proposal density equal to parameter evolution model...">PF</a>; 
     329<a name="l00349"></a>00349                 <span class="comment">// rpior must be set before BM</span> 
     330<a name="l00350"></a>00350                 pf-&gt;prior_from_set(<span class="keyword">set</span>); 
     331<a name="l00351"></a>00351                 pf-&gt;resmethod_from_set(<span class="keyword">set</span>); 
     332<a name="l00352"></a>00352                 pf-&gt;set_model(par,obs); 
     333<a name="l00353"></a>00353                  
     334<a name="l00354"></a>00354                 <a class="code" href="classbdm_1_1shared__ptr.html" title="A naive implementation of roughly a subset of the std::tr1::shared_ptr spec.">shared_ptr&lt;BM&gt;</a> BM0 =UI::build&lt;BM&gt;(<span class="keyword">set</span>,<span class="stringliteral">&quot;BM&quot;</span>,UI::compulsory); 
     335<a name="l00355"></a>00355                 set_BM(*BM0); 
     336<a name="l00356"></a>00356                  
     337<a name="l00357"></a>00357                 <span class="keywordtype">string</span> opt; 
     338<a name="l00358"></a>00358                 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1UI.html#acd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a>(opt,<span class="keyword">set</span>,<span class="stringliteral">&quot;options&quot;</span>,UI::optional)){ 
     339<a name="l00359"></a>00359                         <a class="code" href="classbdm_1_1MPF.html#aada1bdb117bc78035fbb49765fa7ef10">set_options</a>(opt); 
     340<a name="l00360"></a>00360                 } 
     341<a name="l00361"></a>00361                 <span class="comment">//set drv</span> 
     342<a name="l00362"></a>00362                 <span class="comment">//find potential input - what remains in rvc when we subtract rv</span> 
     343<a name="l00363"></a>00363                 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> u = par-&gt;_rvc().remove_time().subt( par-&gt;_rv() );             
     344<a name="l00364"></a>00364                 set_drv(concat(BM0-&gt;_drv(),u) ); 
     345<a name="l00365"></a>00365                 <a class="code" href="classbdm_1_1MPF.html#aa91b588de1b9690ca475c945d0f10f08" title="This method TODO.">validate</a>(); 
     346<a name="l00366"></a>00366         } 
     347<a name="l00367"></a><a class="code" href="classbdm_1_1MPF.html#aa91b588de1b9690ca475c945d0f10f08">00367</a>         <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#aa91b588de1b9690ca475c945d0f10f08" title="This method TODO.">validate</a>(){ 
     348<a name="l00368"></a>00368                 <span class="keywordflow">try</span>{ 
     349<a name="l00369"></a>00369                 pf-&gt;validate(); 
     350<a name="l00370"></a>00370                 } <span class="keywordflow">catch</span> (std::exception &amp;e){ 
     351<a name="l00371"></a>00371                         <span class="keywordflow">throw</span> <a class="code" href="classbdm_1_1UIException.html">UIException</a>(<span class="stringliteral">&quot;Error in PF part of MPF:&quot;</span>); 
     352<a name="l00372"></a>00372                 } 
     353<a name="l00373"></a>00373                 jest.read_parameters(); 
     354<a name="l00374"></a>00374         } 
     355<a name="l00375"></a>00375          
     356<a name="l00376"></a>00376 }; 
     357<a name="l00377"></a>00377 <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>(MPF); 
     358<a name="l00378"></a>00378  
     359<a name="l00379"></a>00379 } 
     360<a name="l00380"></a>00380 <span class="preprocessor">#endif // KF_H</span> 
     361<a name="l00381"></a>00381 <span class="preprocessor"></span> 
     362<a name="l00382"></a>00382  
    318363</pre></div></div> 
    319 <hr size="1"/><address style="text-align: right;"><small>Generated on Fri Sep 18 00:12:03 2009 for mixpp by&nbsp; 
     364<hr size="1"/><address style="text-align: right;"><small>Generated on Sun Sep 27 00:49:04 2009 for mixpp by&nbsp; 
    320365<a href="http://www.doxygen.org/index.html"> 
    321366<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>