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>& <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 &<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<mpdf>(<span class="keyword">set</span>,<span class="stringliteral">"parameter_pdf"</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<mpdf>(<span class="keyword">set</span>,<span class="stringliteral">"observation_pdf"</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 &#39;resmethod&#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>->_rvc().remove_time().subt( <a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a>->_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->_rvc().remove_time().subt( <a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a>->_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->_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 &#39;resmethod&#39; from configuration file">resmethod_from_set</a>(<span class="keyword">const</span> Setting &<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">"resmethod"</span>,UI::optional)){ |
153 | | <a name="l00145"></a>00145 <span class="keywordflow">if</span> (resmeth==<span class="stringliteral">"systematic"</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">"multinomial"</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">"stratified"</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">"Unknown resampling method"</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">"res_threshold"</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 & <span class="keyword">set</span>){ |
174 | | <a name="l00167"></a>00167 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<epdf></a> pri = UI::build<epdf>(<span class="keyword">set</span>,<span class="stringliteral">"prior"</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<</span><a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a>*<span class="keyword">></span>(&(*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">"n"</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>->_rv()._dsize()>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>->_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">"Mismatch of RV and dimension of posterior"</span> ); |
193 | | <a name="l00186"></a>00186 } |
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 &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 Array<vec>& __samples(){<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1PF.html#a914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a>;} |
199 | | <a name="l00193"></a>00193 }; |
200 | | <a name="l00194"></a>00194 <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); |
201 | | <a name="l00195"></a>00195 |
202 | | <a name="l00203"></a><a class="code" href="classbdm_1_1MPF.html">00203</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> { |
203 | | <a name="l00204"></a>00204 <span class="keyword">protected</span>: |
204 | | <a name="l00205"></a>00205 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<PF></a> pf; |
205 | | <a name="l00206"></a>00206 Array<BM*> BMs; |
206 | | <a name="l00207"></a>00207 |
207 | | <a name="l00209"></a>00209 |
208 | | <a name="l00210"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html">00210</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html" title="internal class for MPDF providing composition of eEmp with external components">mpfepdf</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { |
209 | | <a name="l00211"></a>00211 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<PF></a> &pf; |
210 | | <a name="l00212"></a>00212 Array<BM*> &BMs; |
211 | | <a name="l00213"></a>00213 <span class="keyword">public</span>: |
212 | | <a name="l00214"></a>00214 <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html" title="internal class for MPDF providing composition of eEmp with external components">mpfepdf</a> (<a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<PF></a> &pf0, Array<BM*> &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) { }; |
213 | | <a name="l00216"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a78e10feeacd2b7d1c29c5d1041832828">00216</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a78e10feeacd2b7d1c29c5d1041832828" title="a variant of set parameters - this time, parameters are read from BMs and pf">read_parameters</a>(){ |
214 | | <a name="l00217"></a>00217 <a class="code" href="classbdm_1_1epdf.html#a62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> = concat(pf->posterior()._rv(), BMs(0)->posterior()._rv()); |
215 | | <a name="l00218"></a>00218 <a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = pf->posterior().dimension() + BMs(0)->posterior().dimension(); |
216 | | <a name="l00219"></a>00219 <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 == <a class="code" href="classbdm_1_1epdf.html#a62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#ade30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>(), <span class="stringliteral">"Wrong name "</span>); |
217 | | <a name="l00220"></a>00220 } |
218 | | <a name="l00221"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a2c1be50c8a952cdac13a1a48d5a23188">00221</a> vec <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a2c1be50c8a952cdac13a1a48d5a23188" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
219 | | <a name="l00222"></a>00222 <span class="keyword">const</span> vec &w = pf->posterior()._w(); |
220 | | <a name="l00223"></a>00223 vec pom = zeros ( BMs(0)->posterior ().<a class="code" href="classbdm_1_1epdf.html#a7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>() ); |
221 | | <a name="l00224"></a>00224 <span class="comment">//compute mean of BMs</span> |
222 | | <a name="l00225"></a>00225 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < w.length(); i++ ) { |
223 | | <a name="l00226"></a>00226 pom += BMs ( i )->posterior().mean() * w ( i ); |
224 | | <a name="l00227"></a>00227 } |
225 | | <a name="l00228"></a>00228 <span class="keywordflow">return</span> concat ( pf->posterior().mean(), pom ); |
226 | | <a name="l00229"></a>00229 } |
227 | | <a name="l00230"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a345b15545d3fa9cdcbcab616eaa66273">00230</a> vec <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a345b15545d3fa9cdcbcab616eaa66273" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
228 | | <a name="l00231"></a>00231 <span class="keyword">const</span> vec &w = pf->posterior()._w(); |
229 | | <a name="l00232"></a>00232 |
230 | | <a name="l00233"></a>00233 vec pom = zeros ( BMs(0)->posterior ().<a class="code" href="classbdm_1_1epdf.html#a7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>() ); |
231 | | <a name="l00234"></a>00234 vec pom2 = zeros ( BMs(0)->posterior ().<a class="code" href="classbdm_1_1epdf.html#a7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>() ); |
232 | | <a name="l00235"></a>00235 vec mea; |
233 | | <a name="l00236"></a>00236 |
234 | | <a name="l00237"></a>00237 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < w.length(); i++ ) { |
235 | | <a name="l00238"></a>00238 <span class="comment">// save current mean </span> |
236 | | <a name="l00239"></a>00239 mea = BMs ( i )->posterior().mean(); |
237 | | <a name="l00240"></a>00240 pom += mea * w ( i ); |
238 | | <a name="l00241"></a>00241 <span class="comment">//compute variance</span> |
239 | | <a name="l00242"></a>00242 pom2 += ( BMs ( i )->posterior().variance() + pow ( mea, 2 ) ) * w ( i ); |
240 | | <a name="l00243"></a>00243 } |
241 | | <a name="l00244"></a>00244 <span class="keywordflow">return</span> concat ( pf->posterior().variance(), pom2 - pow ( pom, 2 ) ); |
242 | | <a name="l00245"></a>00245 } |
243 | | <a name="l00246"></a>00246 |
244 | | <a name="l00247"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a3db96ec592cc1d39195e5740694435bf">00247</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a3db96ec592cc1d39195e5740694435bf" title="Lower and upper bounds of percentage % quantile, returns mean-2*sigma as default...">qbounds</a> ( vec &lb, vec &ub, <span class="keywordtype">double</span> perc = 0.95 )<span class="keyword"> const </span>{ |
245 | | <a name="l00248"></a>00248 <span class="comment">//bounds on particles</span> |
246 | | <a name="l00249"></a>00249 vec lbp; |
247 | | <a name="l00250"></a>00250 vec ubp; |
248 | | <a name="l00251"></a>00251 pf->posterior().qbounds ( lbp, ubp ); |
249 | | <a name="l00252"></a>00252 |
250 | | <a name="l00253"></a>00253 <span class="comment">//bounds on Components</span> |
251 | | <a name="l00254"></a>00254 <span class="keywordtype">int</span> dimC = BMs ( 0 )->posterior().dimension(); |
252 | | <a name="l00255"></a>00255 <span class="keywordtype">int</span> j; |
253 | | <a name="l00256"></a>00256 <span class="comment">// temporary</span> |
254 | | <a name="l00257"></a>00257 vec lbc ( dimC ); |
255 | | <a name="l00258"></a>00258 vec ubc ( dimC ); |
256 | | <a name="l00259"></a>00259 <span class="comment">// minima and maxima</span> |
257 | | <a name="l00260"></a>00260 vec Lbc ( dimC ); |
258 | | <a name="l00261"></a>00261 vec Ubc ( dimC ); |
259 | | <a name="l00262"></a>00262 Lbc = std::numeric_limits<double>::infinity(); |
260 | | <a name="l00263"></a>00263 Ubc = -std::numeric_limits<double>::infinity(); |
261 | | <a name="l00264"></a>00264 |
262 | | <a name="l00265"></a>00265 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < BMs.length(); i++ ) { |
263 | | <a name="l00266"></a>00266 <span class="comment">// check Coms</span> |
264 | | <a name="l00267"></a>00267 BMs ( i )->posterior().qbounds ( lbc, ubc ); |
265 | | <a name="l00268"></a>00268 <span class="comment">//save either minima or maxima</span> |
266 | | <a name="l00269"></a>00269 <span class="keywordflow">for</span> ( j = 0; j < dimC; j++ ) { |
267 | | <a name="l00270"></a>00270 <span class="keywordflow">if</span> ( lbc ( j ) < Lbc ( j ) ) { |
268 | | <a name="l00271"></a>00271 Lbc ( j ) = lbc ( j ); |
269 | | <a name="l00272"></a>00272 } |
270 | | <a name="l00273"></a>00273 <span class="keywordflow">if</span> ( ubc ( j ) > Ubc ( j ) ) { |
271 | | <a name="l00274"></a>00274 Ubc ( j ) = ubc ( j ); |
272 | | <a name="l00275"></a>00275 } |
273 | | <a name="l00276"></a>00276 } |
274 | | <a name="l00277"></a>00277 } |
275 | | <a name="l00278"></a>00278 lb = concat ( lbp, Lbc ); |
276 | | <a name="l00279"></a>00279 ub = concat ( ubp, Ubc ); |
277 | | <a name="l00280"></a>00280 } |
278 | | <a name="l00281"></a>00281 |
279 | | <a name="l00282"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a3825c7817ee2b5bf92f12b899fc39863">00282</a> vec <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a3825c7817ee2b5bf92f12b899fc39863" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
280 | | <a name="l00283"></a>00283 <a class="code" href="bdmerror_8h.html#a7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> ( <span class="stringliteral">"Not implemented"</span> ); |
281 | | <a name="l00284"></a>00284 <span class="keywordflow">return</span> vec(); |
282 | | <a name="l00285"></a>00285 } |
283 | | <a name="l00286"></a>00286 |
284 | | <a name="l00287"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a64823e29b83f15bfcb144126e03f4f3f">00287</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a64823e29b83f15bfcb144126e03f4f3f" title="Compute log-probability of argument val In case the argument is out of suport return...">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
285 | | <a name="l00288"></a>00288 <a class="code" href="bdmerror_8h.html#a7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> ( <span class="stringliteral">"not implemented"</span> ); |
286 | | <a name="l00289"></a>00289 <span class="keywordflow">return</span> 0.0; |
287 | | <a name="l00290"></a>00290 } |
288 | | <a name="l00291"></a>00291 }; |
289 | | <a name="l00292"></a>00292 |
290 | | <a name="l00294"></a><a class="code" href="classbdm_1_1MPF.html#af50fc7db1d6255a0b5517549f727c6bd">00294</a> <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html" title="internal class for MPDF providing composition of eEmp with external components">mpfepdf</a> <a class="code" href="classbdm_1_1MPF.html#af50fc7db1d6255a0b5517549f727c6bd" title="Density joining PF.est with conditional parts.">jest</a>; |
291 | | <a name="l00295"></a>00295 |
292 | | <a name="l00297"></a><a class="code" href="classbdm_1_1MPF.html#a9e2a4b7abf06feeeaaa56ad695e284ac">00297</a> <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1MPF.html#a9e2a4b7abf06feeeaaa56ad695e284ac" title="Log means of BMs.">opt_L_mea</a>; |
293 | | <a name="l00298"></a>00298 |
294 | | <a name="l00299"></a>00299 <span class="keyword">public</span>: |
295 | | <a name="l00301"></a><a class="code" href="classbdm_1_1MPF.html#af45da512c659b40b21a74492a0c06853">00301</a> <a class="code" href="classbdm_1_1MPF.html#af45da512c659b40b21a74492a0c06853" title="Default constructor.">MPF</a> () : <a class="code" href="classbdm_1_1MPF.html#af50fc7db1d6255a0b5517549f727c6bd" title="Density joining PF.est with conditional parts.">jest</a> (pf,BMs) {}; |
296 | | <a name="l00302"></a>00302 <span class="keywordtype">void</span> set_parameters ( <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></a> par0, <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></a> obs0, <span class="keywordtype">int</span> n0, RESAMPLING_METHOD rm = SYSTEMATIC ) { |
297 | | <a name="l00303"></a>00303 pf->set_model ( par0, obs0); |
298 | | <a name="l00304"></a>00304 pf->set_parameters(n0, rm ); |
299 | | <a name="l00305"></a>00305 BMs.set_length ( n0 ); |
300 | | <a name="l00306"></a>00306 } |
301 | | <a name="l00307"></a>00307 <span class="keywordtype">void</span> set_BM ( <span class="keyword">const</span> BM &BMcond0 ) { |
302 | | <a name="l00308"></a>00308 |
303 | | <a name="l00309"></a>00309 <span class="keywordtype">int</span> n=pf->__w().length(); |
304 | | <a name="l00310"></a>00310 BMs.set_length(n); |
305 | | <a name="l00311"></a>00311 <span class="comment">// copy</span> |
306 | | <a name="l00312"></a>00312 <span class="comment">//BMcond0 .condition ( pf->posterior()._sample ( 0 ) );</span> |
307 | | <a name="l00313"></a>00313 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < n; i++ ) { |
308 | | <a name="l00314"></a>00314 BMs ( i ) = BMcond0._copy_(); |
309 | | <a name="l00315"></a>00315 BMs ( i )->condition ( pf->posterior()._sample ( i ) ); |
310 | | <a name="l00316"></a>00316 } |
311 | | <a name="l00317"></a>00317 }; |
312 | | <a name="l00318"></a>00318 |
313 | | <a name="l00319"></a>00319 <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 &dt ); |
314 | | <a name="l00320"></a>00320 <span class="keyword">const</span> epdf& posterior()<span class="keyword"> const </span>{ |
315 | | <a name="l00321"></a>00321 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1MPF.html#af50fc7db1d6255a0b5517549f727c6bd" title="Density joining PF.est with conditional parts.">jest</a>; |
316 | | <a name="l00322"></a>00322 } |
317 | | <a name="l00325"></a><a class="code" href="classbdm_1_1MPF.html#aada1bdb117bc78035fbb49765fa7ef10">00325</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> &opt ) { |
318 | | <a name="l00326"></a>00326 <a class="code" href="classbdm_1_1MPF.html#aada1bdb117bc78035fbb49765fa7ef10">BM::set_options</a>(opt); |
319 | | <a name="l00327"></a>00327 <a class="code" href="classbdm_1_1MPF.html#a9e2a4b7abf06feeeaaa56ad695e284ac" title="Log means of BMs.">opt_L_mea</a> = ( opt.find ( <span class="stringliteral">"logmeans"</span> ) != string::npos ); |
320 | | <a name="l00328"></a>00328 } |
321 | | <a name="l00329"></a>00329 |
322 | | <a name="l00331"></a><a class="code" href="classbdm_1_1MPF.html#a71608a6986f57dcfb935e016b97c0637">00331</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 ) { |
323 | | <a name="l00332"></a>00332 <span class="keywordflow">return</span> BMs ( i ); |
324 | | <a name="l00333"></a>00333 } |
325 | | <a name="l00334"></a>00334 |
326 | | <a name="l00346"></a><a class="code" href="classbdm_1_1MPF.html#a9f74326b9ca3c888cb8eff1355ba3670">00346</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#a9f74326b9ca3c888cb8eff1355ba3670">from_setting</a>(<span class="keyword">const</span> Setting &<span class="keyword">set</span>){ |
327 | | <a name="l00347"></a>00347 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></a> par = UI::build<mpdf>(<span class="keyword">set</span>,<span class="stringliteral">"parameter_pdf"</span>,UI::compulsory); |
328 | | <a name="l00348"></a>00348 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></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> |
329 | | <a name="l00349"></a>00349 |
330 | | <a name="l00350"></a>00350 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>; |
331 | | <a name="l00351"></a>00351 <span class="comment">// rpior must be set before BM</span> |
332 | | <a name="l00352"></a>00352 pf->prior_from_set(<span class="keyword">set</span>); |
333 | | <a name="l00353"></a>00353 pf->resmethod_from_set(<span class="keyword">set</span>); |
334 | | <a name="l00354"></a>00354 pf->set_model(par,obs); |
335 | | <a name="l00355"></a>00355 |
336 | | <a name="l00356"></a>00356 <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<BM></a> BM0 =UI::build<BM>(<span class="keyword">set</span>,<span class="stringliteral">"BM"</span>,UI::compulsory); |
337 | | <a name="l00357"></a>00357 set_BM(*BM0); |
338 | | <a name="l00358"></a>00358 |
339 | | <a name="l00359"></a>00359 <span class="keywordtype">string</span> opt; |
340 | | <a name="l00360"></a>00360 <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">"options"</span>,UI::optional)){ |
341 | | <a name="l00361"></a>00361 <a class="code" href="classbdm_1_1MPF.html#aada1bdb117bc78035fbb49765fa7ef10">set_options</a>(opt); |
342 | | <a name="l00362"></a>00362 } |
343 | | <a name="l00363"></a>00363 <span class="comment">//set drv</span> |
344 | | <a name="l00364"></a>00364 <span class="comment">//find potential input - what remains in rvc when we subtract rv</span> |
345 | | <a name="l00365"></a>00365 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> u = par->_rvc().remove_time().subt( par->_rv() ); |
346 | | <a name="l00366"></a>00366 set_drv(concat(BM0->_drv(),u) ); |
347 | | <a name="l00367"></a>00367 <a class="code" href="classbdm_1_1MPF.html#aa91b588de1b9690ca475c945d0f10f08" title="This method TODO.">validate</a>(); |
348 | | <a name="l00368"></a>00368 } |
349 | | <a name="l00369"></a><a class="code" href="classbdm_1_1MPF.html#aa91b588de1b9690ca475c945d0f10f08">00369</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#aa91b588de1b9690ca475c945d0f10f08" title="This method TODO.">validate</a>(){ |
350 | | <a name="l00370"></a>00370 <span class="keywordflow">try</span>{ |
351 | | <a name="l00371"></a>00371 pf->validate(); |
352 | | <a name="l00372"></a>00372 } <span class="keywordflow">catch</span> (std::exception &e){ |
353 | | <a name="l00373"></a>00373 <span class="keywordflow">throw</span> <a class="code" href="classbdm_1_1UIException.html">UIException</a>(<span class="stringliteral">"Error in PF part of MPF:"</span>); |
354 | | <a name="l00374"></a>00374 } |
355 | | <a name="l00375"></a>00375 <a class="code" href="classbdm_1_1MPF.html#af50fc7db1d6255a0b5517549f727c6bd" title="Density joining PF.est with conditional parts.">jest</a>.<a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a78e10feeacd2b7d1c29c5d1041832828" title="a variant of set parameters - this time, parameters are read from BMs and pf">read_parameters</a>(); |
| 130 | <a name="l00109"></a><a class="code" href="classbdm_1_1PF.html#ab4e4023b749c33fc6d6b97d805338721">00109</a> RESAMPLING_METHOD <a class="code" href="classbdm_1_1PF.html#ab4e4023b749c33fc6d6b97d805338721" title="access function">_resmethod</a>()<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="l00111"></a><a class="code" href="classbdm_1_1PF.html#aee9553da1a05671f94f30e0e94ff42cd">00111</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a>& <a class="code" href="classbdm_1_1PF.html#aee9553da1a05671f94f30e0e94ff42cd" title="return correctly typed posterior (covariant return)">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="l00112"></a>00112 |
| 133 | <a name="l00125"></a><a class="code" href="classbdm_1_1PF.html#a40d74160df73d152a9bcf044eac25663">00125</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#a40d74160df73d152a9bcf044eac25663">from_setting</a>(<span class="keyword">const</span> Setting &<span class="keyword">set</span>){ |
| 134 | <a name="l00126"></a>00126 <a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a> = UI::build<mpdf>(<span class="keyword">set</span>,<span class="stringliteral">"parameter_pdf"</span>,UI::compulsory); |
| 135 | <a name="l00127"></a>00127 <a class="code" href="classbdm_1_1PF.html#a77ed889e1b993df253e93059933d227d" title="Observation model.">obs</a> = UI::build<mpdf>(<span class="keyword">set</span>,<span class="stringliteral">"observation_pdf"</span>,UI::compulsory); |
| 136 | <a name="l00128"></a>00128 |
| 137 | <a name="l00129"></a>00129 <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="l00130"></a>00130 <a class="code" href="classbdm_1_1PF.html#a30f6a71f3e56ce25e4e0ecafa0ffbd8d" title="auxiliary function reading parameter &#39;resmethod&#39; from configuration file">resmethod_from_set</a>(<span class="keyword">set</span>); |
| 139 | <a name="l00131"></a>00131 <span class="comment">// set resampling method</span> |
| 140 | <a name="l00132"></a>00132 <span class="comment">//set drv</span> |
| 141 | <a name="l00133"></a>00133 <span class="comment">//find potential input - what remains in rvc when we subtract rv</span> |
| 142 | <a name="l00134"></a>00134 <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>->_rvc().remove_time().subt( <a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a>->_rv() ); |
| 143 | <a name="l00135"></a>00135 <span class="comment">//find potential input - what remains in rvc when we subtract x_t</span> |
| 144 | <a name="l00136"></a>00136 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> obs_u = obs->_rvc().remove_time().subt( <a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a>->_rv() ); |
| 145 | <a name="l00137"></a>00137 |
| 146 | <a name="l00138"></a>00138 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="l00139"></a>00139 |
| 148 | <a name="l00140"></a>00140 <a class="code" href="classbdm_1_1BM.html#af135ae6dce7e9f30c9f88229c7930b96" title="access function">set_drv</a>(concat(obs->_rv(),u) ); |
| 149 | <a name="l00141"></a>00141 } |
| 150 | <a name="l00143"></a><a class="code" href="classbdm_1_1PF.html#a30f6a71f3e56ce25e4e0ecafa0ffbd8d">00143</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#a30f6a71f3e56ce25e4e0ecafa0ffbd8d" title="auxiliary function reading parameter &#39;resmethod&#39; from configuration file">resmethod_from_set</a>(<span class="keyword">const</span> Setting &<span class="keyword">set</span>){ |
| 151 | <a name="l00144"></a>00144 <span class="keywordtype">string</span> resmeth; |
| 152 | <a name="l00145"></a>00145 <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">"resmethod"</span>,UI::optional)){ |
| 153 | <a name="l00146"></a>00146 <span class="keywordflow">if</span> (resmeth==<span class="stringliteral">"systematic"</span>) { |
| 154 | <a name="l00147"></a>00147 <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>= SYSTEMATIC; |
| 155 | <a name="l00148"></a>00148 } <span class="keywordflow">else</span> { |
| 156 | <a name="l00149"></a>00149 <span class="keywordflow">if</span> (resmeth==<span class="stringliteral">"multinomial"</span>){ |
| 157 | <a name="l00150"></a>00150 <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>=MULTINOMIAL; |
| 158 | <a name="l00151"></a>00151 } <span class="keywordflow">else</span> { |
| 159 | <a name="l00152"></a>00152 <span class="keywordflow">if</span> (resmeth==<span class="stringliteral">"stratified"</span>){ |
| 160 | <a name="l00153"></a>00153 <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>= STRATIFIED; |
| 161 | <a name="l00154"></a>00154 } <span class="keywordflow">else</span> { |
| 162 | <a name="l00155"></a>00155 <a class="code" href="bdmerror_8h.html#a7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a>(<span class="stringliteral">"Unknown resampling method"</span>); |
| 163 | <a name="l00156"></a>00156 } |
| 164 | <a name="l00157"></a>00157 } |
| 165 | <a name="l00158"></a>00158 } |
| 166 | <a name="l00159"></a>00159 } <span class="keywordflow">else</span> { |
| 167 | <a name="l00160"></a>00160 <a class="code" href="classbdm_1_1PF.html#a9932c7c5865954ef9a438afcbe944e52" title="which resampling method will be used">resmethod</a>=SYSTEMATIC; |
| 168 | <a name="l00161"></a>00161 }; |
| 169 | <a name="l00162"></a>00162 <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">"res_threshold"</span>, UI::optional)){ |
| 170 | <a name="l00163"></a>00163 <a class="code" href="classbdm_1_1PF.html#ab16816e20f97f9bec993d1f25fc3d711">res_threshold</a>=0.5; |
| 171 | <a name="l00164"></a>00164 } |
| 172 | <a name="l00165"></a>00165 } |
| 173 | <a name="l00167"></a><a class="code" href="classbdm_1_1PF.html#a8ac867d4b88c2c6c73ae29d47f37d0bb">00167</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 & <span class="keyword">set</span>){ |
| 174 | <a name="l00168"></a>00168 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<epdf></a> pri = UI::build<epdf>(<span class="keyword">set</span>,<span class="stringliteral">"prior"</span>,UI::compulsory); |
| 175 | <a name="l00169"></a>00169 |
| 176 | <a name="l00170"></a>00170 <a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a> *test_emp=<span class="keyword">dynamic_cast<</span><a class="code" href="classbdm_1_1eEmp.html" title="Weighted empirical density.">eEmp</a>*<span class="keyword">></span>(&(*pri)); |
| 177 | <a name="l00171"></a>00171 <span class="keywordflow">if</span> (test_emp) { <span class="comment">// given pdf is sampled</span> |
| 178 | <a name="l00172"></a>00172 <a class="code" href="classbdm_1_1PF.html#adc049265b9086cad7071f98d00a2b9af" title="posterior density">est</a>=*test_emp; |
| 179 | <a name="l00173"></a>00173 } <span class="keywordflow">else</span> { |
| 180 | <a name="l00174"></a>00174 <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1PF.html#aeeafaf9b8ad75fe62ee9fd6369e3f7fe" title="number of particles;">n</a>; |
| 181 | <a name="l00175"></a>00175 <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">"n"</span>,UI::optional)){n=10;} |
| 182 | <a name="l00176"></a>00176 <span class="comment">// sample from prior</span> |
| 183 | <a name="l00177"></a>00177 set_statistics(ones(n)/n, *pri); |
| 184 | <a name="l00178"></a>00178 } |
| 185 | <a name="l00179"></a>00179 <span class="comment">//validate();</span> |
| 186 | <a name="l00180"></a>00180 } |
| 187 | <a name="l00181"></a>00181 |
| 188 | <a name="l00182"></a><a class="code" href="classbdm_1_1PF.html#a7ebbb12b5b01e8ac6985af0e04e0f0c2">00182</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1PF.html#a7ebbb12b5b01e8ac6985af0e04e0f0c2" title="This method TODO.">validate</a>(){ |
| 189 | <a name="l00183"></a>00183 <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="l00184"></a>00184 <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="l00185"></a>00185 <span class="keywordflow">if</span> (<a class="code" href="classbdm_1_1PF.html#a0b7ffedb2051161df6c102881afe41ff" title="Parameter evolution model.">par</a>->_rv()._dsize()>0) { |
| 192 | <a name="l00186"></a>00186 <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>->_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">"Mismatch of RV and dimension of posterior"</span> ); |
| 193 | <a name="l00187"></a>00187 } |
| 194 | <a name="l00188"></a>00188 } |
| 195 | <a name="l00190"></a><a class="code" href="classbdm_1_1PF.html#a10fd6402c67ad3ee3a1a9a23fe91d7d7">00190</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 &ind){ |
| 196 | <a name="l00191"></a>00191 <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="l00192"></a>00192 } |
| 198 | <a name="l00194"></a><a class="code" href="classbdm_1_1PF.html#ad9a47fe83feff47b5c60c2f03117b4bb">00194</a> Array<vec>& <a class="code" href="classbdm_1_1PF.html#ad9a47fe83feff47b5c60c2f03117b4bb" title="access function">__samples</a>(){<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1PF.html#a914bd66025692c4018dbd482cb3c47c1" title="pointer into eEmp ">_samples</a>;} |
| 199 | <a name="l00195"></a>00195 }; |
| 200 | <a name="l00196"></a>00196 <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); |
| 201 | <a name="l00197"></a>00197 |
| 202 | <a name="l00205"></a><a class="code" href="classbdm_1_1MPF.html">00205</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> { |
| 203 | <a name="l00206"></a>00206 <span class="keyword">protected</span>: |
| 204 | <a name="l00208"></a><a class="code" href="classbdm_1_1MPF.html#a3bfa12c5566a0a38f30fec3a9eca1563">00208</a> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<PF></a> <a class="code" href="classbdm_1_1MPF.html#a3bfa12c5566a0a38f30fec3a9eca1563" title="particle filter on non-linear variable">pf</a>; |
| 205 | <a name="l00210"></a><a class="code" href="classbdm_1_1MPF.html#ad496b1378a6fd715ee64608b1dcb75ae">00210</a> Array<BM*> <a class="code" href="classbdm_1_1MPF.html#ad496b1378a6fd715ee64608b1dcb75ae" title="Array of Bayesian models.">BMs</a>; |
| 206 | <a name="l00211"></a>00211 |
| 207 | <a name="l00213"></a>00213 |
| 208 | <a name="l00214"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html">00214</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html" title="internal class for MPDF providing composition of eEmp with external components">mpfepdf</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1epdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { |
| 209 | <a name="l00216"></a>00216 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<PF></a> &pf; |
| 210 | <a name="l00218"></a>00218 Array<BM*> &BMs; |
| 211 | <a name="l00219"></a>00219 <span class="keyword">public</span>: |
| 212 | <a name="l00221"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a9aa9a7e99f913443a88d32365ac3e640">00221</a> <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a9aa9a7e99f913443a88d32365ac3e640" title="constructor">mpfepdf</a> (<a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<PF></a> &pf0, Array<BM*> &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) { }; |
| 213 | <a name="l00223"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a78e10feeacd2b7d1c29c5d1041832828">00223</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a78e10feeacd2b7d1c29c5d1041832828" title="a variant of set parameters - this time, parameters are read from BMs and pf">read_parameters</a>(){ |
| 214 | <a name="l00224"></a>00224 <a class="code" href="classbdm_1_1epdf.html#a62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a> = concat(pf->posterior()._rv(), BMs(0)->posterior()._rv()); |
| 215 | <a name="l00225"></a>00225 <a class="code" href="classbdm_1_1epdf.html#a16adac20ec7fe07e1ea0b27d917788ce" title="dimension of the random variable">dim</a> = pf->posterior().dimension() + BMs(0)->posterior().dimension(); |
| 216 | <a name="l00226"></a>00226 <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 == <a class="code" href="classbdm_1_1epdf.html#a62c5b8ff71d9ebe6cd58d3c342eb1dc8" title="Description of the random variable.">rv</a>.<a class="code" href="classbdm_1_1RV.html#ade30156104f61d86c94f758861418089" title="total size of a random variable">_dsize</a>(), <span class="stringliteral">"Wrong name "</span>); |
| 217 | <a name="l00227"></a>00227 } |
| 218 | <a name="l00228"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a2c1be50c8a952cdac13a1a48d5a23188">00228</a> vec <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a2c1be50c8a952cdac13a1a48d5a23188" title="return expected value">mean</a>()<span class="keyword"> const </span>{ |
| 219 | <a name="l00229"></a>00229 <span class="keyword">const</span> vec &w = pf->posterior()._w(); |
| 220 | <a name="l00230"></a>00230 vec pom = zeros ( BMs(0)-><a class="code" href="classbdm_1_1MPF.html#a4f4cd8060351dc1a344974e86ffb876b" title="return posterior density">posterior</a> ().<a class="code" href="classbdm_1_1epdf.html#a7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>() ); |
| 221 | <a name="l00231"></a>00231 <span class="comment">//compute mean of BMs</span> |
| 222 | <a name="l00232"></a>00232 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < w.length(); i++ ) { |
| 223 | <a name="l00233"></a>00233 pom += BMs ( i )->posterior().mean() * w ( i ); |
| 224 | <a name="l00234"></a>00234 } |
| 225 | <a name="l00235"></a>00235 <span class="keywordflow">return</span> concat ( pf->posterior().mean(), pom ); |
| 226 | <a name="l00236"></a>00236 } |
| 227 | <a name="l00237"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a345b15545d3fa9cdcbcab616eaa66273">00237</a> vec <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a345b15545d3fa9cdcbcab616eaa66273" title="return expected variance (not covariance!)">variance</a>()<span class="keyword"> const </span>{ |
| 228 | <a name="l00238"></a>00238 <span class="keyword">const</span> vec &w = pf->posterior()._w(); |
| 229 | <a name="l00239"></a>00239 |
| 230 | <a name="l00240"></a>00240 vec pom = zeros ( BMs(0)-><a class="code" href="classbdm_1_1MPF.html#a4f4cd8060351dc1a344974e86ffb876b" title="return posterior density">posterior</a> ().<a class="code" href="classbdm_1_1epdf.html#a7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>() ); |
| 231 | <a name="l00241"></a>00241 vec pom2 = zeros ( BMs(0)-><a class="code" href="classbdm_1_1MPF.html#a4f4cd8060351dc1a344974e86ffb876b" title="return posterior density">posterior</a> ().<a class="code" href="classbdm_1_1epdf.html#a7083a65f7b7a0d0d13b2c516bd2ec29c" title="Size of the random variable.">dimension</a>() ); |
| 232 | <a name="l00242"></a>00242 vec mea; |
| 233 | <a name="l00243"></a>00243 |
| 234 | <a name="l00244"></a>00244 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < w.length(); i++ ) { |
| 235 | <a name="l00245"></a>00245 <span class="comment">// save current mean </span> |
| 236 | <a name="l00246"></a>00246 mea = BMs ( i )->posterior().mean(); |
| 237 | <a name="l00247"></a>00247 pom += mea * w ( i ); |
| 238 | <a name="l00248"></a>00248 <span class="comment">//compute variance</span> |
| 239 | <a name="l00249"></a>00249 pom2 += ( BMs ( i )->posterior().variance() + pow ( mea, 2 ) ) * w ( i ); |
| 240 | <a name="l00250"></a>00250 } |
| 241 | <a name="l00251"></a>00251 <span class="keywordflow">return</span> concat ( pf->posterior().variance(), pom2 - pow ( pom, 2 ) ); |
| 242 | <a name="l00252"></a>00252 } |
| 243 | <a name="l00253"></a>00253 |
| 244 | <a name="l00254"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a3db96ec592cc1d39195e5740694435bf">00254</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a3db96ec592cc1d39195e5740694435bf" title="Lower and upper bounds of percentage % quantile, returns mean-2*sigma as default...">qbounds</a> ( vec &lb, vec &ub, <span class="keywordtype">double</span> perc = 0.95 )<span class="keyword"> const </span>{ |
| 245 | <a name="l00255"></a>00255 <span class="comment">//bounds on particles</span> |
| 246 | <a name="l00256"></a>00256 vec lbp; |
| 247 | <a name="l00257"></a>00257 vec ubp; |
| 248 | <a name="l00258"></a>00258 pf->posterior().qbounds ( lbp, ubp ); |
| 249 | <a name="l00259"></a>00259 |
| 250 | <a name="l00260"></a>00260 <span class="comment">//bounds on Components</span> |
| 251 | <a name="l00261"></a>00261 <span class="keywordtype">int</span> dimC = BMs ( 0 )->posterior().dimension(); |
| 252 | <a name="l00262"></a>00262 <span class="keywordtype">int</span> j; |
| 253 | <a name="l00263"></a>00263 <span class="comment">// temporary</span> |
| 254 | <a name="l00264"></a>00264 vec lbc ( dimC ); |
| 255 | <a name="l00265"></a>00265 vec ubc ( dimC ); |
| 256 | <a name="l00266"></a>00266 <span class="comment">// minima and maxima</span> |
| 257 | <a name="l00267"></a>00267 vec Lbc ( dimC ); |
| 258 | <a name="l00268"></a>00268 vec Ubc ( dimC ); |
| 259 | <a name="l00269"></a>00269 Lbc = std::numeric_limits<double>::infinity(); |
| 260 | <a name="l00270"></a>00270 Ubc = -std::numeric_limits<double>::infinity(); |
| 261 | <a name="l00271"></a>00271 |
| 262 | <a name="l00272"></a>00272 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < BMs.length(); i++ ) { |
| 263 | <a name="l00273"></a>00273 <span class="comment">// check Coms</span> |
| 264 | <a name="l00274"></a>00274 BMs ( i )->posterior().qbounds ( lbc, ubc ); |
| 265 | <a name="l00275"></a>00275 <span class="comment">//save either minima or maxima</span> |
| 266 | <a name="l00276"></a>00276 <span class="keywordflow">for</span> ( j = 0; j < dimC; j++ ) { |
| 267 | <a name="l00277"></a>00277 <span class="keywordflow">if</span> ( lbc ( j ) < Lbc ( j ) ) { |
| 268 | <a name="l00278"></a>00278 Lbc ( j ) = lbc ( j ); |
| 269 | <a name="l00279"></a>00279 } |
| 270 | <a name="l00280"></a>00280 <span class="keywordflow">if</span> ( ubc ( j ) > Ubc ( j ) ) { |
| 271 | <a name="l00281"></a>00281 Ubc ( j ) = ubc ( j ); |
| 272 | <a name="l00282"></a>00282 } |
| 273 | <a name="l00283"></a>00283 } |
| 274 | <a name="l00284"></a>00284 } |
| 275 | <a name="l00285"></a>00285 lb = concat ( lbp, Lbc ); |
| 276 | <a name="l00286"></a>00286 ub = concat ( ubp, Ubc ); |
| 277 | <a name="l00287"></a>00287 } |
| 278 | <a name="l00288"></a>00288 |
| 279 | <a name="l00289"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a3825c7817ee2b5bf92f12b899fc39863">00289</a> vec <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a3825c7817ee2b5bf92f12b899fc39863" title="Returns a sample, from density .">sample</a>()<span class="keyword"> const </span>{ |
| 280 | <a name="l00290"></a>00290 <a class="code" href="bdmerror_8h.html#a7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> ( <span class="stringliteral">"Not implemented"</span> ); |
| 281 | <a name="l00291"></a>00291 <span class="keywordflow">return</span> vec(); |
| 282 | <a name="l00292"></a>00292 } |
| 283 | <a name="l00293"></a>00293 |
| 284 | <a name="l00294"></a><a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a64823e29b83f15bfcb144126e03f4f3f">00294</a> <span class="keywordtype">double</span> <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html#a64823e29b83f15bfcb144126e03f4f3f">evallog</a> ( <span class="keyword">const</span> vec &val )<span class="keyword"> const </span>{ |
| 285 | <a name="l00295"></a>00295 <a class="code" href="bdmerror_8h.html#a7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> ( <span class="stringliteral">"not implemented"</span> ); |
| 286 | <a name="l00296"></a>00296 <span class="keywordflow">return</span> 0.0; |
| 287 | <a name="l00297"></a>00297 } |
| 288 | <a name="l00298"></a>00298 }; |
| 289 | <a name="l00299"></a>00299 |
| 290 | <a name="l00301"></a><a class="code" href="classbdm_1_1MPF.html#af50fc7db1d6255a0b5517549f727c6bd">00301</a> <a class="code" href="classbdm_1_1MPF_1_1mpfepdf.html" title="internal class for MPDF providing composition of eEmp with external components">mpfepdf</a> <a class="code" href="classbdm_1_1MPF.html#af50fc7db1d6255a0b5517549f727c6bd" title="Density joining PF.est with conditional parts.">jest</a>; |
| 291 | <a name="l00302"></a>00302 |
| 292 | <a name="l00304"></a><a class="code" href="classbdm_1_1MPF.html#a9e2a4b7abf06feeeaaa56ad695e284ac">00304</a> <span class="keywordtype">bool</span> <a class="code" href="classbdm_1_1MPF.html#a9e2a4b7abf06feeeaaa56ad695e284ac" title="Log means of BMs.">opt_L_mea</a>; |
| 293 | <a name="l00305"></a>00305 |
| 294 | <a name="l00306"></a>00306 <span class="keyword">public</span>: |
| 295 | <a name="l00308"></a><a class="code" href="classbdm_1_1MPF.html#af45da512c659b40b21a74492a0c06853">00308</a> <a class="code" href="classbdm_1_1MPF.html#af45da512c659b40b21a74492a0c06853" title="Default constructor.">MPF</a> () : <a class="code" href="classbdm_1_1MPF.html#af50fc7db1d6255a0b5517549f727c6bd" title="Density joining PF.est with conditional parts.">jest</a> (<a class="code" href="classbdm_1_1MPF.html#a3bfa12c5566a0a38f30fec3a9eca1563" title="particle filter on non-linear variable">pf</a>,<a class="code" href="classbdm_1_1MPF.html#ad496b1378a6fd715ee64608b1dcb75ae" title="Array of Bayesian models.">BMs</a>) {}; |
| 296 | <a name="l00310"></a><a class="code" href="classbdm_1_1MPF.html#acea07b8861bcd1a82b63cc9c7383fbfd">00310</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#acea07b8861bcd1a82b63cc9c7383fbfd" title="set all parameters at once">set_parameters</a> ( <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></a> par0, <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></a> obs0, <span class="keywordtype">int</span> n0, RESAMPLING_METHOD rm = SYSTEMATIC ) { |
| 297 | <a name="l00311"></a>00311 <a class="code" href="classbdm_1_1MPF.html#a3bfa12c5566a0a38f30fec3a9eca1563" title="particle filter on non-linear variable">pf</a>->set_model ( par0, obs0); |
| 298 | <a name="l00312"></a>00312 <a class="code" href="classbdm_1_1MPF.html#a3bfa12c5566a0a38f30fec3a9eca1563" title="particle filter on non-linear variable">pf</a>->set_parameters(n0, rm ); |
| 299 | <a name="l00313"></a>00313 <a class="code" href="classbdm_1_1MPF.html#ad496b1378a6fd715ee64608b1dcb75ae" title="Array of Bayesian models.">BMs</a>.set_length ( n0 ); |
| 300 | <a name="l00314"></a>00314 } |
| 301 | <a name="l00316"></a><a class="code" href="classbdm_1_1MPF.html#ac3ecf10c8f2e9114c7a57f122890aa9a">00316</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#ac3ecf10c8f2e9114c7a57f122890aa9a" title="set a prototype of BM, copy it to as many times as there is particles in pf">set_BM</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> &BMcond0 ) { |
| 302 | <a name="l00317"></a>00317 |
| 303 | <a name="l00318"></a>00318 <span class="keywordtype">int</span> n=<a class="code" href="classbdm_1_1MPF.html#a3bfa12c5566a0a38f30fec3a9eca1563" title="particle filter on non-linear variable">pf</a>->__w().length(); |
| 304 | <a name="l00319"></a>00319 <a class="code" href="classbdm_1_1MPF.html#ad496b1378a6fd715ee64608b1dcb75ae" title="Array of Bayesian models.">BMs</a>.set_length(n); |
| 305 | <a name="l00320"></a>00320 <span class="comment">// copy</span> |
| 306 | <a name="l00321"></a>00321 <span class="comment">//BMcond0 .condition ( pf->posterior()._sample ( 0 ) );</span> |
| 307 | <a name="l00322"></a>00322 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < n; i++ ) { |
| 308 | <a name="l00323"></a>00323 <a class="code" href="classbdm_1_1MPF.html#ad496b1378a6fd715ee64608b1dcb75ae" title="Array of Bayesian models.">BMs</a> ( i ) = BMcond0.<a class="code" href="classbdm_1_1BM.html#a40f01563651c1e4fe926189e41a6b8ab" title="Copy function required in vectors, Arrays of BM etc. Have to be DELETED manually!...">_copy_</a>(); |
| 309 | <a name="l00324"></a>00324 } |
| 310 | <a name="l00325"></a>00325 }; |
| 311 | <a name="l00326"></a>00326 |
| 312 | <a name="l00327"></a>00327 <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 &dt ); |
| 313 | <a name="l00328"></a><a class="code" href="classbdm_1_1MPF.html#a4f4cd8060351dc1a344974e86ffb876b">00328</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>& <a class="code" href="classbdm_1_1MPF.html#a4f4cd8060351dc1a344974e86ffb876b" title="return posterior density">posterior</a>()<span class="keyword"> const </span>{ |
| 314 | <a name="l00329"></a>00329 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1MPF.html#af50fc7db1d6255a0b5517549f727c6bd" title="Density joining PF.est with conditional parts.">jest</a>; |
| 315 | <a name="l00330"></a>00330 } |
| 316 | <a name="l00333"></a><a class="code" href="classbdm_1_1MPF.html#aada1bdb117bc78035fbb49765fa7ef10">00333</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> &opt ) { |
| 317 | <a name="l00334"></a>00334 <a class="code" href="classbdm_1_1MPF.html#aada1bdb117bc78035fbb49765fa7ef10">BM::set_options</a>(opt); |
| 318 | <a name="l00335"></a>00335 <a class="code" href="classbdm_1_1MPF.html#a9e2a4b7abf06feeeaaa56ad695e284ac" title="Log means of BMs.">opt_L_mea</a> = ( opt.find ( <span class="stringliteral">"logmeans"</span> ) != string::npos ); |
| 319 | <a name="l00336"></a>00336 } |
| 320 | <a name="l00337"></a>00337 |
| 321 | <a name="l00339"></a><a class="code" href="classbdm_1_1MPF.html#a71608a6986f57dcfb935e016b97c0637">00339</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 ) { |
| 322 | <a name="l00340"></a>00340 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1MPF.html#ad496b1378a6fd715ee64608b1dcb75ae" title="Array of Bayesian models.">BMs</a> ( i ); |
| 323 | <a name="l00341"></a>00341 } |
| 324 | <a name="l00342"></a>00342 |
| 325 | <a name="l00354"></a><a class="code" href="classbdm_1_1MPF.html#a9f74326b9ca3c888cb8eff1355ba3670">00354</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MPF.html#a9f74326b9ca3c888cb8eff1355ba3670">from_setting</a>(<span class="keyword">const</span> Setting &<span class="keyword">set</span>){ |
| 326 | <a name="l00355"></a>00355 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></a> par = UI::build<mpdf>(<span class="keyword">set</span>,<span class="stringliteral">"parameter_pdf"</span>,UI::compulsory); |
| 327 | <a name="l00356"></a>00356 <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<mpdf></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> |
| 328 | <a name="l00357"></a>00357 |
| 329 | <a name="l00358"></a>00358 <a class="code" href="classbdm_1_1MPF.html#a3bfa12c5566a0a38f30fec3a9eca1563" title="particle filter on non-linear variable">pf</a> = <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>; |
| 330 | <a name="l00359"></a>00359 <span class="comment">// rpior must be set before BM</span> |
| 331 | <a name="l00360"></a>00360 <a class="code" href="classbdm_1_1MPF.html#a3bfa12c5566a0a38f30fec3a9eca1563" title="particle filter on non-linear variable">pf</a>->prior_from_set(<span class="keyword">set</span>); |
| 332 | <a name="l00361"></a>00361 <a class="code" href="classbdm_1_1MPF.html#a3bfa12c5566a0a38f30fec3a9eca1563" title="particle filter on non-linear variable">pf</a>->resmethod_from_set(<span class="keyword">set</span>); |
| 333 | <a name="l00362"></a>00362 <a class="code" href="classbdm_1_1MPF.html#a3bfa12c5566a0a38f30fec3a9eca1563" title="particle filter on non-linear variable">pf</a>->set_model(par,obs); |
| 334 | <a name="l00363"></a>00363 |
| 335 | <a name="l00364"></a>00364 <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<BM></a> BM0 =UI::build<BM>(<span class="keyword">set</span>,<span class="stringliteral">"BM"</span>,UI::compulsory); |
| 336 | <a name="l00365"></a>00365 <a class="code" href="classbdm_1_1MPF.html#ac3ecf10c8f2e9114c7a57f122890aa9a" title="set a prototype of BM, copy it to as many times as there is particles in pf">set_BM</a>(*BM0); |
| 337 | <a name="l00366"></a>00366 |
| 338 | <a name="l00367"></a>00367 <span class="keywordtype">string</span> opt; |
| 339 | <a name="l00368"></a>00368 <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">"options"</span>,UI::optional)){ |
| 340 | <a name="l00369"></a>00369 <a class="code" href="classbdm_1_1MPF.html#aada1bdb117bc78035fbb49765fa7ef10">set_options</a>(opt); |
| 341 | <a name="l00370"></a>00370 } |
| 342 | <a name="l00371"></a>00371 <span class="comment">//set drv</span> |
| 343 | <a name="l00372"></a>00372 <span class="comment">//find potential input - what remains in rvc when we subtract rv</span> |
| 344 | <a name="l00373"></a>00373 <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> u = par->_rvc().remove_time().subt( par->_rv() ); |
| 345 | <a name="l00374"></a>00374 <a class="code" href="classbdm_1_1BM.html#af135ae6dce7e9f30c9f88229c7930b96" title="access function">set_drv</a>(concat(BM0->_drv(),u) ); |
| 346 | <a name="l00375"></a>00375 <a class="code" href="classbdm_1_1MPF.html#aa91b588de1b9690ca475c945d0f10f08" title="This method TODO.">validate</a>(); |