26 | | <a name="l00028"></a><a class="code" href="classPF.html">00028</a> <span class="keyword">class </span><a class="code" href="classPF.html" title="Trivial particle filter with proposal density equal to parameter evolution model...">PF</a> : <span class="keyword">public</span> <a class="code" href="classBM.html" title="Bayesian Model of the world, i.e. all uncertainty is modeled by probabilities.">BM</a> { |
27 | | <a name="l00029"></a>00029 <span class="keyword">protected</span>: |
28 | | <a name="l00031"></a><a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280">00031</a> <span class="keywordtype">int</span> <a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280" title="number of particles;">n</a>; |
29 | | <a name="l00033"></a><a class="code" href="classPF.html#1a0a09e309da997f63ae8e30d1e9806b">00033</a> <a class="code" href="classeEmp.html" title="Weighted empirical density.">eEmp</a> <a class="code" href="classPF.html#1a0a09e309da997f63ae8e30d1e9806b" title="posterior density">est</a>; |
30 | | <a name="l00035"></a><a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a">00035</a> vec &<a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a>; |
31 | | <a name="l00037"></a><a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5">00037</a> Array<vec> &<a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a>; |
32 | | <a name="l00039"></a><a class="code" href="classPF.html#d92ac103f88f8c21e197e90af5695a09">00039</a> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> &<a class="code" href="classPF.html#d92ac103f88f8c21e197e90af5695a09" title="Parameter evolution model.">par</a>; |
33 | | <a name="l00041"></a><a class="code" href="classPF.html#dd0a687a4515333d6809147335854e77">00041</a> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> &<a class="code" href="classPF.html#dd0a687a4515333d6809147335854e77" title="Observation model.">obs</a>; |
34 | | <a name="l00042"></a>00042 <span class="keyword">public</span>: |
35 | | <a name="l00044"></a><a class="code" href="classPF.html#e99f0d866721405dd281e315ecb690aa">00044</a> <a class="code" href="classPF.html#e99f0d866721405dd281e315ecb690aa" title="Default constructor.">PF</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rv0, <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> &par0, <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> &obs0, <span class="keywordtype">int</span> n0 ) :<a class="code" href="classBM.html" title="Bayesian Model of the world, i.e. all uncertainty is modeled by probabilities.">BM</a> ( rv0 ), |
36 | | <a name="l00045"></a>00045 <a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280" title="number of particles;">n</a> ( n0 ),<a class="code" href="classPF.html#1a0a09e309da997f63ae8e30d1e9806b" title="posterior density">est</a> ( rv0,<a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280" title="number of particles;">n</a> ),<a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a> ( <a class="code" href="classPF.html#1a0a09e309da997f63ae8e30d1e9806b" title="posterior density">est</a>.<a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a>() ),<a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a> ( <a class="code" href="classPF.html#1a0a09e309da997f63ae8e30d1e9806b" title="posterior density">est</a>.<a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a>() ), |
37 | | <a name="l00046"></a>00046 <a class="code" href="classPF.html#d92ac103f88f8c21e197e90af5695a09" title="Parameter evolution model.">par</a> ( par0 ), <a class="code" href="classPF.html#dd0a687a4515333d6809147335854e77" title="Observation model.">obs</a> ( obs0 ) {}; |
38 | | <a name="l00047"></a>00047 |
39 | | <a name="l00049"></a>00049 <span class="keywordtype">void</span> <a class="code" href="classPF.html#04d38fbcc0348b558212f530d9ec183e" title="Set posterior density by sampling from epdf0.">set_est</a> ( <span class="keyword">const</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> &epdf0 ); |
40 | | <a name="l00050"></a>00050 <span class="keywordtype">void</span> <a class="code" href="classPF.html#64f636bbd63bea9efd778214e6b631d3" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &dt ); |
41 | | <a name="l00051"></a>00051 }; |
42 | | <a name="l00052"></a>00052 |
43 | | <a name="l00059"></a>00059 <span class="keyword">template</span><<span class="keyword">class</span> BM_T> |
44 | | <a name="l00060"></a>00060 |
45 | | <a name="l00061"></a><a class="code" href="classMPF.html">00061</a> <span class="keyword">class </span><a class="code" href="classMPF.html" title="Marginalized Particle filter.">MPF</a> : <span class="keyword">public</span> <a class="code" href="classPF.html" title="Trivial particle filter with proposal density equal to parameter evolution model...">PF</a> { |
46 | | <a name="l00062"></a>00062 BM_T* Bms[1000]; |
| 26 | <a name="l00022"></a>00022 <span class="comment">//UGLY HACK</span> |
| 27 | <a name="l00023"></a>00023 <span class="keyword">extern</span> <span class="keywordtype">double</span> PF_SSAT;<span class="comment">//used for StrSim:06 test... if length>0 the value is written.</span> |
| 28 | <a name="l00024"></a>00024 |
| 29 | <a name="l00031"></a><a class="code" href="classPF.html">00031</a> <span class="keyword">class </span><a class="code" href="classPF.html" title="Trivial particle filter with proposal density equal to parameter evolution model...">PF</a> : <span class="keyword">public</span> <a class="code" href="classBM.html" title="Bayesian Model of the world, i.e. all uncertainty is modeled by probabilities.">BM</a> { |
| 30 | <a name="l00032"></a>00032 <span class="keyword">protected</span>: |
| 31 | <a name="l00034"></a><a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280">00034</a> <span class="keywordtype">int</span> <a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280" title="number of particles;">n</a>; |
| 32 | <a name="l00036"></a><a class="code" href="classPF.html#1a0a09e309da997f63ae8e30d1e9806b">00036</a> <a class="code" href="classeEmp.html" title="Weighted empirical density.">eEmp</a> <a class="code" href="classPF.html#1a0a09e309da997f63ae8e30d1e9806b" title="posterior density">est</a>; |
| 33 | <a name="l00038"></a><a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a">00038</a> vec &<a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a>; |
| 34 | <a name="l00040"></a><a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5">00040</a> Array<vec> &<a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a>; |
| 35 | <a name="l00042"></a><a class="code" href="classPF.html#d92ac103f88f8c21e197e90af5695a09">00042</a> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> &<a class="code" href="classPF.html#d92ac103f88f8c21e197e90af5695a09" title="Parameter evolution model.">par</a>; |
| 36 | <a name="l00044"></a><a class="code" href="classPF.html#dd0a687a4515333d6809147335854e77">00044</a> <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> &<a class="code" href="classPF.html#dd0a687a4515333d6809147335854e77" title="Observation model.">obs</a>; |
| 37 | <a name="l00045"></a>00045 <span class="keyword">public</span>: |
| 38 | <a name="l00047"></a><a class="code" href="classPF.html#e99f0d866721405dd281e315ecb690aa">00047</a> <a class="code" href="classPF.html#e99f0d866721405dd281e315ecb690aa" title="Default constructor.">PF</a> ( <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rv0, <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> &par0, <a class="code" href="classmpdf.html" title="Conditional probability density, e.g. modeling some dependencies.">mpdf</a> &obs0, <span class="keywordtype">int</span> n0 ) :<a class="code" href="classBM.html" title="Bayesian Model of the world, i.e. all uncertainty is modeled by probabilities.">BM</a> ( rv0 ), |
| 39 | <a name="l00048"></a>00048 <a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280" title="number of particles;">n</a> ( n0 ),<a class="code" href="classPF.html#1a0a09e309da997f63ae8e30d1e9806b" title="posterior density">est</a> ( rv0,<a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280" title="number of particles;">n</a> ),<a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a> ( <a class="code" href="classPF.html#1a0a09e309da997f63ae8e30d1e9806b" title="posterior density">est</a>.<a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a>() ),<a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a> ( <a class="code" href="classPF.html#1a0a09e309da997f63ae8e30d1e9806b" title="posterior density">est</a>.<a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a>() ), |
| 40 | <a name="l00049"></a>00049 <a class="code" href="classPF.html#d92ac103f88f8c21e197e90af5695a09" title="Parameter evolution model.">par</a> ( par0 ), <a class="code" href="classPF.html#dd0a687a4515333d6809147335854e77" title="Observation model.">obs</a> ( obs0 ) {}; |
| 41 | <a name="l00050"></a>00050 |
| 42 | <a name="l00052"></a>00052 <span class="keywordtype">void</span> <a class="code" href="classPF.html#04d38fbcc0348b558212f530d9ec183e" title="Set posterior density by sampling from epdf0.">set_est</a> ( <span class="keyword">const</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> &epdf0 ); |
| 43 | <a name="l00053"></a>00053 <span class="keywordtype">void</span> <a class="code" href="classPF.html#64f636bbd63bea9efd778214e6b631d3" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &dt ); |
| 44 | <a name="l00054"></a>00054 }; |
| 45 | <a name="l00055"></a>00055 |
| 46 | <a name="l00062"></a>00062 <span class="keyword">template</span><<span class="keyword">class</span> BM_T> |
48 | | <a name="l00065"></a>00065 |
49 | | <a name="l00066"></a>00066 <span class="keyword">class </span>mpfepdf : <span class="keyword">public</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { |
50 | | <a name="l00067"></a>00067 <span class="keyword">protected</span>: |
51 | | <a name="l00068"></a>00068 <a class="code" href="classeEmp.html" title="Weighted empirical density.">eEmp</a> &E; |
52 | | <a name="l00069"></a>00069 vec &<a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a>; |
53 | | <a name="l00070"></a>00070 Array<epdf*> Coms; |
54 | | <a name="l00071"></a>00071 <span class="keyword">public</span>: |
55 | | <a name="l00072"></a>00072 mpfepdf ( <a class="code" href="classeEmp.html" title="Weighted empirical density.">eEmp</a> &E0, <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rvc ) : |
56 | | <a name="l00073"></a>00073 <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a>( ) ), E ( E0 ), <a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a> ( E._w() ), |
57 | | <a name="l00074"></a>00074 Coms ( <a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a>.length() ) { |
58 | | <a name="l00075"></a>00075 <a class="code" href="classBM.html#af00f0612fabe66241dd507188cdbf88" title="Random variable of the posterior.">rv</a>.<a class="code" href="classRV.html#4fc941a5ebc9f82aa372f54f2e02dab2" title="Add (concat) another variable to the current one.">add</a> ( E._rv() ); |
59 | | <a name="l00076"></a>00076 <a class="code" href="classBM.html#af00f0612fabe66241dd507188cdbf88" title="Random variable of the posterior.">rv</a>.<a class="code" href="classRV.html#4fc941a5ebc9f82aa372f54f2e02dab2" title="Add (concat) another variable to the current one.">add</a> ( rvc ); |
60 | | <a name="l00077"></a>00077 }; |
61 | | <a name="l00078"></a>00078 |
62 | | <a name="l00079"></a>00079 <span class="keywordtype">void</span> set_elements ( <span class="keywordtype">int</span> &i, <span class="keywordtype">double</span> wi, <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>* ep ) |
63 | | <a name="l00080"></a>00080 {<a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a> ( i ) =wi; Coms ( i ) =ep;}; |
| 48 | <a name="l00064"></a><a class="code" href="classMPF.html">00064</a> <span class="keyword">class </span><a class="code" href="classMPF.html" title="Marginalized Particle filter.">MPF</a> : <span class="keyword">public</span> <a class="code" href="classPF.html" title="Trivial particle filter with proposal density equal to parameter evolution model...">PF</a> { |
| 49 | <a name="l00065"></a>00065 BM_T* Bms[10000]; |
| 50 | <a name="l00066"></a>00066 |
| 51 | <a name="l00068"></a>00068 |
| 52 | <a name="l00069"></a>00069 <span class="keyword">class </span>mpfepdf : <span class="keyword">public</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> { |
| 53 | <a name="l00070"></a>00070 <span class="keyword">protected</span>: |
| 54 | <a name="l00071"></a>00071 <a class="code" href="classeEmp.html" title="Weighted empirical density.">eEmp</a> &E; |
| 55 | <a name="l00072"></a>00072 vec &<a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a>; |
| 56 | <a name="l00073"></a>00073 Array<epdf*> Coms; |
| 57 | <a name="l00074"></a>00074 <span class="keyword">public</span>: |
| 58 | <a name="l00075"></a>00075 mpfepdf ( <a class="code" href="classeEmp.html" title="Weighted empirical density.">eEmp</a> &E0, <span class="keyword">const</span> <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a> &rvc ) : |
| 59 | <a name="l00076"></a>00076 <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a> ( <a class="code" href="classRV.html" title="Class representing variables, most often random variables.">RV</a>( ) ), E ( E0 ), <a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a> ( E._w() ), |
| 60 | <a name="l00077"></a>00077 Coms ( <a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a>.length() ) { |
| 61 | <a name="l00078"></a>00078 <a class="code" href="classBM.html#af00f0612fabe66241dd507188cdbf88" title="Random variable of the posterior.">rv</a>.<a class="code" href="classRV.html#4fc941a5ebc9f82aa372f54f2e02dab2" title="Add (concat) another variable to the current one.">add</a> ( E._rv() ); |
| 62 | <a name="l00079"></a>00079 <a class="code" href="classBM.html#af00f0612fabe66241dd507188cdbf88" title="Random variable of the posterior.">rv</a>.<a class="code" href="classRV.html#4fc941a5ebc9f82aa372f54f2e02dab2" title="Add (concat) another variable to the current one.">add</a> ( rvc ); |
| 63 | <a name="l00080"></a>00080 }; |
87 | | <a name="l00106"></a>00106 |
88 | | <a name="l00107"></a>00107 <span class="keywordflow">if</span> ( n>1000 ) it_error ( <span class="stringliteral">"increase 1000 here!"</span> ); |
89 | | <a name="l00108"></a>00108 |
90 | | <a name="l00109"></a>00109 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<n;i++ ) { |
91 | | <a name="l00110"></a>00110 Bms[i] = <span class="keyword">new</span> BM_T ( BMcond0 ); <span class="comment">//copy constructor</span> |
92 | | <a name="l00111"></a>00111 <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>& pom=Bms[i]->_epdf(); |
93 | | <a name="l00112"></a>00112 jest.set_elements ( i,1.0/n,&pom ); |
94 | | <a name="l00113"></a>00113 } |
95 | | <a name="l00114"></a>00114 }; |
96 | | <a name="l00115"></a>00115 |
97 | | <a name="l00116"></a>00116 ~<a class="code" href="classMPF.html" title="Marginalized Particle filter.">MPF</a>() { |
98 | | <a name="l00117"></a>00117 } |
| 87 | <a name="l00106"></a>00106 <span class="comment">//TODO test if rv and BMcond.rv are compatible.</span> |
| 88 | <a name="l00107"></a>00107 <a class="code" href="classBM.html#af00f0612fabe66241dd507188cdbf88" title="Random variable of the posterior.">rv</a>.<a class="code" href="classRV.html#4fc941a5ebc9f82aa372f54f2e02dab2" title="Add (concat) another variable to the current one.">add</a> ( rvlin ); |
| 89 | <a name="l00108"></a>00108 <span class="comment">//</span> |
| 90 | <a name="l00109"></a>00109 |
| 91 | <a name="l00110"></a>00110 <span class="keywordflow">if</span> ( n>10000 ) it_error ( <span class="stringliteral">"increase 10000 here!"</span> ); |
| 92 | <a name="l00111"></a>00111 |
| 93 | <a name="l00112"></a>00112 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<n;i++ ) { |
| 94 | <a name="l00113"></a>00113 Bms[i] = <span class="keyword">new</span> BM_T ( BMcond0 ); <span class="comment">//copy constructor</span> |
| 95 | <a name="l00114"></a>00114 <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>& pom=Bms[i]->_epdf(); |
| 96 | <a name="l00115"></a>00115 jest.set_elements ( i,1.0/n,&pom ); |
| 97 | <a name="l00116"></a>00116 } |
| 98 | <a name="l00117"></a>00117 }; |
100 | | <a name="l00119"></a>00119 <span class="keywordtype">void</span> <a class="code" href="classMPF.html#55daf8e4b6553dd9f47c692de7931623" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &dt ); |
101 | | <a name="l00120"></a><a class="code" href="classMPF.html#549e08268a46a250f21a33d06f19276a">00120</a> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>& <a class="code" href="classMPF.html#549e08268a46a250f21a33d06f19276a" title="Returns a pointer to the epdf representing posterior density on parameters. Use with...">_epdf</a>() {<span class="keywordflow">return</span> jest;} |
102 | | <a name="l00122"></a><a class="code" href="classMPF.html#7c66e1c1c0e45fc4ae765133cb3a1553">00122</a> <span class="keywordtype">void</span> <a class="code" href="classMPF.html#7c66e1c1c0e45fc4ae765133cb3a1553" title="Set postrior of rvc to samples from epdf0. Statistics of Bms are not re-computed!...">set_est</a> ( <span class="keyword">const</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>& epdf0 ) { |
103 | | <a name="l00123"></a>00123 <a class="code" href="classPF.html#04d38fbcc0348b558212f530d9ec183e" title="Set posterior density by sampling from epdf0.">PF::set_est</a> ( epdf0 ); <span class="comment">// sample params in condition</span> |
104 | | <a name="l00124"></a>00124 <span class="comment">// copy conditions to BMs</span> |
105 | | <a name="l00125"></a>00125 |
106 | | <a name="l00126"></a>00126 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280" title="number of particles;">n</a>;i++ ) {Bms[i]->condition ( <a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a> ( i ) );} |
107 | | <a name="l00127"></a>00127 } |
108 | | <a name="l00128"></a>00128 }; |
109 | | <a name="l00129"></a>00129 |
110 | | <a name="l00130"></a>00130 <span class="keyword">template</span><<span class="keyword">class</span> BM_T> |
111 | | <a name="l00131"></a><a class="code" href="classMPF.html#55daf8e4b6553dd9f47c692de7931623">00131</a> <span class="keywordtype">void</span> <a class="code" href="classMPF.html#55daf8e4b6553dd9f47c692de7931623" title="Incremental Bayes rule.">MPF<BM_T>::bayes</a> ( <span class="keyword">const</span> vec &dt ) { |
112 | | <a name="l00132"></a>00132 <span class="keywordtype">int</span> i; |
113 | | <a name="l00133"></a>00133 vec lls ( <a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280" title="number of particles;">n</a> ); |
114 | | <a name="l00134"></a>00134 ivec ind; |
115 | | <a name="l00135"></a>00135 <span class="keywordtype">double</span> mlls=-std::numeric_limits<double>::infinity(); |
116 | | <a name="l00136"></a>00136 |
117 | | <a name="l00137"></a>00137 <span class="keywordflow">for</span> ( i=0;i<<a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280" title="number of particles;">n</a>;i++ ) { |
118 | | <a name="l00138"></a>00138 <span class="comment">//generate new samples from paramater evolution model;</span> |
119 | | <a name="l00139"></a>00139 <a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a> ( i ) = <a class="code" href="classPF.html#d92ac103f88f8c21e197e90af5695a09" title="Parameter evolution model.">par</a>.<a class="code" href="classmpdf.html#b0193a350c97933ddf15b15a130da352" title="Returns the required moment of the epdf.">samplecond</a> ( <a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a> ( i ), lls ( i ) ); |
120 | | <a name="l00140"></a>00140 Bms[i]->condition ( <a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a> ( i ) ); |
121 | | <a name="l00141"></a>00141 Bms[i]->bayes ( dt ); |
122 | | <a name="l00142"></a>00142 lls ( i ) = Bms[i]->_ll(); <span class="comment">// lls above is also in proposal her must be lls(i) =, not +=!!</span> |
| 100 | <a name="l00119"></a>00119 ~<a class="code" href="classMPF.html" title="Marginalized Particle filter.">MPF</a>() { |
| 101 | <a name="l00120"></a>00120 } |
| 102 | <a name="l00121"></a>00121 |
| 103 | <a name="l00122"></a>00122 <span class="keywordtype">void</span> <a class="code" href="classMPF.html#55daf8e4b6553dd9f47c692de7931623" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &dt ); |
| 104 | <a name="l00123"></a><a class="code" href="classMPF.html#549e08268a46a250f21a33d06f19276a">00123</a> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>& <a class="code" href="classMPF.html#549e08268a46a250f21a33d06f19276a" title="Returns a pointer to the epdf representing posterior density on parameters. Use with...">_epdf</a>() {<span class="keywordflow">return</span> jest;} |
| 105 | <a name="l00125"></a><a class="code" href="classMPF.html#7c66e1c1c0e45fc4ae765133cb3a1553">00125</a> <span class="keywordtype">void</span> <a class="code" href="classMPF.html#7c66e1c1c0e45fc4ae765133cb3a1553" title="Set postrior of rvc to samples from epdf0. Statistics of Bms are not re-computed!...">set_est</a> ( <span class="keyword">const</span> <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>& epdf0 ) { |
| 106 | <a name="l00126"></a>00126 <a class="code" href="classPF.html#04d38fbcc0348b558212f530d9ec183e" title="Set posterior density by sampling from epdf0.">PF::set_est</a> ( epdf0 ); <span class="comment">// sample params in condition</span> |
| 107 | <a name="l00127"></a>00127 <span class="comment">// copy conditions to BMs</span> |
| 108 | <a name="l00128"></a>00128 |
| 109 | <a name="l00129"></a>00129 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i<<a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280" title="number of particles;">n</a>;i++ ) {Bms[i]->condition ( <a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a> ( i ) );} |
| 110 | <a name="l00130"></a>00130 } |
| 111 | <a name="l00131"></a>00131 |
| 112 | <a name="l00132"></a>00132 <span class="comment">//SimStr:</span> |
| 113 | <a name="l00133"></a>00133 <span class="keywordtype">double</span> SSAT; |
| 114 | <a name="l00134"></a>00134 }; |
| 115 | <a name="l00135"></a>00135 |
| 116 | <a name="l00136"></a>00136 <span class="keyword">template</span><<span class="keyword">class</span> BM_T> |
| 117 | <a name="l00137"></a><a class="code" href="classMPF.html#55daf8e4b6553dd9f47c692de7931623">00137</a> <span class="keywordtype">void</span> <a class="code" href="classMPF.html#55daf8e4b6553dd9f47c692de7931623" title="Incremental Bayes rule.">MPF<BM_T>::bayes</a> ( <span class="keyword">const</span> vec &dt ) { |
| 118 | <a name="l00138"></a>00138 <span class="keywordtype">int</span> i; |
| 119 | <a name="l00139"></a>00139 vec lls ( <a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280" title="number of particles;">n</a> ); |
| 120 | <a name="l00140"></a>00140 vec llsP ( <a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280" title="number of particles;">n</a> ); |
| 121 | <a name="l00141"></a>00141 ivec ind; |
| 122 | <a name="l00142"></a>00142 <span class="keywordtype">double</span> mlls=-std::numeric_limits<double>::infinity(); |
124 | | <a name="l00144"></a>00144 <span class="keywordflow">if</span> ( lls ( i ) >mlls ) mlls=lls ( i ); <span class="comment">//find maximum likelihood (for numerical stability)</span> |
125 | | <a name="l00145"></a>00145 } |
126 | | <a name="l00146"></a>00146 |
127 | | <a name="l00147"></a>00147 <span class="comment">// compute weights</span> |
128 | | <a name="l00148"></a>00148 <span class="keywordflow">for</span> ( i=0;i<n;i++ ) { |
129 | | <a name="l00149"></a>00149 <a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a> ( i ) *= exp ( lls ( i ) - mlls ); <span class="comment">// multiply w by likelihood</span> |
130 | | <a name="l00150"></a>00150 } |
131 | | <a name="l00151"></a>00151 |
132 | | <a name="l00152"></a>00152 <a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a> /=sum(<a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a>); <span class="comment">//?</span> |
133 | | <a name="l00153"></a>00153 |
134 | | <a name="l00154"></a>00154 <span class="keywordtype">double</span> eff = 1.0/( <a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a>*<a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a> ); |
135 | | <a name="l00155"></a>00155 <span class="keywordflow">if</span> ( eff < ( 0.1*n ) ) { |
136 | | <a name="l00156"></a>00156 ind = <a class="code" href="classPF.html#1a0a09e309da997f63ae8e30d1e9806b" title="posterior density">est</a>.<a class="code" href="classeEmp.html#77268292fc4465cb73ddbfb1f2932a59" title="Function performs resampling, i.e. removal of low-weight samples and duplication...">resample</a>(); |
137 | | <a name="l00157"></a>00157 <span class="comment">// Resample Bms!</span> |
138 | | <a name="l00158"></a>00158 |
139 | | <a name="l00159"></a>00159 <span class="keywordflow">for</span> ( i=0;i<n;i++ ) { |
140 | | <a name="l00160"></a>00160 <span class="keywordflow">if</span> ( ind ( i ) !=i ) {<span class="comment">//replace the current Bm by a new one</span> |
141 | | <a name="l00161"></a>00161 <span class="comment">//fixme this would require new assignment operator</span> |
142 | | <a name="l00162"></a>00162 <span class="comment">// *Bms[i] = *Bms[ind ( i ) ];</span> |
143 | | <a name="l00163"></a>00163 |
144 | | <a name="l00164"></a>00164 <span class="comment">// poor-man's solution: replicate constructor here</span> |
145 | | <a name="l00165"></a>00165 <span class="comment">// copied from MPF::MPF</span> |
146 | | <a name="l00166"></a>00166 <span class="keyword">delete</span> Bms[i]; |
147 | | <a name="l00167"></a>00167 Bms[i] = <span class="keyword">new</span> BM_T ( *Bms[ind ( i ) ] ); <span class="comment">//copy constructor</span> |
148 | | <a name="l00168"></a>00168 <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>& pom=Bms[i]->_epdf(); |
149 | | <a name="l00169"></a>00169 jest.set_elements ( i,1.0/n,&pom ); |
150 | | <a name="l00170"></a>00170 } |
151 | | <a name="l00171"></a>00171 }; |
152 | | <a name="l00172"></a>00172 cout << <span class="charliteral">'.'</span>; |
153 | | <a name="l00173"></a>00173 } |
154 | | <a name="l00174"></a>00174 } |
155 | | <a name="l00175"></a>00175 |
156 | | <a name="l00176"></a>00176 <span class="preprocessor">#endif // KF_H</span> |
157 | | <a name="l00177"></a>00177 <span class="preprocessor"></span> |
158 | | <a name="l00178"></a>00178 |
159 | | </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Wed Mar 12 16:15:44 2008 for mixpp by |
| 124 | <a name="l00144"></a>00144 <span class="comment">// StrSim:06</span> |
| 125 | <a name="l00145"></a>00145 <span class="keywordtype">double</span> sumLWL=0.0; |
| 126 | <a name="l00146"></a>00146 <span class="keywordtype">double</span> sumL2WL=0.0; |
| 127 | <a name="l00147"></a>00147 <span class="keywordtype">double</span> WL = 0.0; |
| 128 | <a name="l00148"></a>00148 |
| 129 | <a name="l00149"></a>00149 <span class="keywordflow">for</span> ( i=0;i<<a class="code" href="classPF.html#2c2f44ed7a4eaa42e07bdb58d503f280" title="number of particles;">n</a>;i++ ) { |
| 130 | <a name="l00150"></a>00150 <span class="comment">//generate new samples from paramater evolution model;</span> |
| 131 | <a name="l00151"></a>00151 <a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a> ( i ) = <a class="code" href="classPF.html#d92ac103f88f8c21e197e90af5695a09" title="Parameter evolution model.">par</a>.<a class="code" href="classmpdf.html#b0193a350c97933ddf15b15a130da352" title="Returns the required moment of the epdf.">samplecond</a> ( <a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a> ( i ), llsP ( i ) ); |
| 132 | <a name="l00152"></a>00152 Bms[i]->condition ( <a class="code" href="classPF.html#cf7dad75e31215780a746c30e71ad9c5" title="pointer into eEmp ">_samples</a> ( i ) ); |
| 133 | <a name="l00153"></a>00153 Bms[i]->bayes ( dt ); |
| 134 | <a name="l00154"></a>00154 lls ( i ) = Bms[i]->_ll(); <span class="comment">// lls above is also in proposal her must be lls(i) =, not +=!!</span> |
| 135 | <a name="l00155"></a>00155 |
| 136 | <a name="l00156"></a>00156 <span class="keywordflow">if</span> ( lls ( i ) >mlls ) mlls=lls ( i ); <span class="comment">//find maximum likelihood (for numerical stability)</span> |
| 137 | <a name="l00157"></a>00157 } |
| 138 | <a name="l00158"></a>00158 |
| 139 | <a name="l00159"></a>00159 <span class="keywordflow">if</span> ( <span class="keyword">true</span> ) { |
| 140 | <a name="l00160"></a>00160 <span class="keywordflow">for</span> ( i=0;i<n;i++ ) { |
| 141 | <a name="l00161"></a>00161 WL = <a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a> ( i ) *exp ( llsP ( i ) ); <span class="comment">//using old weights!</span> |
| 142 | <a name="l00162"></a>00162 sumLWL += exp ( lls ( i ) ) *WL; |
| 143 | <a name="l00163"></a>00163 sumL2WL += exp ( 2*lls ( i ) ) *WL; |
| 144 | <a name="l00164"></a>00164 } |
| 145 | <a name="l00165"></a>00165 SSAT = sumL2WL/(sumLWL*sumLWL); |
| 146 | <a name="l00166"></a>00166 } |
| 147 | <a name="l00167"></a>00167 |
| 148 | <a name="l00168"></a>00168 <span class="comment">// compute weights</span> |
| 149 | <a name="l00169"></a>00169 <span class="keywordflow">for</span> ( i=0;i<n;i++ ) { |
| 150 | <a name="l00170"></a>00170 <a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a> ( i ) *= exp ( lls ( i ) - mlls ); <span class="comment">// multiply w by likelihood</span> |
| 151 | <a name="l00171"></a>00171 } |
| 152 | <a name="l00172"></a>00172 |
| 153 | <a name="l00173"></a>00173 <span class="keywordflow">if</span> (sum(<a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a>)>0.0){ |
| 154 | <a name="l00174"></a>00174 <a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a> /=sum ( <a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a> ); <span class="comment">//?</span> |
| 155 | <a name="l00175"></a>00175 } |
| 156 | <a name="l00176"></a>00176 <span class="keywordflow">else</span> |
| 157 | <a name="l00177"></a>00177 { |
| 158 | <a name="l00178"></a>00178 cout<<<span class="stringliteral">"sum(w)==0"</span><<endl; |
| 159 | <a name="l00179"></a>00179 } |
| 160 | <a name="l00180"></a>00180 |
| 161 | <a name="l00181"></a>00181 |
| 162 | <a name="l00182"></a>00182 <span class="keywordtype">double</span> eff = 1.0/ ( <a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a>*<a class="code" href="classPF.html#5c87aba508df321ff26536ced64dbb3a" title="pointer into eEmp ">_w</a> ); |
| 163 | <a name="l00183"></a>00183 <span class="keywordflow">if</span> ( eff < ( 0.3*n ) ) { |
| 164 | <a name="l00184"></a>00184 ind = <a class="code" href="classPF.html#1a0a09e309da997f63ae8e30d1e9806b" title="posterior density">est</a>.<a class="code" href="classeEmp.html#77268292fc4465cb73ddbfb1f2932a59" title="Function performs resampling, i.e. removal of low-weight samples and duplication...">resample</a>(); |
| 165 | <a name="l00185"></a>00185 <span class="comment">// Resample Bms!</span> |
| 166 | <a name="l00186"></a>00186 |
| 167 | <a name="l00187"></a>00187 <span class="keywordflow">for</span> ( i=0;i<n;i++ ) { |
| 168 | <a name="l00188"></a>00188 <span class="keywordflow">if</span> ( ind ( i ) !=i ) {<span class="comment">//replace the current Bm by a new one</span> |
| 169 | <a name="l00189"></a>00189 <span class="comment">//fixme this would require new assignment operator</span> |
| 170 | <a name="l00190"></a>00190 <span class="comment">// *Bms[i] = *Bms[ind ( i ) ];</span> |
| 171 | <a name="l00191"></a>00191 |
| 172 | <a name="l00192"></a>00192 <span class="comment">// poor-man's solution: replicate constructor here</span> |
| 173 | <a name="l00193"></a>00193 <span class="comment">// copied from MPF::MPF</span> |
| 174 | <a name="l00194"></a>00194 <span class="keyword">delete</span> Bms[i]; |
| 175 | <a name="l00195"></a>00195 Bms[i] = <span class="keyword">new</span> BM_T ( *Bms[ind ( i ) ] ); <span class="comment">//copy constructor</span> |
| 176 | <a name="l00196"></a>00196 <a class="code" href="classepdf.html" title="Probability density function with numerical statistics, e.g. posterior density.">epdf</a>& pom=Bms[i]->_epdf(); |
| 177 | <a name="l00197"></a>00197 jest.set_elements ( i,1.0/n,&pom ); |
| 178 | <a name="l00198"></a>00198 } |
| 179 | <a name="l00199"></a>00199 }; |
| 180 | <a name="l00200"></a>00200 cout << <span class="charliteral">'.'</span>; |
| 181 | <a name="l00201"></a>00201 } |
| 182 | <a name="l00202"></a>00202 } |
| 183 | <a name="l00203"></a>00203 |
| 184 | <a name="l00204"></a>00204 <span class="preprocessor">#endif // KF_H</span> |
| 185 | <a name="l00205"></a>00205 <span class="preprocessor"></span> |
| 186 | <a name="l00206"></a>00206 |
| 187 | </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Fri Apr 18 11:15:14 2008 for mixpp by |