74 | | <a name="l00022"></a>00022 <span class="keyword">namespace </span>bdm { |
75 | | <a name="l00023"></a>00023 |
76 | | <a name="l00028"></a><a class="code" href="classbdm_1_1KalmanFull.html">00028</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1KalmanFull.html" title="Basic Kalman filter with full matrices (education purpose only)! Will be deleted...">KalmanFull</a> { |
77 | | <a name="l00029"></a>00029 <span class="keyword">protected</span>: |
78 | | <a name="l00030"></a>00030 <span class="keywordtype">int</span> dimx, dimy, dimu; |
79 | | <a name="l00031"></a>00031 mat A, B, C, D, R, Q; |
80 | | <a name="l00032"></a>00032 |
81 | | <a name="l00033"></a>00033 <span class="comment">//cache</span> |
82 | | <a name="l00034"></a>00034 mat _Pp, _Ry, _iRy, _K; |
83 | | <a name="l00035"></a>00035 <span class="keyword">public</span>: |
84 | | <a name="l00036"></a>00036 <span class="comment">//posterior</span> |
85 | | <a name="l00038"></a><a class="code" href="classbdm_1_1KalmanFull.html#2defb75e58892615c5f95fd844f3a666">00038</a> <span class="comment"></span> vec <a class="code" href="classbdm_1_1KalmanFull.html#2defb75e58892615c5f95fd844f3a666" title="Mean value of the posterior density.">mu</a>; |
86 | | <a name="l00040"></a><a class="code" href="classbdm_1_1KalmanFull.html#acacd228e100c3e937de575ad2d7cd9c">00040</a> mat <a class="code" href="classbdm_1_1KalmanFull.html#acacd228e100c3e937de575ad2d7cd9c" title="Variance of the posterior density.">P</a>; |
87 | | <a name="l00041"></a>00041 |
88 | | <a name="l00042"></a>00042 <span class="keywordtype">bool</span> evalll; |
89 | | <a name="l00043"></a>00043 <span class="keywordtype">double</span> ll; |
90 | | <a name="l00044"></a>00044 <span class="keyword">public</span>: |
91 | | <a name="l00046"></a>00046 <a class="code" href="classbdm_1_1KalmanFull.html#bdcc98c8b18c1cbdebdf218ae838fd11" title="For EKFfull;.">KalmanFull</a> ( mat A, mat B, mat C, mat D, mat R, mat Q, mat P0, vec mu0 ); |
92 | | <a name="l00048"></a>00048 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1KalmanFull.html#081924bc97f453f674bb982b7951d053" title="Here dt = [yt;ut] of appropriate dimensions.">bayes</a> ( <span class="keyword">const</span> vec &dt ); |
93 | | <a name="l00050"></a>00050 <span class="keyword">friend</span> std::ostream &<a class="code" href="classbdm_1_1KalmanFull.html#86ba216243ed95bb46d80d88775d16af" title="print elements of KF">operator<< </a>( std::ostream &os, <span class="keyword">const</span> <a class="code" href="classbdm_1_1KalmanFull.html" title="Basic Kalman filter with full matrices (education purpose only)! Will be deleted...">KalmanFull</a> &kf ); |
94 | | <a name="l00052"></a><a class="code" href="classbdm_1_1KalmanFull.html#bdcc98c8b18c1cbdebdf218ae838fd11">00052</a> <a class="code" href="classbdm_1_1KalmanFull.html#bdcc98c8b18c1cbdebdf218ae838fd11" title="For EKFfull;.">KalmanFull</a>() {}; |
95 | | <a name="l00053"></a>00053 }; |
96 | | <a name="l00054"></a>00054 |
97 | | <a name="l00055"></a>00055 |
98 | | <a name="l00063"></a>00063 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
99 | | <a name="l00064"></a>00064 |
100 | | <a name="l00065"></a><a class="code" href="classbdm_1_1Kalman.html">00065</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1Kalman.html" title="Kalman filter with covariance matrices in square root form.">Kalman</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> { |
101 | | <a name="l00066"></a>00066 <span class="keyword">protected</span>: |
102 | | <a name="l00068"></a><a class="code" href="classbdm_1_1Kalman.html#3fe475a1e920b20b63bb342c0e1571f7">00068</a> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> <a class="code" href="classbdm_1_1Kalman.html#3fe475a1e920b20b63bb342c0e1571f7" title="Indetifier of output rv.">rvy</a>; |
103 | | <a name="l00070"></a><a class="code" href="classbdm_1_1Kalman.html#149e27424fd1a7cc1c998ea088618a94">00070</a> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> <a class="code" href="classbdm_1_1Kalman.html#149e27424fd1a7cc1c998ea088618a94" title="Indetifier of exogeneous rv.">rvu</a>; |
104 | | <a name="l00072"></a><a class="code" href="classbdm_1_1Kalman.html#ba7699cdb3b1382a54d3e28b9b7517fa">00072</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1Kalman.html#ba7699cdb3b1382a54d3e28b9b7517fa" title="cache of rv.count()">dimx</a>; |
105 | | <a name="l00074"></a><a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f">00074</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a>; |
106 | | <a name="l00076"></a><a class="code" href="classbdm_1_1Kalman.html#c5136ef617f6ac0e426bea222755d92b">00076</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1Kalman.html#c5136ef617f6ac0e426bea222755d92b" title="cache of rvu.count()">dimu</a>; |
107 | | <a name="l00078"></a><a class="code" href="classbdm_1_1Kalman.html#0a2072e2090c10fac74ad30a023a4ace">00078</a> mat <a class="code" href="classbdm_1_1Kalman.html#0a2072e2090c10fac74ad30a023a4ace" title="Matrix A.">A</a>; |
108 | | <a name="l00080"></a><a class="code" href="classbdm_1_1Kalman.html#5977b2c81857948a35105f0e7840203c">00080</a> mat <a class="code" href="classbdm_1_1Kalman.html#5977b2c81857948a35105f0e7840203c" title="Matrix B.">B</a>; |
109 | | <a name="l00082"></a><a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177">00082</a> mat <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a>; |
110 | | <a name="l00084"></a><a class="code" href="classbdm_1_1Kalman.html#7b56ac423d0654b5755e4f852a870456">00084</a> mat <a class="code" href="classbdm_1_1Kalman.html#7b56ac423d0654b5755e4f852a870456" title="Matrix D.">D</a>; |
111 | | <a name="l00086"></a><a class="code" href="classbdm_1_1Kalman.html#70f8bf19e81b532c60fd3a7a152425ee">00086</a> sq_T <a class="code" href="classbdm_1_1Kalman.html#70f8bf19e81b532c60fd3a7a152425ee" title="Matrix Q in square-root form.">Q</a>; |
112 | | <a name="l00088"></a><a class="code" href="classbdm_1_1Kalman.html#475b088287cdfbba4dc60a3d027728b7">00088</a> sq_T <a class="code" href="classbdm_1_1Kalman.html#475b088287cdfbba4dc60a3d027728b7" title="Matrix R in square-root form.">R</a>; |
113 | | <a name="l00089"></a>00089 |
114 | | <a name="l00091"></a><a class="code" href="classbdm_1_1Kalman.html#383f329ff18bbe219254c8b3b916f40d">00091</a> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a> <a class="code" href="classbdm_1_1Kalman.html#383f329ff18bbe219254c8b3b916f40d" title="posterior density on $x_t$">est</a>; |
115 | | <a name="l00093"></a><a class="code" href="classbdm_1_1Kalman.html#ba555c394c429f6831c9bbabfa2c944c">00093</a> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a> <a class="code" href="classbdm_1_1Kalman.html#ba555c394c429f6831c9bbabfa2c944c" title="preditive density on $y_t$">fy</a>; |
116 | | <a name="l00094"></a>00094 |
117 | | <a name="l00096"></a><a class="code" href="classbdm_1_1Kalman.html#bd69dfb802465f22dd84d73a180d5c92">00096</a> mat <a class="code" href="classbdm_1_1Kalman.html#bd69dfb802465f22dd84d73a180d5c92" title="placeholder for Kalman gain">_K</a>; |
118 | | <a name="l00098"></a><a class="code" href="classbdm_1_1Kalman.html#c249d45258c8578b13858ad3e7b729b1">00098</a> vec& <a class="code" href="classbdm_1_1Kalman.html#c249d45258c8578b13858ad3e7b729b1" title="cache of fy.mu">_yp</a>; |
119 | | <a name="l00100"></a><a class="code" href="classbdm_1_1Kalman.html#2dd268f2d7fbe6382cb8825a1114192a">00100</a> sq_T& <a class="code" href="classbdm_1_1Kalman.html#2dd268f2d7fbe6382cb8825a1114192a" title="cache of fy.R">_Ry</a>; |
120 | | <a name="l00102"></a><a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0">00102</a> vec& <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a>; |
121 | | <a name="l00104"></a><a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed">00104</a> sq_T& <a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed" title="cache of est.R">_P</a>; |
122 | | <a name="l00105"></a>00105 |
123 | | <a name="l00106"></a>00106 <span class="keyword">public</span>: |
124 | | <a name="l00108"></a>00108 <a class="code" href="classbdm_1_1Kalman.html#025a0196cbcc2e6adb13311f9d3d52b4" title="Default constructor.">Kalman</a> ( ); |
125 | | <a name="l00110"></a>00110 <a class="code" href="classbdm_1_1Kalman.html#025a0196cbcc2e6adb13311f9d3d52b4" title="Default constructor.">Kalman</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1Kalman.html" title="Kalman filter with covariance matrices in square root form.">Kalman<sq_T></a> &K0 ); |
126 | | <a name="l00112"></a>00112 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1Kalman.html#3c7fb87fb6b87d08deb6a5a7862da957" title="Set parameters with check of relevance.">set_parameters</a> ( <span class="keyword">const</span> mat &A0, <span class="keyword">const</span> mat &B0, <span class="keyword">const</span> mat &C0, <span class="keyword">const</span> mat &D0, <span class="keyword">const</span> sq_T &Q0, <span class="keyword">const</span> sq_T &R0 ); |
127 | | <a name="l00114"></a><a class="code" href="classbdm_1_1Kalman.html#9264fc6b173ecb803d2684b883f32c68">00114</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1Kalman.html#9264fc6b173ecb803d2684b883f32c68" title="Set estimate values, used e.g. in initialization.">set_est</a> ( <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &P0 ) { |
128 | | <a name="l00115"></a>00115 sq_T pom ( <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> ); |
129 | | <a name="l00116"></a>00116 <a class="code" href="classbdm_1_1Kalman.html#383f329ff18bbe219254c8b3b916f40d" title="posterior density on $x_t$">est</a>.set_parameters ( mu0, P0 ); |
130 | | <a name="l00117"></a>00117 P0.mult_sym ( <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a>, pom ); |
131 | | <a name="l00118"></a>00118 <a class="code" href="classbdm_1_1Kalman.html#ba555c394c429f6831c9bbabfa2c944c" title="preditive density on $y_t$">fy</a>.set_parameters ( <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a>*mu0, pom ); |
132 | | <a name="l00119"></a>00119 }; |
133 | | <a name="l00120"></a>00120 |
134 | | <a name="l00122"></a>00122 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1Kalman.html#4a39330c14eff8d13179e868a1d1aa8c" title="Here dt = [yt;ut] of appropriate dimensions.">bayes</a> ( <span class="keyword">const</span> vec &dt ); |
135 | | <a name="l00124"></a><a class="code" href="classbdm_1_1Kalman.html#f75e487ff6c129d7012d702030f8c890">00124</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_1Kalman.html#f75e487ff6c129d7012d702030f8c890" title="access function">posterior</a>()<span class="keyword"> const </span>{ |
136 | | <a name="l00125"></a>00125 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1Kalman.html#383f329ff18bbe219254c8b3b916f40d" title="posterior density on $x_t$">est</a>; |
137 | | <a name="l00126"></a>00126 } |
138 | | <a name="l00128"></a><a class="code" href="classbdm_1_1Kalman.html#c788ec6e6c6f5f5861ae8a56d8ede277">00128</a> mat& <a class="code" href="classbdm_1_1Kalman.html#c788ec6e6c6f5f5861ae8a56d8ede277" title="access function">__K</a>() { |
139 | | <a name="l00129"></a>00129 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1Kalman.html#bd69dfb802465f22dd84d73a180d5c92" title="placeholder for Kalman gain">_K</a>; |
140 | | <a name="l00130"></a>00130 } |
141 | | <a name="l00132"></a><a class="code" href="classbdm_1_1Kalman.html#a250d1dbe7bba861dba2a324520cfa48">00132</a> vec <a class="code" href="classbdm_1_1Kalman.html#a250d1dbe7bba861dba2a324520cfa48" title="access function">_dP</a>() { |
142 | | <a name="l00133"></a>00133 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed" title="cache of est.R">_P</a>->getD(); |
143 | | <a name="l00134"></a>00134 } |
144 | | <a name="l00135"></a>00135 }; |
145 | | <a name="l00136"></a>00136 |
146 | | <a name="l00143"></a><a class="code" href="classbdm_1_1KalmanCh.html">00143</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1KalmanCh.html" title="Kalman filter in square root form.">KalmanCh</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1Kalman.html" title="Kalman filter with covariance matrices in square root form.">Kalman</a><chmat> { |
147 | | <a name="l00144"></a>00144 <span class="keyword">protected</span>: |
148 | | <a name="l00146"></a><a class="code" href="classbdm_1_1KalmanCh.html#48611c8582706cfa62e832be0972e75d">00146</a> mat <a class="code" href="classbdm_1_1KalmanCh.html#48611c8582706cfa62e832be0972e75d" title="pre array (triangular matrix)">preA</a>; |
149 | | <a name="l00148"></a><a class="code" href="classbdm_1_1KalmanCh.html#bcbd68f51d4b57246e7784ca5900171f">00148</a> mat <a class="code" href="classbdm_1_1KalmanCh.html#bcbd68f51d4b57246e7784ca5900171f" title="post array (triangular matrix)">postA</a>; |
150 | | <a name="l00149"></a>00149 |
151 | | <a name="l00150"></a>00150 <span class="keyword">public</span>: |
152 | | <a name="l00152"></a><a class="code" href="classbdm_1_1KalmanCh.html#24ce65bdaa538d4d5153d709a929b996">00152</a> <a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a>* <a class="code" href="classbdm_1_1KalmanCh.html#24ce65bdaa538d4d5153d709a929b996" title="copy constructor">_copy_</a>()<span class="keyword"> const </span>{ |
153 | | <a name="l00153"></a>00153 <a class="code" href="classbdm_1_1KalmanCh.html" title="Kalman filter in square root form.">KalmanCh</a>* K = <span class="keyword">new</span> <a class="code" href="classbdm_1_1KalmanCh.html" title="Kalman filter in square root form.">KalmanCh</a>; |
154 | | <a name="l00154"></a>00154 K-><a class="code" href="classbdm_1_1KalmanCh.html#20a4d4c664e8ac8a3f1bb7b0d11c6d87" title="Set parameters with check of relevance.">set_parameters</a> ( <a class="code" href="classbdm_1_1Kalman.html#0a2072e2090c10fac74ad30a023a4ace" title="Matrix A.">A</a>, <a class="code" href="classbdm_1_1Kalman.html#5977b2c81857948a35105f0e7840203c" title="Matrix B.">B</a>, <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a>, <a class="code" href="classbdm_1_1Kalman.html#7b56ac423d0654b5755e4f852a870456" title="Matrix D.">D</a>, <a class="code" href="classbdm_1_1Kalman.html#70f8bf19e81b532c60fd3a7a152425ee" title="Matrix Q in square-root form.">Q</a>, <a class="code" href="classbdm_1_1Kalman.html#475b088287cdfbba4dc60a3d027728b7" title="Matrix R in square-root form.">R</a> ); |
155 | | <a name="l00155"></a>00155 K-><a class="code" href="classbdm_1_1KalmanCh.html#6e169272657ed101f3d128b49c59b890">set_statistics</a> ( <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a>, <a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed" title="cache of est.R">_P</a> ); |
156 | | <a name="l00156"></a>00156 <span class="keywordflow">return</span> K; |
157 | | <a name="l00157"></a>00157 } |
158 | | <a name="l00159"></a>00159 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1KalmanCh.html#20a4d4c664e8ac8a3f1bb7b0d11c6d87" title="Set parameters with check of relevance.">set_parameters</a> ( <span class="keyword">const</span> mat &A0, <span class="keyword">const</span> mat &B0, <span class="keyword">const</span> mat &C0, <span class="keyword">const</span> mat &D0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> &Q0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> &R0 ); |
159 | | <a name="l00160"></a>00160 <span class="keywordtype">void</span> set_statistics ( <span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> &P0 ) { |
160 | | <a name="l00161"></a>00161 <a class="code" href="classbdm_1_1Kalman.html#383f329ff18bbe219254c8b3b916f40d" title="posterior density on $x_t$">est</a>.<a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> ( mu0, P0 ); |
161 | | <a name="l00162"></a>00162 }; |
162 | | <a name="l00163"></a>00163 |
163 | | <a name="l00164"></a>00164 |
164 | | <a name="l00178"></a>00178 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1KalmanCh.html#b41fe5540548100b08e1684c3be767b6" title="Here dt = [yt;ut] of appropriate dimensions.">bayes</a> ( <span class="keyword">const</span> vec &dt ); |
165 | | <a name="l00179"></a>00179 }; |
166 | | <a name="l00180"></a>00180 |
167 | | <a name="l00186"></a><a class="code" href="classbdm_1_1EKFfull.html">00186</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1EKFfull.html" title="Extended Kalman Filter in full matrices.">EKFfull</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1KalmanFull.html" title="Basic Kalman filter with full matrices (education purpose only)! Will be deleted...">KalmanFull</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> { |
168 | | <a name="l00187"></a>00187 <span class="keyword">protected</span>: |
169 | | <a name="l00189"></a><a class="code" href="classbdm_1_1EKFfull.html#ee5bfb3f09dfa994596c5bc68306f7d6">00189</a> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<diffbifn></a> <a class="code" href="classbdm_1_1EKFfull.html#ee5bfb3f09dfa994596c5bc68306f7d6" title="Internal Model f(x,u).">pfxu</a>; |
170 | | <a name="l00190"></a>00190 |
171 | | <a name="l00192"></a><a class="code" href="classbdm_1_1EKFfull.html#6432c675b1a9b83898b4ff19eab9b45c">00192</a> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<diffbifn></a> <a class="code" href="classbdm_1_1EKFfull.html#6432c675b1a9b83898b4ff19eab9b45c" title="Observation Model h(x,u).">phxu</a>; |
172 | | <a name="l00193"></a>00193 |
173 | | <a name="l00194"></a>00194 <a class="code" href="classbdm_1_1enorm.html">enorm<fsqmat></a> E; |
174 | | <a name="l00195"></a>00195 <span class="keyword">public</span>: |
175 | | <a name="l00197"></a>00197 <a class="code" href="classbdm_1_1EKFfull.html#6939c345389abb8b2481457b4cfe1165" title="Default constructor.">EKFfull</a> ( ); |
176 | | <a name="l00198"></a>00198 |
177 | | <a name="l00200"></a>00200 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1EKFfull.html#8a68f95124a4b01f9ce23225f3c736a4" title="Set nonlinear functions for mean values and covariance matrices.">set_parameters</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<diffbifn></a> &<a class="code" href="classbdm_1_1EKFfull.html#ee5bfb3f09dfa994596c5bc68306f7d6" title="Internal Model f(x,u).">pfxu</a>, <span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<diffbifn></a> &<a class="code" href="classbdm_1_1EKFfull.html#6432c675b1a9b83898b4ff19eab9b45c" title="Observation Model h(x,u).">phxu</a>, <span class="keyword">const</span> mat Q0, <span class="keyword">const</span> mat R0 ); |
178 | | <a name="l00201"></a>00201 |
179 | | <a name="l00203"></a>00203 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1EKFfull.html#f149ae8e9ce14d9931a7bb2850736699" title="Here dt = [yt;ut] of appropriate dimensions.">bayes</a> ( <span class="keyword">const</span> vec &dt ); |
180 | | <a name="l00205"></a><a class="code" href="classbdm_1_1EKFfull.html#1949a9b1496a855cc7c24e619bc52365">00205</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1EKFfull.html#1949a9b1496a855cc7c24e619bc52365" title="set estimates">set_statistics</a> ( vec mu0, mat P0 ) { |
181 | | <a name="l00206"></a>00206 <a class="code" href="classbdm_1_1KalmanFull.html#2defb75e58892615c5f95fd844f3a666" title="Mean value of the posterior density.">mu</a> = mu0; |
182 | | <a name="l00207"></a>00207 <a class="code" href="classbdm_1_1KalmanFull.html#acacd228e100c3e937de575ad2d7cd9c" title="Variance of the posterior density.">P</a> = P0; |
183 | | <a name="l00208"></a>00208 }; |
184 | | <a name="l00210"></a><a class="code" href="classbdm_1_1EKFfull.html#7e9a69f36a0a0615c9abb806772ef36d">00210</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_1EKFfull.html#7e9a69f36a0a0615c9abb806772ef36d" title="dummy!">posterior</a>()<span class="keyword"> const </span>{ |
185 | | <a name="l00211"></a>00211 <span class="keywordflow">return</span> E; |
186 | | <a name="l00212"></a>00212 }; |
187 | | <a name="l00213"></a>00213 <span class="keyword">const</span> mat _R() { |
188 | | <a name="l00214"></a>00214 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1KalmanFull.html#acacd228e100c3e937de575ad2d7cd9c" title="Variance of the posterior density.">P</a>; |
189 | | <a name="l00215"></a>00215 } |
190 | | <a name="l00216"></a>00216 }; |
191 | | <a name="l00217"></a>00217 |
192 | | <a name="l00223"></a>00223 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
193 | | <a name="l00224"></a><a class="code" href="classbdm_1_1EKF.html">00224</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1EKF.html" title="Extended Kalman Filter.">EKF</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1Kalman.html" title="Kalman filter with covariance matrices in square root form.">Kalman</a><fsqmat> { |
194 | | <a name="l00226"></a>00226 <a class="code" href="classbdm_1_1diffbifn.html" title="Class representing a differentiable function of two variables .">diffbifn</a>* pfxu; |
195 | | <a name="l00228"></a>00228 <a class="code" href="classbdm_1_1diffbifn.html" title="Class representing a differentiable function of two variables .">diffbifn</a>* phxu; |
196 | | <a name="l00229"></a>00229 <span class="keyword">public</span>: |
197 | | <a name="l00231"></a>00231 <a class="code" href="classbdm_1_1EKF.html#d087a8bb408d26ac4f5c542746b81059" title="Default constructor.">EKF</a> ( <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rvx, <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> <a class="code" href="classbdm_1_1Kalman.html#3fe475a1e920b20b63bb342c0e1571f7" title="Indetifier of output rv.">rvy</a>, <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> <a class="code" href="classbdm_1_1Kalman.html#149e27424fd1a7cc1c998ea088618a94" title="Indetifier of exogeneous rv.">rvu</a> ); |
198 | | <a name="l00233"></a><a class="code" href="classbdm_1_1EKF.html#fe9b2e227255ad32dc73df316b7318f4">00233</a> <a class="code" href="classbdm_1_1EKF.html" title="Extended Kalman Filter.">EKF<sq_T></a>* <a class="code" href="classbdm_1_1EKF.html#fe9b2e227255ad32dc73df316b7318f4" title="copy constructor">_copy_</a>()<span class="keyword"> const </span>{ |
199 | | <a name="l00234"></a>00234 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classbdm_1_1EKF.html" title="Extended Kalman Filter.">EKF<sq_T></a> ( this ); |
200 | | <a name="l00235"></a>00235 } |
201 | | <a name="l00237"></a>00237 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1EKF.html#00fec1a0a6a467eb83fb36c65eba7bcb" title="Set nonlinear functions for mean values and covariance matrices.">set_parameters</a> ( <a class="code" href="classbdm_1_1diffbifn.html" title="Class representing a differentiable function of two variables .">diffbifn</a>* pfxu, <a class="code" href="classbdm_1_1diffbifn.html" title="Class representing a differentiable function of two variables .">diffbifn</a>* phxu, <span class="keyword">const</span> sq_T Q0, <span class="keyword">const</span> sq_T R0 ); |
202 | | <a name="l00239"></a>00239 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1EKF.html#3fb182ecc29b10ca1163cecbf3bcccfa" title="Here dt = [yt;ut] of appropriate dimensions.">bayes</a> ( <span class="keyword">const</span> vec &dt ); |
203 | | <a name="l00240"></a>00240 }; |
| 74 | <a name="l00022"></a>00022 <span class="keyword">namespace </span>bdm |
| 75 | <a name="l00023"></a>00023 { |
| 76 | <a name="l00024"></a>00024 |
| 77 | <a name="l00032"></a>00032 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 78 | <a name="l00033"></a><a class="code" href="classbdm_1_1StateSpace.html">00033</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1StateSpace.html" title="Basic elements of linear state-space model.">StateSpace</a> |
| 79 | <a name="l00034"></a>00034 { |
| 80 | <a name="l00035"></a>00035 <span class="keyword">protected</span>: |
| 81 | <a name="l00037"></a><a class="code" href="classbdm_1_1StateSpace.html#c3120f1c9cd7c3a0ba9944e4a2381f21">00037</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1StateSpace.html#c3120f1c9cd7c3a0ba9944e4a2381f21" title="cache of rv.count()">dimx</a>; |
| 82 | <a name="l00039"></a><a class="code" href="classbdm_1_1StateSpace.html#3b784d85ca911866225a79193ae1441f">00039</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1StateSpace.html#3b784d85ca911866225a79193ae1441f" title="cache of rvy.count()">dimy</a>; |
| 83 | <a name="l00041"></a><a class="code" href="classbdm_1_1StateSpace.html#95bb59ffbfd34c55d03d4d7a2a9b4faf">00041</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1StateSpace.html#95bb59ffbfd34c55d03d4d7a2a9b4faf" title="cache of rvu.count()">dimu</a>; |
| 84 | <a name="l00043"></a><a class="code" href="classbdm_1_1StateSpace.html#de7d828a8d06cbbd5ac45afeaf9f0c7b">00043</a> mat <a class="code" href="classbdm_1_1StateSpace.html#de7d828a8d06cbbd5ac45afeaf9f0c7b" title="Matrix A.">A</a>; |
| 85 | <a name="l00045"></a><a class="code" href="classbdm_1_1StateSpace.html#0cdaa906550290b759a1584d02b3ca51">00045</a> mat <a class="code" href="classbdm_1_1StateSpace.html#0cdaa906550290b759a1584d02b3ca51" title="Matrix B.">B</a>; |
| 86 | <a name="l00047"></a><a class="code" href="classbdm_1_1StateSpace.html#c7ec82d2200c956cff6dff559bd32ff9">00047</a> mat <a class="code" href="classbdm_1_1StateSpace.html#c7ec82d2200c956cff6dff559bd32ff9" title="Matrix C.">C</a>; |
| 87 | <a name="l00049"></a><a class="code" href="classbdm_1_1StateSpace.html#d5769a41b34eb518716120cf04dbc23f">00049</a> mat <a class="code" href="classbdm_1_1StateSpace.html#d5769a41b34eb518716120cf04dbc23f" title="Matrix D.">D</a>; |
| 88 | <a name="l00051"></a><a class="code" href="classbdm_1_1StateSpace.html#66248c83836424f1cd7c1b5b9a92cf1f">00051</a> sq_T <a class="code" href="classbdm_1_1StateSpace.html#66248c83836424f1cd7c1b5b9a92cf1f" title="Matrix Q in square-root form.">Q</a>; |
| 89 | <a name="l00053"></a><a class="code" href="classbdm_1_1StateSpace.html#11dd3493d62ec9329860386adb3e6084">00053</a> sq_T <a class="code" href="classbdm_1_1StateSpace.html#11dd3493d62ec9329860386adb3e6084" title="Matrix R in square-root form.">R</a>; |
| 90 | <a name="l00054"></a>00054 <span class="keyword">public</span>: |
| 91 | <a name="l00055"></a>00055 <a class="code" href="classbdm_1_1StateSpace.html" title="Basic elements of linear state-space model.">StateSpace</a>() : <a class="code" href="classbdm_1_1StateSpace.html#c3120f1c9cd7c3a0ba9944e4a2381f21" title="cache of rv.count()">dimx</a> (0), <a class="code" href="classbdm_1_1StateSpace.html#3b784d85ca911866225a79193ae1441f" title="cache of rvy.count()">dimy</a> (0), <a class="code" href="classbdm_1_1StateSpace.html#95bb59ffbfd34c55d03d4d7a2a9b4faf" title="cache of rvu.count()">dimu</a> (0), <a class="code" href="classbdm_1_1StateSpace.html#de7d828a8d06cbbd5ac45afeaf9f0c7b" title="Matrix A.">A</a>(), <a class="code" href="classbdm_1_1StateSpace.html#0cdaa906550290b759a1584d02b3ca51" title="Matrix B.">B</a>(), <a class="code" href="classbdm_1_1StateSpace.html#c7ec82d2200c956cff6dff559bd32ff9" title="Matrix C.">C</a>(), <a class="code" href="classbdm_1_1StateSpace.html#d5769a41b34eb518716120cf04dbc23f" title="Matrix D.">D</a>(), <a class="code" href="classbdm_1_1StateSpace.html#66248c83836424f1cd7c1b5b9a92cf1f" title="Matrix Q in square-root form.">Q</a>(), <a class="code" href="classbdm_1_1StateSpace.html#11dd3493d62ec9329860386adb3e6084" title="Matrix R in square-root form.">R</a>() {} |
| 92 | <a name="l00056"></a>00056 <span class="keywordtype">void</span> set_parameters (<span class="keyword">const</span> mat &A0, <span class="keyword">const</span> mat &B0, <span class="keyword">const</span> mat &C0, <span class="keyword">const</span> mat &D0, <span class="keyword">const</span> sq_T &Q0, <span class="keyword">const</span> sq_T &R0); |
| 93 | <a name="l00057"></a>00057 <span class="keywordtype">void</span> validate(); |
| 94 | <a name="l00059"></a><a class="code" href="classbdm_1_1StateSpace.html#02470085bbf3c41fe8e36544813eecbd">00059</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1StateSpace.html#02470085bbf3c41fe8e36544813eecbd" title="not virtual in this case">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
| 95 | <a name="l00060"></a>00060 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1StateSpace.html#de7d828a8d06cbbd5ac45afeaf9f0c7b" title="Matrix A.">A</a>, <span class="keyword">set</span>, <span class="stringliteral">"A"</span>, UI::compulsory); |
| 96 | <a name="l00061"></a>00061 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1StateSpace.html#0cdaa906550290b759a1584d02b3ca51" title="Matrix B.">B</a>, <span class="keyword">set</span>, <span class="stringliteral">"B"</span>, UI::compulsory); |
| 97 | <a name="l00062"></a>00062 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1StateSpace.html#c7ec82d2200c956cff6dff559bd32ff9" title="Matrix C.">C</a>, <span class="keyword">set</span>, <span class="stringliteral">"C"</span>, UI::compulsory); |
| 98 | <a name="l00063"></a>00063 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1StateSpace.html#d5769a41b34eb518716120cf04dbc23f" title="Matrix D.">D</a>, <span class="keyword">set</span>, <span class="stringliteral">"D"</span>, UI::compulsory); |
| 99 | <a name="l00064"></a>00064 mat Qtm, Rtm; |
| 100 | <a name="l00065"></a>00065 <span class="keywordflow">if</span>(!<a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a>(Qtm, <span class="keyword">set</span>, <span class="stringliteral">"Q"</span>, UI::optional)){ |
| 101 | <a name="l00066"></a>00066 vec dq; |
| 102 | <a name="l00067"></a>00067 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a>(dq, <span class="keyword">set</span>, <span class="stringliteral">"dQ"</span>, UI::compulsory); |
| 103 | <a name="l00068"></a>00068 Qtm=diag(dq); |
| 104 | <a name="l00069"></a>00069 } |
| 105 | <a name="l00070"></a>00070 <span class="keywordflow">if</span>(!<a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a>(Rtm, <span class="keyword">set</span>, <span class="stringliteral">"R"</span>, UI::optional)){ |
| 106 | <a name="l00071"></a>00071 vec dr; |
| 107 | <a name="l00072"></a>00072 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a>(dr, <span class="keyword">set</span>, <span class="stringliteral">"dQ"</span>, UI::compulsory); |
| 108 | <a name="l00073"></a>00073 Rtm=diag(dr); |
| 109 | <a name="l00074"></a>00074 } |
| 110 | <a name="l00075"></a>00075 <a class="code" href="classbdm_1_1StateSpace.html#11dd3493d62ec9329860386adb3e6084" title="Matrix R in square-root form.">R</a>=Rtm; <span class="comment">// automatic conversion</span> |
| 111 | <a name="l00076"></a>00076 <a class="code" href="classbdm_1_1StateSpace.html#66248c83836424f1cd7c1b5b9a92cf1f" title="Matrix Q in square-root form.">Q</a>=Qtm; |
| 112 | <a name="l00077"></a>00077 |
| 113 | <a name="l00078"></a>00078 validate(); |
| 114 | <a name="l00079"></a>00079 } |
| 115 | <a name="l00081"></a><a class="code" href="classbdm_1_1StateSpace.html#b1972e00d9b9dd22a0f983c7cb0b8b40">00081</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1StateSpace.html#b1972e00d9b9dd22a0f983c7cb0b8b40" title="access function">_dimx</a>(){<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1StateSpace.html#c3120f1c9cd7c3a0ba9944e4a2381f21" title="cache of rv.count()">dimx</a>;} |
| 116 | <a name="l00083"></a><a class="code" href="classbdm_1_1StateSpace.html#f3d83a4b39e05df9fb4246fd6ddc2a60">00083</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1StateSpace.html#f3d83a4b39e05df9fb4246fd6ddc2a60" title="access function">_dimy</a>(){<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1StateSpace.html#3b784d85ca911866225a79193ae1441f" title="cache of rvy.count()">dimy</a>;} |
| 117 | <a name="l00085"></a><a class="code" href="classbdm_1_1StateSpace.html#a238842025a0eaade26d5d79a0e9000e">00085</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1StateSpace.html#a238842025a0eaade26d5d79a0e9000e" title="access function">_dimu</a>(){<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1StateSpace.html#95bb59ffbfd34c55d03d4d7a2a9b4faf" title="cache of rvu.count()">dimu</a>;} |
| 118 | <a name="l00087"></a><a class="code" href="classbdm_1_1StateSpace.html#a70f6c8ab37f955f408361150e13c47b">00087</a> mat <a class="code" href="classbdm_1_1StateSpace.html#a70f6c8ab37f955f408361150e13c47b" title="access function">_A</a>(){<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1StateSpace.html#de7d828a8d06cbbd5ac45afeaf9f0c7b" title="Matrix A.">A</a>;} |
| 119 | <a name="l00089"></a><a class="code" href="classbdm_1_1StateSpace.html#4272982f976ea9d0ea7c9b7182ed7e3c">00089</a> mat <a class="code" href="classbdm_1_1StateSpace.html#4272982f976ea9d0ea7c9b7182ed7e3c" title="access function">_B</a>(){<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1StateSpace.html#0cdaa906550290b759a1584d02b3ca51" title="Matrix B.">B</a>;} |
| 120 | <a name="l00091"></a><a class="code" href="classbdm_1_1StateSpace.html#ec4c0923e2b5d0c3e5dfe119ffee511e">00091</a> mat <a class="code" href="classbdm_1_1StateSpace.html#ec4c0923e2b5d0c3e5dfe119ffee511e" title="access function">_C</a>(){<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1StateSpace.html#c7ec82d2200c956cff6dff559bd32ff9" title="Matrix C.">C</a>;} |
| 121 | <a name="l00093"></a><a class="code" href="classbdm_1_1StateSpace.html#e0757fcc5e0ebaf0bd95f522bf405f06">00093</a> mat <a class="code" href="classbdm_1_1StateSpace.html#e0757fcc5e0ebaf0bd95f522bf405f06" title="access function">_D</a>(){<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1StateSpace.html#d5769a41b34eb518716120cf04dbc23f" title="Matrix D.">D</a>;} |
| 122 | <a name="l00095"></a><a class="code" href="classbdm_1_1StateSpace.html#4c908775f27db8d869b93078862a4934">00095</a> sq_T <a class="code" href="classbdm_1_1StateSpace.html#4c908775f27db8d869b93078862a4934" title="access function">_Q</a>(){<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1StateSpace.html#66248c83836424f1cd7c1b5b9a92cf1f" title="Matrix Q in square-root form.">Q</a>;} |
| 123 | <a name="l00097"></a><a class="code" href="classbdm_1_1StateSpace.html#8c94418779eb70f6199fa3467c45f316">00097</a> sq_T <a class="code" href="classbdm_1_1StateSpace.html#8c94418779eb70f6199fa3467c45f316" title="access function">_R</a>(){<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1StateSpace.html#11dd3493d62ec9329860386adb3e6084" title="Matrix R in square-root form.">R</a>;} |
| 124 | <a name="l00098"></a>00098 }; |
| 125 | <a name="l00099"></a>00099 |
| 126 | <a name="l00101"></a>00101 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 127 | <a name="l00102"></a><a class="code" href="classbdm_1_1Kalman.html">00102</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1Kalman.html" title="Common abstract base for Kalman filters.">Kalman</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>, <span class="keyword">public</span> <a class="code" href="classbdm_1_1StateSpace.html" title="Basic elements of linear state-space model.">StateSpace</a><sq_T> |
| 128 | <a name="l00103"></a>00103 { |
| 129 | <a name="l00104"></a>00104 <span class="keyword">protected</span>: |
| 130 | <a name="l00106"></a><a class="code" href="classbdm_1_1Kalman.html#aac28e226fe6cbff5a9ae38d8d025d7a">00106</a> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> <a class="code" href="classbdm_1_1Kalman.html#aac28e226fe6cbff5a9ae38d8d025d7a" title="id of output">yrv</a>; |
| 131 | <a name="l00108"></a><a class="code" href="classbdm_1_1Kalman.html#44d4a8ab05d5311286e1da78b831633e">00108</a> <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> <a class="code" href="classbdm_1_1Kalman.html#44d4a8ab05d5311286e1da78b831633e" title="id of input">urv</a>; |
| 132 | <a name="l00110"></a><a class="code" href="classbdm_1_1Kalman.html#bd69dfb802465f22dd84d73a180d5c92">00110</a> mat <a class="code" href="classbdm_1_1Kalman.html#bd69dfb802465f22dd84d73a180d5c92" title="Kalman gain.">_K</a>; |
| 133 | <a name="l00112"></a><a class="code" href="classbdm_1_1Kalman.html#c83599f2541eb01de329f7b0bb35bf43">00112</a> <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<enorm<sq_T></a> > <a class="code" href="classbdm_1_1Kalman.html#c83599f2541eb01de329f7b0bb35bf43" title="posterior">est</a>; |
| 134 | <a name="l00114"></a><a class="code" href="classbdm_1_1Kalman.html#ba555c394c429f6831c9bbabfa2c944c">00114</a> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a> <a class="code" href="classbdm_1_1Kalman.html#ba555c394c429f6831c9bbabfa2c944c" title="marginal on data f(y|y)">fy</a>; |
| 135 | <a name="l00115"></a>00115 <span class="keyword">public</span>: |
| 136 | <a name="l00116"></a>00116 <a class="code" href="classbdm_1_1Kalman.html" title="Common abstract base for Kalman filters.">Kalman</a>() : <a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a>(), <a class="code" href="classbdm_1_1StateSpace.html" title="Basic elements of linear state-space model.">StateSpace</a><sq_T>(), <a class="code" href="classbdm_1_1Kalman.html#aac28e226fe6cbff5a9ae38d8d025d7a" title="id of output">yrv</a>(),<a class="code" href="classbdm_1_1Kalman.html#44d4a8ab05d5311286e1da78b831633e" title="id of input">urv</a>(), <a class="code" href="classbdm_1_1Kalman.html#bd69dfb802465f22dd84d73a180d5c92" title="Kalman gain.">_K</a>(), <a class="code" href="classbdm_1_1Kalman.html#c83599f2541eb01de329f7b0bb35bf43" title="posterior">est</a>(new <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm</a><sq_T>){} |
| 137 | <a name="l00117"></a>00117 <span class="keywordtype">void</span> set_statistics (<span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> mat &P0) {<a class="code" href="classbdm_1_1Kalman.html#c83599f2541eb01de329f7b0bb35bf43" title="posterior">est</a>->set_parameters (mu0, P0); }; |
| 138 | <a name="l00118"></a>00118 <span class="keywordtype">void</span> set_statistics (<span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> sq_T &P0) {<a class="code" href="classbdm_1_1Kalman.html#c83599f2541eb01de329f7b0bb35bf43" title="posterior">est</a>->set_parameters (mu0, P0); }; |
| 139 | <a name="l00120"></a><a class="code" href="classbdm_1_1Kalman.html#8b0c3db41eb292edb20b826832c9b5fa">00120</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1enorm.html" title="Gaussian density with positive definite (decomposed) covariance matrix.">enorm<sq_T></a>& <a class="code" href="classbdm_1_1Kalman.html#8b0c3db41eb292edb20b826832c9b5fa" title="posterior">posterior</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> *<a class="code" href="classbdm_1_1Kalman.html#c83599f2541eb01de329f7b0bb35bf43" title="posterior">est</a>.<a class="code" href="classbdm_1_1shared__ptr.html#37ebcfb6750dd7b5630f1d2354c07a96">get</a>();} |
| 140 | <a name="l00122"></a><a class="code" href="classbdm_1_1Kalman.html#4da2fdd01e9b335b133def9814eb0620">00122</a> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<epdf></a> <a class="code" href="classbdm_1_1Kalman.html#4da2fdd01e9b335b133def9814eb0620" title="shared posterior">shared_posterior</a>() {<span class="keywordflow">return</span> <a class="code" href="classbdm_1_1Kalman.html#c83599f2541eb01de329f7b0bb35bf43" title="posterior">est</a>;} |
| 141 | <a name="l00124"></a><a class="code" href="classbdm_1_1Kalman.html#7fe88fc3471cab1911707bcdb6b4690a">00124</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1Kalman.html#7fe88fc3471cab1911707bcdb6b4690a" title="load basic elements of Kalman from structure">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>) { |
| 142 | <a name="l00125"></a>00125 <a class="code" href="classbdm_1_1Kalman.html#7fe88fc3471cab1911707bcdb6b4690a" title="load basic elements of Kalman from structure">StateSpace<sq_T>::from_setting</a>(<span class="keyword">set</span>); |
| 143 | <a name="l00126"></a>00126 |
| 144 | <a name="l00127"></a>00127 mat P0; vec mu0; |
| 145 | <a name="l00128"></a>00128 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a>(mu0, <span class="keyword">set</span>, <span class="stringliteral">"mu0"</span>, UI::optional); |
| 146 | <a name="l00129"></a>00129 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a>(P0, <span class="keyword">set</span>, <span class="stringliteral">"P0"</span>, UI::optional); |
| 147 | <a name="l00130"></a>00130 set_statistics(mu0,P0); |
| 148 | <a name="l00131"></a>00131 <span class="comment">// Initial values</span> |
| 149 | <a name="l00132"></a>00132 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1Kalman.html#aac28e226fe6cbff5a9ae38d8d025d7a" title="id of output">yrv</a>, <span class="keyword">set</span>, <span class="stringliteral">"yrv"</span>, UI::optional); |
| 150 | <a name="l00133"></a>00133 <a class="code" href="classbdm_1_1UI.html#cd1667e6fec99ec64dabcb3ca2ff922d">UI::get</a> (<a class="code" href="classbdm_1_1Kalman.html#44d4a8ab05d5311286e1da78b831633e" title="id of input">urv</a>, <span class="keyword">set</span>, <span class="stringliteral">"urv"</span>, UI::optional); |
| 151 | <a name="l00134"></a>00134 set_drv(concat(<a class="code" href="classbdm_1_1Kalman.html#aac28e226fe6cbff5a9ae38d8d025d7a" title="id of output">yrv</a>,<a class="code" href="classbdm_1_1Kalman.html#44d4a8ab05d5311286e1da78b831633e" title="id of input">urv</a>)); |
| 152 | <a name="l00135"></a>00135 |
| 153 | <a name="l00136"></a>00136 validate(); |
| 154 | <a name="l00137"></a>00137 } |
| 155 | <a name="l00138"></a>00138 <span class="keywordtype">void</span> validate() { |
| 156 | <a name="l00139"></a>00139 <a class="code" href="classbdm_1_1StateSpace.html" title="Basic elements of linear state-space model.">StateSpace<sq_T>::validate</a>(); |
| 157 | <a name="l00140"></a>00140 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a>(<a class="code" href="classbdm_1_1Kalman.html#c83599f2541eb01de329f7b0bb35bf43" title="posterior">est</a>->dimension(), <span class="stringliteral">"Statistics and model parameters mismatch"</span>); |
| 158 | <a name="l00141"></a>00141 } |
| 159 | <a name="l00142"></a>00142 }; |
| 160 | <a name="l00147"></a><a class="code" href="classbdm_1_1KalmanFull.html">00147</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1KalmanFull.html" title="Basic Kalman filter with full matrices.">KalmanFull</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1Kalman.html" title="Common abstract base for Kalman filters.">Kalman</a><fsqmat> |
| 161 | <a name="l00148"></a>00148 { |
| 162 | <a name="l00149"></a>00149 <span class="keyword">public</span>: |
| 163 | <a name="l00151"></a><a class="code" href="classbdm_1_1KalmanFull.html#bdcc98c8b18c1cbdebdf218ae838fd11">00151</a> <a class="code" href="classbdm_1_1KalmanFull.html#bdcc98c8b18c1cbdebdf218ae838fd11" title="For EKFfull;.">KalmanFull</a>() :<a class="code" href="classbdm_1_1Kalman.html" title="Common abstract base for Kalman filters.">Kalman</a><<a class="code" href="classbdm_1_1fsqmat.html" title="Fake sqmat. This class maps sqmat operations to operations on full matrix.">fsqmat</a>>(){}; |
| 164 | <a name="l00153"></a>00153 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1KalmanFull.html#081924bc97f453f674bb982b7951d053" title="Here dt = [yt;ut] of appropriate dimensions.">bayes</a> (<span class="keyword">const</span> vec &dt); |
| 165 | <a name="l00154"></a>00154 }; |
| 166 | <a name="l00155"></a>00155 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(KalmanFull); |
| 167 | <a name="l00156"></a>00156 |
| 168 | <a name="l00157"></a>00157 |
| 169 | <a name="l00165"></a><a class="code" href="classbdm_1_1KalmanCh.html">00165</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1KalmanCh.html" title="Kalman filter in square root form.">KalmanCh</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1Kalman.html" title="Common abstract base for Kalman filters.">Kalman</a><chmat> |
| 170 | <a name="l00166"></a>00166 { |
| 171 | <a name="l00167"></a>00167 <span class="keyword">protected</span>: |
| 172 | <a name="l00170"></a>00170 mat preA; |
| 173 | <a name="l00172"></a><a class="code" href="classbdm_1_1KalmanCh.html#bcbd68f51d4b57246e7784ca5900171f">00172</a> mat <a class="code" href="classbdm_1_1KalmanCh.html#bcbd68f51d4b57246e7784ca5900171f" title="post array (triangular matrix)">postA</a>; |
| 174 | <a name="l00174"></a>00174 <span class="keyword">public</span>: |
| 175 | <a name="l00176"></a><a class="code" href="classbdm_1_1KalmanCh.html#24ce65bdaa538d4d5153d709a929b996">00176</a> <a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a>* <a class="code" href="classbdm_1_1KalmanCh.html#24ce65bdaa538d4d5153d709a929b996" title="copy constructor">_copy_</a>()<span class="keyword"> const </span>{ |
| 176 | <a name="l00177"></a>00177 <a class="code" href="classbdm_1_1KalmanCh.html" title="Kalman filter in square root form.">KalmanCh</a>* K = <span class="keyword">new</span> <a class="code" href="classbdm_1_1KalmanCh.html" title="Kalman filter in square root form.">KalmanCh</a>; |
| 177 | <a name="l00178"></a>00178 K-><a class="code" href="classbdm_1_1KalmanCh.html#20a4d4c664e8ac8a3f1bb7b0d11c6d87" title="set parameters for adapt from Kalman">set_parameters</a> (<a class="code" href="classbdm_1_1StateSpace.html#de7d828a8d06cbbd5ac45afeaf9f0c7b" title="Matrix A.">A</a>, <a class="code" href="classbdm_1_1StateSpace.html#0cdaa906550290b759a1584d02b3ca51" title="Matrix B.">B</a>, <a class="code" href="classbdm_1_1StateSpace.html#c7ec82d2200c956cff6dff559bd32ff9" title="Matrix C.">C</a>, <a class="code" href="classbdm_1_1StateSpace.html#d5769a41b34eb518716120cf04dbc23f" title="Matrix D.">D</a>, <a class="code" href="classbdm_1_1StateSpace.html#66248c83836424f1cd7c1b5b9a92cf1f" title="Matrix Q in square-root form.">Q</a>, <a class="code" href="classbdm_1_1StateSpace.html#11dd3493d62ec9329860386adb3e6084" title="Matrix R in square-root form.">R</a>); |
| 178 | <a name="l00179"></a>00179 K-><a class="code" href="classbdm_1_1Kalman.html#d9107617cd5482272ab046849cbfff49">set_statistics</a> (<a class="code" href="classbdm_1_1Kalman.html#c83599f2541eb01de329f7b0bb35bf43" title="posterior">est</a>->_mu(), <a class="code" href="classbdm_1_1Kalman.html#c83599f2541eb01de329f7b0bb35bf43" title="posterior">est</a>->_R()); |
| 179 | <a name="l00180"></a>00180 <span class="keywordflow">return</span> K; |
| 180 | <a name="l00181"></a>00181 } |
| 181 | <a name="l00183"></a>00183 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1KalmanCh.html#20a4d4c664e8ac8a3f1bb7b0d11c6d87" title="set parameters for adapt from Kalman">set_parameters</a> (<span class="keyword">const</span> mat &A0, <span class="keyword">const</span> mat &B0, <span class="keyword">const</span> mat &C0, <span class="keyword">const</span> mat &D0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> &Q0, <span class="keyword">const</span> <a class="code" href="classbdm_1_1chmat.html" title="Symmetric matrix stored in square root decomposition using upper cholesky.">chmat</a> &R0); |
| 182 | <a name="l00185"></a>00185 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1KalmanCh.html#c983b1a2687312ab733d4c859cf83c1e" title="initialize internal parametetrs">initialize</a>(); |
| 183 | <a name="l00186"></a>00186 |
| 184 | <a name="l00200"></a>00200 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1KalmanCh.html#b41fe5540548100b08e1684c3be767b6" title="Here dt = [yt;ut] of appropriate dimensions.">bayes</a> (<span class="keyword">const</span> vec &dt); |
| 185 | <a name="l00201"></a>00201 |
| 186 | <a name="l00202"></a><a class="code" href="classbdm_1_1KalmanCh.html#13f68cef5b14c8753012ad3ed695689d">00202</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1KalmanCh.html#13f68cef5b14c8753012ad3ed695689d" title="load basic elements of Kalman from structure">from_setting</a>(<span class="keyword">const</span> Setting &<span class="keyword">set</span>){ |
| 187 | <a name="l00203"></a>00203 <a class="code" href="classbdm_1_1KalmanCh.html#13f68cef5b14c8753012ad3ed695689d" title="load basic elements of Kalman from structure">Kalman<chmat>::from_setting</a>(<span class="keyword">set</span>); |
| 188 | <a name="l00204"></a>00204 <a class="code" href="classbdm_1_1KalmanCh.html#c983b1a2687312ab733d4c859cf83c1e" title="initialize internal parametetrs">initialize</a>(); |
| 189 | <a name="l00205"></a>00205 } |
| 190 | <a name="l00206"></a>00206 }; |
| 191 | <a name="l00207"></a>00207 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(KalmanCh); |
| 192 | <a name="l00208"></a>00208 |
| 193 | <a name="l00214"></a><a class="code" href="classbdm_1_1EKFfull.html">00214</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1EKFfull.html" title="Extended Kalman Filter in full matrices.">EKFfull</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1KalmanFull.html" title="Basic Kalman filter with full matrices.">KalmanFull</a> |
| 194 | <a name="l00215"></a>00215 { |
| 195 | <a name="l00216"></a>00216 <span class="keyword">protected</span>: |
| 196 | <a name="l00218"></a><a class="code" href="classbdm_1_1EKFfull.html#ee5bfb3f09dfa994596c5bc68306f7d6">00218</a> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<diffbifn></a> <a class="code" href="classbdm_1_1EKFfull.html#ee5bfb3f09dfa994596c5bc68306f7d6" title="Internal Model f(x,u).">pfxu</a>; |
| 197 | <a name="l00219"></a>00219 |
| 198 | <a name="l00221"></a><a class="code" href="classbdm_1_1EKFfull.html#6432c675b1a9b83898b4ff19eab9b45c">00221</a> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<diffbifn></a> <a class="code" href="classbdm_1_1EKFfull.html#6432c675b1a9b83898b4ff19eab9b45c" title="Observation Model h(x,u).">phxu</a>; |
| 199 | <a name="l00222"></a>00222 |
| 200 | <a name="l00223"></a>00223 <span class="keyword">public</span>: |
| 201 | <a name="l00225"></a>00225 <a class="code" href="classbdm_1_1EKFfull.html#6939c345389abb8b2481457b4cfe1165" title="Default constructor.">EKFfull</a> (); |
| 202 | <a name="l00226"></a>00226 |
| 203 | <a name="l00228"></a>00228 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1EKFfull.html#8a68f95124a4b01f9ce23225f3c736a4" title="Set nonlinear functions for mean values and covariance matrices.">set_parameters</a> (<span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<diffbifn></a> &<a class="code" href="classbdm_1_1EKFfull.html#ee5bfb3f09dfa994596c5bc68306f7d6" title="Internal Model f(x,u).">pfxu</a>, <span class="keyword">const</span> <a class="code" href="classbdm_1_1shared__ptr.html">shared_ptr<diffbifn></a> &<a class="code" href="classbdm_1_1EKFfull.html#6432c675b1a9b83898b4ff19eab9b45c" title="Observation Model h(x,u).">phxu</a>, <span class="keyword">const</span> mat Q0, <span class="keyword">const</span> mat R0); |
| 204 | <a name="l00229"></a>00229 |
| 205 | <a name="l00231"></a>00231 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1EKFfull.html#f149ae8e9ce14d9931a7bb2850736699" title="Here dt = [yt;ut] of appropriate dimensions.">bayes</a> (<span class="keyword">const</span> vec &dt); |
| 206 | <a name="l00233"></a><a class="code" href="classbdm_1_1EKFfull.html#44986d667c19bcf7708495a4a5afc841">00233</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1EKFfull.html#44986d667c19bcf7708495a4a5afc841" title="set estimates">set_statistics</a> (<span class="keyword">const</span> vec &mu0, <span class="keyword">const</span> mat &P0) { |
| 207 | <a name="l00234"></a>00234 <a class="code" href="classbdm_1_1Kalman.html#c83599f2541eb01de329f7b0bb35bf43" title="posterior">est</a>->set_parameters (mu0, P0); |
| 208 | <a name="l00235"></a>00235 }; |
| 209 | <a name="l00236"></a><a class="code" href="classbdm_1_1EKFfull.html#d4f57cb8af64b06c530f528c32596d4d">00236</a> <span class="keyword">const</span> mat <a class="code" href="classbdm_1_1EKFfull.html#d4f57cb8af64b06c530f528c32596d4d" title="access function">_R</a>() { |
| 210 | <a name="l00237"></a>00237 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1Kalman.html#c83599f2541eb01de329f7b0bb35bf43" title="posterior">est</a>->_R().to_mat(); |
| 211 | <a name="l00238"></a>00238 } |
| 212 | <a name="l00239"></a>00239 }; |
| 213 | <a name="l00240"></a>00240 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a>(EKFfull); |
232 | | <a name="l00284"></a><a class="code" href="classbdm_1_1KFcondQR.html">00284</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1KFcondQR.html" title="Kalman Filter with conditional diagonal matrices R and Q.">KFcondQR</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1Kalman.html" title="Kalman filter with covariance matrices in square root form.">Kalman</a><ldmat> { |
233 | | <a name="l00285"></a>00285 <span class="comment">//protected:</span> |
234 | | <a name="l00286"></a>00286 <span class="keyword">public</span>: |
235 | | <a name="l00287"></a><a class="code" href="classbdm_1_1KFcondQR.html#31bc31087ee7ed6c0bfb92d626321b91">00287</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1KFcondQR.html#31bc31087ee7ed6c0bfb92d626321b91" title="Substitute val for rvc.">condition</a> ( <span class="keyword">const</span> vec &QR ) { |
236 | | <a name="l00288"></a>00288 it_assert_debug ( QR.length() == ( <a class="code" href="classbdm_1_1Kalman.html#ba7699cdb3b1382a54d3e28b9b7517fa" title="cache of rv.count()">dimx</a> + <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> ), <span class="stringliteral">"KFcondRQ: conditioning by incompatible vector"</span> ); |
237 | | <a name="l00289"></a>00289 |
238 | | <a name="l00290"></a>00290 <a class="code" href="classbdm_1_1Kalman.html#70f8bf19e81b532c60fd3a7a152425ee" title="Matrix Q in square-root form.">Q</a>.<a class="code" href="classbdm_1_1ldmat.html#72e61ad4e0653f4fc38e7d60d3cf1d4e" title="Access functions.">setD</a> ( QR ( 0, <a class="code" href="classbdm_1_1Kalman.html#ba7699cdb3b1382a54d3e28b9b7517fa" title="cache of rv.count()">dimx</a> - 1 ) ); |
239 | | <a name="l00291"></a>00291 <a class="code" href="classbdm_1_1Kalman.html#475b088287cdfbba4dc60a3d027728b7" title="Matrix R in square-root form.">R</a>.<a class="code" href="classbdm_1_1ldmat.html#72e61ad4e0653f4fc38e7d60d3cf1d4e" title="Access functions.">setD</a> ( QR ( <a class="code" href="classbdm_1_1Kalman.html#ba7699cdb3b1382a54d3e28b9b7517fa" title="cache of rv.count()">dimx</a>, -1 ) ); |
240 | | <a name="l00292"></a>00292 }; |
241 | | <a name="l00293"></a>00293 }; |
242 | | <a name="l00294"></a>00294 |
243 | | <a name="l00299"></a><a class="code" href="classbdm_1_1KFcondR.html">00299</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1KFcondR.html" title="Kalman Filter with conditional diagonal matrices R and Q.">KFcondR</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1Kalman.html" title="Kalman filter with covariance matrices in square root form.">Kalman</a><ldmat> { |
244 | | <a name="l00300"></a>00300 <span class="comment">//protected:</span> |
245 | | <a name="l00301"></a>00301 <span class="keyword">public</span>: |
246 | | <a name="l00303"></a><a class="code" href="classbdm_1_1KFcondR.html#f11639d79f10b1e7dad16a0d8233450d">00303</a> <a class="code" href="classbdm_1_1KFcondR.html#f11639d79f10b1e7dad16a0d8233450d" title="Default constructor.">KFcondR</a> ( ) : <a class="code" href="classbdm_1_1Kalman.html" title="Kalman filter with covariance matrices in square root form.">Kalman</a><<a class="code" href="classbdm_1_1ldmat.html" title="Matrix stored in LD form, (commonly known as UD).">ldmat</a>> ( ) {}; |
247 | | <a name="l00304"></a>00304 |
248 | | <a name="l00305"></a><a class="code" href="classbdm_1_1KFcondR.html#7d42a421acbdcf9b610a5682ee5fb9a8">00305</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1KFcondR.html#7d42a421acbdcf9b610a5682ee5fb9a8" title="Substitute val for rvc.">condition</a> ( <span class="keyword">const</span> vec &R0 ) { |
249 | | <a name="l00306"></a>00306 it_assert_debug ( R0.length() == ( <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> ), <span class="stringliteral">"KFcondR: conditioning by incompatible vector"</span> ); |
250 | | <a name="l00307"></a>00307 |
251 | | <a name="l00308"></a>00308 <a class="code" href="classbdm_1_1Kalman.html#475b088287cdfbba4dc60a3d027728b7" title="Matrix R in square-root form.">R</a>.<a class="code" href="classbdm_1_1ldmat.html#72e61ad4e0653f4fc38e7d60d3cf1d4e" title="Access functions.">setD</a> ( R0 ); |
252 | | <a name="l00309"></a>00309 }; |
253 | | <a name="l00310"></a>00310 |
254 | | <a name="l00311"></a>00311 }; |
255 | | <a name="l00312"></a>00312 |
256 | | <a name="l00314"></a>00314 |
257 | | <a name="l00315"></a>00315 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
258 | | <a name="l00316"></a><a class="code" href="classbdm_1_1Kalman.html#8b22c45cffa949d70b8e5ac92ed5ce25">00316</a> <a class="code" href="classbdm_1_1Kalman.html#025a0196cbcc2e6adb13311f9d3d52b4" title="Default constructor.">Kalman<sq_T>::Kalman</a> ( <span class="keyword">const</span> <a class="code" href="classbdm_1_1Kalman.html" title="Kalman filter with covariance matrices in square root form.">Kalman<sq_T></a> &K0 ) : <a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a> ( ), rvy ( K0.rvy ), rvu ( K0.rvu ), |
259 | | <a name="l00317"></a>00317 dimx ( K0.dimx ), dimy ( K0.dimy ), dimu ( K0.dimu ), |
260 | | <a name="l00318"></a>00318 A ( K0.A ), B ( K0.B ), C ( K0.C ), D ( K0.D ), |
261 | | <a name="l00319"></a>00319 Q ( K0.Q ), R ( K0.R ), |
262 | | <a name="l00320"></a>00320 est ( K0.est ), fy ( K0.fy ), _yp ( fy._mu() ), _Ry ( fy._R() ), _mu ( est._mu() ), _P ( est._R() ) { |
263 | | <a name="l00321"></a>00321 |
264 | | <a name="l00322"></a>00322 <span class="comment">// copy values in pointers</span> |
265 | | <a name="l00323"></a>00323 <span class="comment">// _mu = K0._mu;</span> |
266 | | <a name="l00324"></a>00324 <span class="comment">// _P = K0._P;</span> |
267 | | <a name="l00325"></a>00325 <span class="comment">// _yp = K0._yp;</span> |
268 | | <a name="l00326"></a>00326 <span class="comment">// _Ry = K0._Ry;</span> |
269 | | <a name="l00327"></a>00327 |
270 | | <a name="l00328"></a>00328 } |
271 | | <a name="l00329"></a>00329 |
272 | | <a name="l00330"></a>00330 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
273 | | <a name="l00331"></a><a class="code" href="classbdm_1_1Kalman.html#025a0196cbcc2e6adb13311f9d3d52b4">00331</a> <a class="code" href="classbdm_1_1Kalman.html#025a0196cbcc2e6adb13311f9d3d52b4" title="Default constructor.">Kalman<sq_T>::Kalman</a> ( ) : <a class="code" href="classbdm_1_1BM.html" title="Bayesian Model of a system, i.e. all uncertainty is modeled by probabilities.">BM</a> (), est ( ), fy (), _yp ( fy._mu() ), _Ry ( fy._R() ), _mu ( est._mu() ), _P ( est._R() ) { |
274 | | <a name="l00332"></a>00332 }; |
275 | | <a name="l00333"></a>00333 |
276 | | <a name="l00334"></a>00334 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
277 | | <a name="l00335"></a><a class="code" href="classbdm_1_1Kalman.html#3c7fb87fb6b87d08deb6a5a7862da957">00335</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1Kalman.html#3c7fb87fb6b87d08deb6a5a7862da957" title="Set parameters with check of relevance.">Kalman<sq_T>::set_parameters</a> ( <span class="keyword">const</span> mat &A0, <span class="keyword">const</span> mat &B0, <span class="keyword">const</span> mat &C0, <span class="keyword">const</span> mat &D0, <span class="keyword">const</span> sq_T &Q0, <span class="keyword">const</span> sq_T &R0 ) { |
278 | | <a name="l00336"></a>00336 <a class="code" href="classbdm_1_1Kalman.html#ba7699cdb3b1382a54d3e28b9b7517fa" title="cache of rv.count()">dimx</a> = A0.rows(); |
279 | | <a name="l00337"></a>00337 <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> = C0.rows(); |
280 | | <a name="l00338"></a>00338 <a class="code" href="classbdm_1_1Kalman.html#c5136ef617f6ac0e426bea222755d92b" title="cache of rvu.count()">dimu</a> = B0.cols(); |
281 | | <a name="l00339"></a>00339 |
282 | | <a name="l00340"></a>00340 it_assert_debug ( A0.cols() == <a class="code" href="classbdm_1_1Kalman.html#ba7699cdb3b1382a54d3e28b9b7517fa" title="cache of rv.count()">dimx</a>, <span class="stringliteral">"Kalman: A is not square"</span> ); |
283 | | <a name="l00341"></a>00341 it_assert_debug ( B0.rows() == <a class="code" href="classbdm_1_1Kalman.html#ba7699cdb3b1382a54d3e28b9b7517fa" title="cache of rv.count()">dimx</a>, <span class="stringliteral">"Kalman: B is not compatible"</span> ); |
284 | | <a name="l00342"></a>00342 it_assert_debug ( C0.cols() == <a class="code" href="classbdm_1_1Kalman.html#ba7699cdb3b1382a54d3e28b9b7517fa" title="cache of rv.count()">dimx</a>, <span class="stringliteral">"Kalman: C is not square"</span> ); |
285 | | <a name="l00343"></a>00343 it_assert_debug ( ( D0.rows() == <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> ) || ( D0.cols() == <a class="code" href="classbdm_1_1Kalman.html#c5136ef617f6ac0e426bea222755d92b" title="cache of rvu.count()">dimu</a> ), <span class="stringliteral">"Kalman: D is not compatible"</span> ); |
286 | | <a name="l00344"></a>00344 it_assert_debug ( ( R0.cols() == <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> ) || ( R0.rows() == <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> ), <span class="stringliteral">"Kalman: R is not compatible"</span> ); |
287 | | <a name="l00345"></a>00345 it_assert_debug ( ( Q0.cols() == <a class="code" href="classbdm_1_1Kalman.html#ba7699cdb3b1382a54d3e28b9b7517fa" title="cache of rv.count()">dimx</a> ) || ( Q0.rows() == <a class="code" href="classbdm_1_1Kalman.html#ba7699cdb3b1382a54d3e28b9b7517fa" title="cache of rv.count()">dimx</a> ), <span class="stringliteral">"Kalman: Q is not compatible"</span> ); |
288 | | <a name="l00346"></a>00346 |
289 | | <a name="l00347"></a>00347 <a class="code" href="classbdm_1_1Kalman.html#0a2072e2090c10fac74ad30a023a4ace" title="Matrix A.">A</a> = A0; |
290 | | <a name="l00348"></a>00348 <a class="code" href="classbdm_1_1Kalman.html#5977b2c81857948a35105f0e7840203c" title="Matrix B.">B</a> = B0; |
291 | | <a name="l00349"></a>00349 <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a> = C0; |
292 | | <a name="l00350"></a>00350 <a class="code" href="classbdm_1_1Kalman.html#7b56ac423d0654b5755e4f852a870456" title="Matrix D.">D</a> = D0; |
293 | | <a name="l00351"></a>00351 <a class="code" href="classbdm_1_1Kalman.html#475b088287cdfbba4dc60a3d027728b7" title="Matrix R in square-root form.">R</a> = R0; |
294 | | <a name="l00352"></a>00352 <a class="code" href="classbdm_1_1Kalman.html#70f8bf19e81b532c60fd3a7a152425ee" title="Matrix Q in square-root form.">Q</a> = Q0; |
295 | | <a name="l00353"></a>00353 } |
| 242 | <a name="l00280"></a>00280 |
| 243 | <a name="l00282"></a>00282 |
| 244 | <a name="l00290"></a><a class="code" href="classbdm_1_1MultiModel.html">00290</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1MultiModel.html" title="(Switching) Multiple Model The model runs several models in parallel and evaluates...">MultiModel</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> |
| 245 | <a name="l00291"></a>00291 { |
| 246 | <a name="l00292"></a>00292 <span class="keyword">protected</span>: |
| 247 | <a name="l00294"></a><a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93">00294</a> Array<EKFCh*> <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a>; |
| 248 | <a name="l00296"></a><a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a">00296</a> vec <a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a" title="vector of model weights">w</a>; |
| 249 | <a name="l00298"></a><a class="code" href="classbdm_1_1MultiModel.html#7b4012fc2208ce4ddd5c0d1fe69d7634">00298</a> vec <a class="code" href="classbdm_1_1MultiModel.html#7b4012fc2208ce4ddd5c0d1fe69d7634" title="cache of model lls">_lls</a>; |
| 250 | <a name="l00300"></a><a class="code" href="classbdm_1_1MultiModel.html#9b56bcde4664bd53f8995d7ee7ed415c">00300</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1MultiModel.html#9b56bcde4664bd53f8995d7ee7ed415c" title="type of switching policy [1=maximum,2=...]">policy</a>; |
| 251 | <a name="l00302"></a><a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b">00302</a> <a class="code" href="classbdm_1_1enorm.html">enorm<chmat></a> <a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>; |
| 252 | <a name="l00303"></a>00303 <span class="keyword">public</span>: |
| 253 | <a name="l00304"></a>00304 <span class="keywordtype">void</span> set_parameters (Array<EKFCh*> A, <span class="keywordtype">int</span> pol0 = 1) { |
| 254 | <a name="l00305"></a>00305 <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a> = A;<span class="comment">//TODO: test if evalll is set</span> |
| 255 | <a name="l00306"></a>00306 <a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a" title="vector of model weights">w</a>.set_length (A.length()); |
| 256 | <a name="l00307"></a>00307 <a class="code" href="classbdm_1_1MultiModel.html#7b4012fc2208ce4ddd5c0d1fe69d7634" title="cache of model lls">_lls</a>.set_length (A.length()); |
| 257 | <a name="l00308"></a>00308 <a class="code" href="classbdm_1_1MultiModel.html#9b56bcde4664bd53f8995d7ee7ed415c" title="type of switching policy [1=maximum,2=...]">policy</a> = pol0; |
| 258 | <a name="l00309"></a>00309 |
| 259 | <a name="l00310"></a>00310 <a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>.<a class="code" href="classbdm_1_1epdf.html#f423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a> (<a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> (<span class="stringliteral">"MM"</span>, A (0)-><a class="code" href="classbdm_1_1MultiModel.html#2af3f8dc10dfdae0ddc8160a9f36aaee" title="posterior density">posterior</a>().dimension(), 0)); |
| 260 | <a name="l00311"></a>00311 <a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>.<a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> (A (0)-><a class="code" href="classbdm_1_1MultiModel.html#2af3f8dc10dfdae0ddc8160a9f36aaee" title="posterior density">posterior</a>().mean(), A (0)-><a class="code" href="classbdm_1_1MultiModel.html#2af3f8dc10dfdae0ddc8160a9f36aaee" title="posterior density">posterior</a>()._R()); |
| 261 | <a name="l00312"></a>00312 } |
| 262 | <a name="l00313"></a><a class="code" href="classbdm_1_1MultiModel.html#a915deeddb0e94c337d02ebc0abe535e">00313</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MultiModel.html#a915deeddb0e94c337d02ebc0abe535e" title="Incremental Bayes rule.">bayes</a> (<span class="keyword">const</span> vec &dt) { |
| 263 | <a name="l00314"></a>00314 <span class="keywordtype">int</span> n = <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a>.length(); |
| 264 | <a name="l00315"></a>00315 <span class="keywordtype">int</span> i; |
| 265 | <a name="l00316"></a>00316 <span class="keywordflow">for</span> (i = 0; i < n; i++) { |
| 266 | <a name="l00317"></a>00317 <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a> (i)->bayes (dt); |
| 267 | <a name="l00318"></a>00318 <a class="code" href="classbdm_1_1MultiModel.html#7b4012fc2208ce4ddd5c0d1fe69d7634" title="cache of model lls">_lls</a> (i) = <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a> (i)->_ll(); |
| 268 | <a name="l00319"></a>00319 } |
| 269 | <a name="l00320"></a>00320 <span class="keywordtype">double</span> mlls = max (<a class="code" href="classbdm_1_1MultiModel.html#7b4012fc2208ce4ddd5c0d1fe69d7634" title="cache of model lls">_lls</a>); |
| 270 | <a name="l00321"></a>00321 <a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a" title="vector of model weights">w</a> = exp (<a class="code" href="classbdm_1_1MultiModel.html#7b4012fc2208ce4ddd5c0d1fe69d7634" title="cache of model lls">_lls</a> - mlls); |
| 271 | <a name="l00322"></a>00322 <a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a" title="vector of model weights">w</a> /= sum (<a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a" title="vector of model weights">w</a>); <span class="comment">//normalization</span> |
| 272 | <a name="l00323"></a>00323 <span class="comment">//set statistics</span> |
| 273 | <a name="l00324"></a>00324 <span class="keywordflow">switch</span> (<a class="code" href="classbdm_1_1MultiModel.html#9b56bcde4664bd53f8995d7ee7ed415c" title="type of switching policy [1=maximum,2=...]">policy</a>) { |
| 274 | <a name="l00325"></a>00325 <span class="keywordflow">case</span> 1: { |
| 275 | <a name="l00326"></a>00326 <span class="keywordtype">int</span> mi = max_index (<a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a" title="vector of model weights">w</a>); |
| 276 | <a name="l00327"></a>00327 <span class="keyword">const</span> <a class="code" href="classbdm_1_1enorm.html">enorm<chmat></a> &st = <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a> (mi)->posterior() ; |
| 277 | <a name="l00328"></a>00328 <a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>.<a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> (st.<a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600" title="return expected value">mean</a>(), st.<a class="code" href="classbdm_1_1enorm.html#81d81e35e57c9f194bde248e3affcf1f">_R</a>()); |
| 278 | <a name="l00329"></a>00329 } |
| 279 | <a name="l00330"></a>00330 <span class="keywordflow">break</span>; |
| 280 | <a name="l00331"></a>00331 <span class="keywordflow">default</span>: |
| 281 | <a name="l00332"></a>00332 <a class="code" href="bdmerror_8h.html#7c43f3a72afe68ab0c85663a1bb3521a" title="Unconditionally throw std::runtime_error.">bdm_error</a> (<span class="stringliteral">"unknown policy"</span>); |
| 282 | <a name="l00333"></a>00333 } |
| 283 | <a name="l00334"></a>00334 <span class="comment">// copy result to all models</span> |
| 284 | <a name="l00335"></a>00335 <span class="keywordflow">for</span> (i = 0; i < n; i++) { |
| 285 | <a name="l00336"></a>00336 <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a> (i)->set_statistics (<a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>.<a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600" title="return expected value">mean</a>(), <a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>.<a class="code" href="classbdm_1_1enorm.html#81d81e35e57c9f194bde248e3affcf1f">_R</a>()); |
| 286 | <a name="l00337"></a>00337 } |
| 287 | <a name="l00338"></a>00338 } |
| 288 | <a name="l00340"></a><a class="code" href="classbdm_1_1MultiModel.html#2af3f8dc10dfdae0ddc8160a9f36aaee">00340</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1enorm.html">enorm<chmat></a>& <a class="code" href="classbdm_1_1MultiModel.html#2af3f8dc10dfdae0ddc8160a9f36aaee" title="posterior density">posterior</a>()<span class="keyword"> const </span>{ |
| 289 | <a name="l00341"></a>00341 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>; |
| 290 | <a name="l00342"></a>00342 } |
| 291 | <a name="l00343"></a>00343 |
| 292 | <a name="l00344"></a>00344 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MultiModel.html#7bd320fa2540883749b3f83cf2261878" title="This method arrange instance properties according the data stored in the Setting...">from_setting</a> (<span class="keyword">const</span> Setting &<span class="keyword">set</span>); |
| 293 | <a name="l00345"></a>00345 |
| 294 | <a name="l00346"></a>00346 <span class="comment">// TODO dodelat void to_setting( Setting &set ) const;</span> |
| 295 | <a name="l00347"></a>00347 |
| 296 | <a name="l00348"></a>00348 }; |
| 297 | <a name="l00349"></a>00349 |
| 298 | <a name="l00350"></a>00350 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a> (MultiModel); |
| 299 | <a name="l00351"></a>00351 SHAREDPTR (MultiModel); |
| 300 | <a name="l00352"></a>00352 |
297 | | <a name="l00355"></a>00355 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
298 | | <a name="l00356"></a><a class="code" href="classbdm_1_1Kalman.html#4a39330c14eff8d13179e868a1d1aa8c">00356</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1Kalman.html#4a39330c14eff8d13179e868a1d1aa8c" title="Here dt = [yt;ut] of appropriate dimensions.">Kalman<sq_T>::bayes</a> ( <span class="keyword">const</span> vec &dt ) { |
299 | | <a name="l00357"></a>00357 it_assert_debug ( dt.length() == ( <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> + <a class="code" href="classbdm_1_1Kalman.html#c5136ef617f6ac0e426bea222755d92b" title="cache of rvu.count()">dimu</a> ), <span class="stringliteral">"KalmanFull::bayes wrong size of dt"</span> ); |
300 | | <a name="l00358"></a>00358 |
301 | | <a name="l00359"></a>00359 sq_T iRy ( <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> ); |
302 | | <a name="l00360"></a>00360 vec u = dt.get ( <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a>, <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> + <a class="code" href="classbdm_1_1Kalman.html#c5136ef617f6ac0e426bea222755d92b" title="cache of rvu.count()">dimu</a> - 1 ); |
303 | | <a name="l00361"></a>00361 vec y = dt.get ( 0, <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> - 1 ); |
304 | | <a name="l00362"></a>00362 <span class="comment">//Time update</span> |
305 | | <a name="l00363"></a>00363 <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a> = <a class="code" href="classbdm_1_1Kalman.html#0a2072e2090c10fac74ad30a023a4ace" title="Matrix A.">A</a> * <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a> + <a class="code" href="classbdm_1_1Kalman.html#5977b2c81857948a35105f0e7840203c" title="Matrix B.">B</a> * u; |
306 | | <a name="l00364"></a>00364 <span class="comment">//P = A*P*A.transpose() + Q; in sq_T</span> |
307 | | <a name="l00365"></a>00365 <a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed" title="cache of est.R">_P</a>.mult_sym ( <a class="code" href="classbdm_1_1Kalman.html#0a2072e2090c10fac74ad30a023a4ace" title="Matrix A.">A</a> ); |
308 | | <a name="l00366"></a>00366 <a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed" title="cache of est.R">_P</a> += <a class="code" href="classbdm_1_1Kalman.html#70f8bf19e81b532c60fd3a7a152425ee" title="Matrix Q in square-root form.">Q</a>; |
309 | | <a name="l00367"></a>00367 |
310 | | <a name="l00368"></a>00368 <span class="comment">//Data update</span> |
311 | | <a name="l00369"></a>00369 <span class="comment">//_Ry = C*P*C.transpose() + R; in sq_T</span> |
312 | | <a name="l00370"></a>00370 <a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed" title="cache of est.R">_P</a>.mult_sym ( <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a>, <a class="code" href="classbdm_1_1Kalman.html#2dd268f2d7fbe6382cb8825a1114192a" title="cache of fy.R">_Ry</a> ); |
313 | | <a name="l00371"></a>00371 <a class="code" href="classbdm_1_1Kalman.html#2dd268f2d7fbe6382cb8825a1114192a" title="cache of fy.R">_Ry</a> += <a class="code" href="classbdm_1_1Kalman.html#475b088287cdfbba4dc60a3d027728b7" title="Matrix R in square-root form.">R</a>; |
314 | | <a name="l00372"></a>00372 |
315 | | <a name="l00373"></a>00373 mat Pfull = <a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed" title="cache of est.R">_P</a>.to_mat(); |
316 | | <a name="l00374"></a>00374 |
317 | | <a name="l00375"></a>00375 <a class="code" href="classbdm_1_1Kalman.html#2dd268f2d7fbe6382cb8825a1114192a" title="cache of fy.R">_Ry</a>.inv ( iRy ); <span class="comment">// result is in _iRy;</span> |
318 | | <a name="l00376"></a>00376 <a class="code" href="classbdm_1_1Kalman.html#bd69dfb802465f22dd84d73a180d5c92" title="placeholder for Kalman gain">_K</a> = Pfull * <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a>.transpose() * ( iRy.to_mat() ); |
319 | | <a name="l00377"></a>00377 |
320 | | <a name="l00378"></a>00378 sq_T pom ( ( <span class="keywordtype">int</span> ) Pfull.rows() ); |
321 | | <a name="l00379"></a>00379 iRy.mult_sym_t ( <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a>*Pfull, pom ); |
322 | | <a name="l00380"></a>00380 ( <a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed" title="cache of est.R">_P</a> ) -= pom; <span class="comment">// P = P -PC'iRy*CP;</span> |
323 | | <a name="l00381"></a>00381 ( <a class="code" href="classbdm_1_1Kalman.html#c249d45258c8578b13858ad3e7b729b1" title="cache of fy.mu">_yp</a> ) = <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a> * <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a> + <a class="code" href="classbdm_1_1Kalman.html#7b56ac423d0654b5755e4f852a870456" title="Matrix D.">D</a> * u; <span class="comment">//y prediction</span> |
324 | | <a name="l00382"></a>00382 ( <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a> ) += <a class="code" href="classbdm_1_1Kalman.html#bd69dfb802465f22dd84d73a180d5c92" title="placeholder for Kalman gain">_K</a> * ( y - <a class="code" href="classbdm_1_1Kalman.html#c249d45258c8578b13858ad3e7b729b1" title="cache of fy.mu">_yp</a> ); |
325 | | <a name="l00383"></a>00383 |
326 | | <a name="l00384"></a>00384 |
327 | | <a name="l00385"></a>00385 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> == <span class="keyword">true</span> ) { <span class="comment">//likelihood of observation y</span> |
328 | | <a name="l00386"></a>00386 <a class="code" href="classbdm_1_1BM.html#4064b6559d962633e4372b12f4cd204a" title="Logarithm of marginalized data likelihood.">ll</a> = <a class="code" href="classbdm_1_1Kalman.html#ba555c394c429f6831c9bbabfa2c944c" title="preditive density on $y_t$">fy</a>.evallog ( y ); |
329 | | <a name="l00387"></a>00387 } |
330 | | <a name="l00388"></a>00388 |
331 | | <a name="l00389"></a>00389 <span class="comment">//cout << "y: " << y-(*_yp) <<" R: " << _Ry->to_mat() << " iR: " << _iRy->to_mat() << " ll: " << ll <<endl;</span> |
332 | | <a name="l00390"></a>00390 |
333 | | <a name="l00391"></a>00391 }; |
334 | | <a name="l00392"></a>00392 |
335 | | <a name="l00400"></a><a class="code" href="classbdm_1_1MultiModel.html">00400</a> <span class="keyword">class </span><a class="code" href="classbdm_1_1MultiModel.html" title="(Switching) Multiple Model The model runs several models in parallel and evaluates...">MultiModel</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> { |
336 | | <a name="l00401"></a>00401 <span class="keyword">protected</span>: |
337 | | <a name="l00403"></a><a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93">00403</a> Array<EKFCh*> <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a>; |
338 | | <a name="l00405"></a><a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a">00405</a> vec <a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a" title="vector of model weights">w</a>; |
339 | | <a name="l00407"></a><a class="code" href="classbdm_1_1MultiModel.html#7b4012fc2208ce4ddd5c0d1fe69d7634">00407</a> vec <a class="code" href="classbdm_1_1MultiModel.html#7b4012fc2208ce4ddd5c0d1fe69d7634" title="cache of model lls">_lls</a>; |
340 | | <a name="l00409"></a><a class="code" href="classbdm_1_1MultiModel.html#9b56bcde4664bd53f8995d7ee7ed415c">00409</a> <span class="keywordtype">int</span> <a class="code" href="classbdm_1_1MultiModel.html#9b56bcde4664bd53f8995d7ee7ed415c" title="type of switching policy [1=maximum,2=...]">policy</a>; |
341 | | <a name="l00411"></a><a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b">00411</a> <a class="code" href="classbdm_1_1enorm.html">enorm<chmat></a> <a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>; |
342 | | <a name="l00412"></a>00412 <span class="keyword">public</span>: |
343 | | <a name="l00413"></a>00413 <span class="keywordtype">void</span> set_parameters ( Array<EKFCh*> A, <span class="keywordtype">int</span> pol0 = 1 ) { |
344 | | <a name="l00414"></a>00414 <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a> = A;<span class="comment">//TODO: test if evalll is set</span> |
345 | | <a name="l00415"></a>00415 <a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a" title="vector of model weights">w</a>.set_length ( A.length() ); |
346 | | <a name="l00416"></a>00416 <a class="code" href="classbdm_1_1MultiModel.html#7b4012fc2208ce4ddd5c0d1fe69d7634" title="cache of model lls">_lls</a>.set_length ( A.length() ); |
347 | | <a name="l00417"></a>00417 <a class="code" href="classbdm_1_1MultiModel.html#9b56bcde4664bd53f8995d7ee7ed415c" title="type of switching policy [1=maximum,2=...]">policy</a> = pol0; |
348 | | <a name="l00418"></a>00418 |
349 | | <a name="l00419"></a>00419 <a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>.<a class="code" href="classbdm_1_1epdf.html#f423e28448dbb69ef4905295ec8de8ff" title="Name its rv.">set_rv</a> ( <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> ( <span class="stringliteral">"MM"</span>, A ( 0 )-><a class="code" href="classbdm_1_1MultiModel.html#2af3f8dc10dfdae0ddc8160a9f36aaee" title="posterior density">posterior</a>().dimension(), 0 ) ); |
350 | | <a name="l00420"></a>00420 <a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>.<a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> ( A ( 0 )-><a class="code" href="classbdm_1_1MultiModel.html#2af3f8dc10dfdae0ddc8160a9f36aaee" title="posterior density">posterior</a>().mean(), A ( 0 )-><a class="code" href="classbdm_1_1MultiModel.html#2af3f8dc10dfdae0ddc8160a9f36aaee" title="posterior density">posterior</a>()._R() ); |
351 | | <a name="l00421"></a>00421 } |
352 | | <a name="l00422"></a><a class="code" href="classbdm_1_1MultiModel.html#a915deeddb0e94c337d02ebc0abe535e">00422</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MultiModel.html#a915deeddb0e94c337d02ebc0abe535e" title="Incremental Bayes rule.">bayes</a> ( <span class="keyword">const</span> vec &dt ) { |
353 | | <a name="l00423"></a>00423 <span class="keywordtype">int</span> n = <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a>.length(); |
354 | | <a name="l00424"></a>00424 <span class="keywordtype">int</span> i; |
355 | | <a name="l00425"></a>00425 <span class="keywordflow">for</span> ( i = 0; i < n; i++ ) { |
356 | | <a name="l00426"></a>00426 <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a> ( i )->bayes ( dt ); |
357 | | <a name="l00427"></a>00427 <a class="code" href="classbdm_1_1MultiModel.html#7b4012fc2208ce4ddd5c0d1fe69d7634" title="cache of model lls">_lls</a> ( i ) = <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a> ( i )->_ll(); |
358 | | <a name="l00428"></a>00428 } |
359 | | <a name="l00429"></a>00429 <span class="keywordtype">double</span> mlls = max ( <a class="code" href="classbdm_1_1MultiModel.html#7b4012fc2208ce4ddd5c0d1fe69d7634" title="cache of model lls">_lls</a> ); |
360 | | <a name="l00430"></a>00430 <a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a" title="vector of model weights">w</a> = exp ( <a class="code" href="classbdm_1_1MultiModel.html#7b4012fc2208ce4ddd5c0d1fe69d7634" title="cache of model lls">_lls</a> - mlls ); |
361 | | <a name="l00431"></a>00431 <a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a" title="vector of model weights">w</a> /= sum ( <a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a" title="vector of model weights">w</a> ); <span class="comment">//normalization</span> |
362 | | <a name="l00432"></a>00432 <span class="comment">//set statistics</span> |
363 | | <a name="l00433"></a>00433 <span class="keywordflow">switch</span> ( <a class="code" href="classbdm_1_1MultiModel.html#9b56bcde4664bd53f8995d7ee7ed415c" title="type of switching policy [1=maximum,2=...]">policy</a> ) { |
364 | | <a name="l00434"></a>00434 <span class="keywordflow">case</span> 1: { |
365 | | <a name="l00435"></a>00435 <span class="keywordtype">int</span> mi = max_index ( <a class="code" href="classbdm_1_1MultiModel.html#ef85ea61575bffa8beac8040869ee47a" title="vector of model weights">w</a> ); |
366 | | <a name="l00436"></a>00436 <span class="keyword">const</span> <a class="code" href="classbdm_1_1enorm.html">enorm<chmat></a> &st = <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a> ( mi )->posterior() ; |
367 | | <a name="l00437"></a>00437 <a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>.<a class="code" href="classbdm_1_1enorm.html#b8322f2c11560871dd922c660f4771bb">set_parameters</a> ( st.<a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600" title="return expected value">mean</a>(), st.<a class="code" href="classbdm_1_1enorm.html#81d81e35e57c9f194bde248e3affcf1f">_R</a>() ); |
368 | | <a name="l00438"></a>00438 } |
369 | | <a name="l00439"></a>00439 <span class="keywordflow">break</span>; |
370 | | <a name="l00440"></a>00440 <span class="keywordflow">default</span>: |
371 | | <a name="l00441"></a>00441 it_error ( <span class="stringliteral">"unknown policy"</span> ); |
372 | | <a name="l00442"></a>00442 } |
373 | | <a name="l00443"></a>00443 <span class="comment">// copy result to all models</span> |
374 | | <a name="l00444"></a>00444 <span class="keywordflow">for</span> ( i = 0; i < n; i++ ) { |
375 | | <a name="l00445"></a>00445 <a class="code" href="classbdm_1_1MultiModel.html#33de5d07ee774070632de8963b5d4c93" title="List of models between which we switch.">Models</a> ( i )->set_statistics ( <a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>.<a class="code" href="classbdm_1_1enorm.html#b2fa2915c35366392fe9bb022ca1a600" title="return expected value">mean</a>(), <a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>.<a class="code" href="classbdm_1_1enorm.html#81d81e35e57c9f194bde248e3affcf1f">_R</a>() ); |
376 | | <a name="l00446"></a>00446 } |
377 | | <a name="l00447"></a>00447 } |
378 | | <a name="l00449"></a><a class="code" href="classbdm_1_1MultiModel.html#2af3f8dc10dfdae0ddc8160a9f36aaee">00449</a> <span class="keyword">const</span> <a class="code" href="classbdm_1_1enorm.html">enorm<chmat></a>& <a class="code" href="classbdm_1_1MultiModel.html#2af3f8dc10dfdae0ddc8160a9f36aaee" title="posterior density">posterior</a>()<span class="keyword"> const </span>{ |
379 | | <a name="l00450"></a>00450 <span class="keywordflow">return</span> <a class="code" href="classbdm_1_1MultiModel.html#d665551d045b1a1055eeb9185558ff0b" title="internal statistics">est</a>; |
380 | | <a name="l00451"></a>00451 } |
381 | | <a name="l00452"></a>00452 |
382 | | <a name="l00453"></a>00453 <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1MultiModel.html#7bd320fa2540883749b3f83cf2261878" title="This method arrange instance properties according the data stored in the Setting...">from_setting</a> ( <span class="keyword">const</span> Setting &<span class="keyword">set</span> ); |
383 | | <a name="l00454"></a>00454 |
384 | | <a name="l00455"></a>00455 <span class="comment">// TODO dodelat void to_setting( Setting &set ) const;</span> |
385 | | <a name="l00456"></a>00456 |
386 | | <a name="l00457"></a>00457 }; |
387 | | <a name="l00458"></a>00458 |
388 | | <a name="l00459"></a>00459 <a class="code" href="user__info_8h.html#4f9de2f17e844047726487b99def99c6" title="Macro for registration of class into map of user-infos, registered class is scriptable...">UIREGISTER</a> ( MultiModel ); |
389 | | <a name="l00460"></a>00460 SHAREDPTR ( MultiModel ); |
390 | | <a name="l00461"></a>00461 |
391 | | <a name="l00462"></a>00462 |
392 | | <a name="l00463"></a>00463 |
393 | | <a name="l00464"></a>00464 <span class="comment">//TODO why not const pointer??</span> |
394 | | <a name="l00465"></a>00465 |
395 | | <a name="l00466"></a>00466 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
396 | | <a name="l00467"></a><a class="code" href="classbdm_1_1EKF.html#d087a8bb408d26ac4f5c542746b81059">00467</a> <a class="code" href="classbdm_1_1EKF.html#d087a8bb408d26ac4f5c542746b81059" title="Default constructor.">EKF<sq_T>::EKF</a> ( <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rvx0, <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rvy0, <a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> rvu0 ) : <a class="code" href="classbdm_1_1Kalman.html" title="Kalman filter with covariance matrices in square root form.">Kalman</a><sq_T> ( rvx0, rvy0, rvu0 ) {} |
397 | | <a name="l00468"></a>00468 |
398 | | <a name="l00469"></a>00469 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
399 | | <a name="l00470"></a><a class="code" href="classbdm_1_1EKF.html#00fec1a0a6a467eb83fb36c65eba7bcb">00470</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1EKF.html#00fec1a0a6a467eb83fb36c65eba7bcb" title="Set nonlinear functions for mean values and covariance matrices.">EKF<sq_T>::set_parameters</a> ( <a class="code" href="classbdm_1_1diffbifn.html" title="Class representing a differentiable function of two variables .">diffbifn</a>* pfxu0, <a class="code" href="classbdm_1_1diffbifn.html" title="Class representing a differentiable function of two variables .">diffbifn</a>* phxu0, <span class="keyword">const</span> sq_T Q0, <span class="keyword">const</span> sq_T R0 ) { |
400 | | <a name="l00471"></a>00471 pfxu = pfxu0; |
401 | | <a name="l00472"></a>00472 phxu = phxu0; |
402 | | <a name="l00473"></a>00473 |
403 | | <a name="l00474"></a>00474 <span class="comment">//initialize matrices A C, later, these will be only updated!</span> |
404 | | <a name="l00475"></a>00475 pfxu-><a class="code" href="classbdm_1_1diffbifn.html#651184f808a35f236dbfea21aca1b6ac" title="Evaluates and writes result into A .">dfdx_cond</a> ( <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a>, zeros ( <a class="code" href="classbdm_1_1Kalman.html#c5136ef617f6ac0e426bea222755d92b" title="cache of rvu.count()">dimu</a> ), <a class="code" href="classbdm_1_1Kalman.html#0a2072e2090c10fac74ad30a023a4ace" title="Matrix A.">A</a>, <span class="keyword">true</span> ); |
405 | | <a name="l00476"></a>00476 <span class="comment">// pfxu->dfdu_cond ( *_mu,zeros ( dimu ),B,true );</span> |
406 | | <a name="l00477"></a>00477 <a class="code" href="classbdm_1_1Kalman.html#5977b2c81857948a35105f0e7840203c" title="Matrix B.">B</a>.clear(); |
407 | | <a name="l00478"></a>00478 phxu-><a class="code" href="classbdm_1_1diffbifn.html#651184f808a35f236dbfea21aca1b6ac" title="Evaluates and writes result into A .">dfdx_cond</a> ( <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a>, zeros ( <a class="code" href="classbdm_1_1Kalman.html#c5136ef617f6ac0e426bea222755d92b" title="cache of rvu.count()">dimu</a> ), <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a>, <span class="keyword">true</span> ); |
408 | | <a name="l00479"></a>00479 <span class="comment">// phxu->dfdu_cond ( *_mu,zeros ( dimu ),D,true );</span> |
409 | | <a name="l00480"></a>00480 <a class="code" href="classbdm_1_1Kalman.html#7b56ac423d0654b5755e4f852a870456" title="Matrix D.">D</a>.clear(); |
410 | | <a name="l00481"></a>00481 |
411 | | <a name="l00482"></a>00482 <a class="code" href="classbdm_1_1Kalman.html#475b088287cdfbba4dc60a3d027728b7" title="Matrix R in square-root form.">R</a> = R0; |
412 | | <a name="l00483"></a>00483 <a class="code" href="classbdm_1_1Kalman.html#70f8bf19e81b532c60fd3a7a152425ee" title="Matrix Q in square-root form.">Q</a> = Q0; |
413 | | <a name="l00484"></a>00484 } |
414 | | <a name="l00485"></a>00485 |
415 | | <a name="l00486"></a>00486 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
416 | | <a name="l00487"></a><a class="code" href="classbdm_1_1EKF.html#3fb182ecc29b10ca1163cecbf3bcccfa">00487</a> <span class="keywordtype">void</span> <a class="code" href="classbdm_1_1EKF.html#3fb182ecc29b10ca1163cecbf3bcccfa" title="Here dt = [yt;ut] of appropriate dimensions.">EKF<sq_T>::bayes</a> ( <span class="keyword">const</span> vec &dt ) { |
417 | | <a name="l00488"></a>00488 it_assert_debug ( dt.length() == ( <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> + <a class="code" href="classbdm_1_1Kalman.html#c5136ef617f6ac0e426bea222755d92b" title="cache of rvu.count()">dimu</a> ), <span class="stringliteral">"KalmanFull::bayes wrong size of dt"</span> ); |
418 | | <a name="l00489"></a>00489 |
419 | | <a name="l00490"></a>00490 sq_T iRy ( <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a>, <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> ); |
420 | | <a name="l00491"></a>00491 vec u = dt.get ( <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a>, <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> + <a class="code" href="classbdm_1_1Kalman.html#c5136ef617f6ac0e426bea222755d92b" title="cache of rvu.count()">dimu</a> - 1 ); |
421 | | <a name="l00492"></a>00492 vec y = dt.get ( 0, <a class="code" href="classbdm_1_1Kalman.html#d2c36ba01760bf207b985bf321b7817f" title="cache of rvy.count()">dimy</a> - 1 ); |
422 | | <a name="l00493"></a>00493 <span class="comment">//Time update</span> |
423 | | <a name="l00494"></a>00494 <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a> = pfxu-><a class="code" href="classbdm_1_1diffbifn.html#188f31066bd72e1bf0ddacd1eb0e6af3" title="Evaluates (VS: Do we really need common eval? ).">eval</a> ( <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a>, u ); |
424 | | <a name="l00495"></a>00495 pfxu-><a class="code" href="classbdm_1_1diffbifn.html#651184f808a35f236dbfea21aca1b6ac" title="Evaluates and writes result into A .">dfdx_cond</a> ( <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a>, u, <a class="code" href="classbdm_1_1Kalman.html#0a2072e2090c10fac74ad30a023a4ace" title="Matrix A.">A</a>, <span class="keyword">false</span> ); <span class="comment">//update A by a derivative of fx</span> |
425 | | <a name="l00496"></a>00496 |
426 | | <a name="l00497"></a>00497 <span class="comment">//P = A*P*A.transpose() + Q; in sq_T</span> |
427 | | <a name="l00498"></a>00498 <a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed" title="cache of est.R">_P</a>.<a class="code" href="classbdm_1_1fsqmat.html#fca713af3f74677fd7fbafe723590112" title="Inplace symmetric multiplication by a SQUARE matrix , i.e. .">mult_sym</a> ( <a class="code" href="classbdm_1_1Kalman.html#0a2072e2090c10fac74ad30a023a4ace" title="Matrix A.">A</a> ); |
428 | | <a name="l00499"></a>00499 <a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed" title="cache of est.R">_P</a> += <a class="code" href="classbdm_1_1Kalman.html#70f8bf19e81b532c60fd3a7a152425ee" title="Matrix Q in square-root form.">Q</a>; |
429 | | <a name="l00500"></a>00500 |
430 | | <a name="l00501"></a>00501 <span class="comment">//Data update</span> |
431 | | <a name="l00502"></a>00502 phxu-><a class="code" href="classbdm_1_1diffbifn.html#651184f808a35f236dbfea21aca1b6ac" title="Evaluates and writes result into A .">dfdx_cond</a> ( <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a>, u, <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a>, <span class="keyword">false</span> ); <span class="comment">//update C by a derivative hx</span> |
432 | | <a name="l00503"></a>00503 <span class="comment">//_Ry = C*P*C.transpose() + R; in sq_T</span> |
433 | | <a name="l00504"></a>00504 <a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed" title="cache of est.R">_P</a>.<a class="code" href="classbdm_1_1fsqmat.html#fca713af3f74677fd7fbafe723590112" title="Inplace symmetric multiplication by a SQUARE matrix , i.e. .">mult_sym</a> ( <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a>, <a class="code" href="classbdm_1_1Kalman.html#2dd268f2d7fbe6382cb8825a1114192a" title="cache of fy.R">_Ry</a> ); |
434 | | <a name="l00505"></a>00505 ( <a class="code" href="classbdm_1_1Kalman.html#2dd268f2d7fbe6382cb8825a1114192a" title="cache of fy.R">_Ry</a> ) += <a class="code" href="classbdm_1_1Kalman.html#475b088287cdfbba4dc60a3d027728b7" title="Matrix R in square-root form.">R</a>; |
435 | | <a name="l00506"></a>00506 |
436 | | <a name="l00507"></a>00507 mat Pfull = <a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed" title="cache of est.R">_P</a>.<a class="code" href="classbdm_1_1fsqmat.html#5c27d47cd0fa7ae686d4519f89a3c9b0" title="Conversion to full matrix.">to_mat</a>(); |
437 | | <a name="l00508"></a>00508 |
438 | | <a name="l00509"></a>00509 <a class="code" href="classbdm_1_1Kalman.html#2dd268f2d7fbe6382cb8825a1114192a" title="cache of fy.R">_Ry</a>.<a class="code" href="classbdm_1_1fsqmat.html#d17495888ab35e09ebb9b4e789f586d5" title="Matrix inversion preserving the chosen form.">inv</a> ( iRy ); <span class="comment">// result is in _iRy;</span> |
439 | | <a name="l00510"></a>00510 <a class="code" href="classbdm_1_1Kalman.html#bd69dfb802465f22dd84d73a180d5c92" title="placeholder for Kalman gain">_K</a> = Pfull * <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a>.transpose() * ( iRy.to_mat() ); |
440 | | <a name="l00511"></a>00511 |
441 | | <a name="l00512"></a>00512 sq_T pom ( ( <span class="keywordtype">int</span> ) Pfull.rows() ); |
442 | | <a name="l00513"></a>00513 iRy.mult_sym_t ( <a class="code" href="classbdm_1_1Kalman.html#818eba63a23972786a4579ad30294177" title="Matrix C.">C</a>*Pfull, pom ); |
443 | | <a name="l00514"></a>00514 ( <a class="code" href="classbdm_1_1Kalman.html#00c27b0bf324f0018497921ca23c71ed" title="cache of est.R">_P</a> ) -= pom; <span class="comment">// P = P -PC'iRy*CP;</span> |
444 | | <a name="l00515"></a>00515 <a class="code" href="classbdm_1_1Kalman.html#c249d45258c8578b13858ad3e7b729b1" title="cache of fy.mu">_yp</a> = phxu-><a class="code" href="classbdm_1_1diffbifn.html#188f31066bd72e1bf0ddacd1eb0e6af3" title="Evaluates (VS: Do we really need common eval? ).">eval</a> ( <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a>, u ); <span class="comment">//y prediction</span> |
445 | | <a name="l00516"></a>00516 ( <a class="code" href="classbdm_1_1Kalman.html#fa172078091e45561343fa513dd573b0" title="cache of est.mu">_mu</a> ) += <a class="code" href="classbdm_1_1Kalman.html#bd69dfb802465f22dd84d73a180d5c92" title="placeholder for Kalman gain">_K</a> * ( y - <a class="code" href="classbdm_1_1Kalman.html#c249d45258c8578b13858ad3e7b729b1" title="cache of fy.mu">_yp</a> ); |
446 | | <a name="l00517"></a>00517 |
447 | | <a name="l00518"></a>00518 <span class="keywordflow">if</span> ( <a class="code" href="classbdm_1_1BM.html#faff0ad12556fe7dc0e2807d4fd938ee" title="If true, the filter will compute likelihood of the data record and store it in ll...">evalll</a> == <span class="keyword">true</span> ) { |
448 | | <a name="l00519"></a>00519 <a class="code" href="classbdm_1_1BM.html#4064b6559d962633e4372b12f4cd204a" title="Logarithm of marginalized data likelihood.">ll</a> += <a class="code" href="classbdm_1_1Kalman.html#ba555c394c429f6831c9bbabfa2c944c" title="preditive density on $y_t$">fy</a>.<a class="code" href="classbdm_1_1eEF.html#a36d06ecdd6f4c79dc122510eaccc692" title="Evaluate normalized log-probability.">evallog</a> ( y ); |
449 | | <a name="l00520"></a>00520 } |
450 | | <a name="l00521"></a>00521 }; |
451 | | <a name="l00522"></a>00522 |
452 | | <a name="l00523"></a>00523 |
453 | | <a name="l00524"></a>00524 } |
454 | | <a name="l00525"></a>00525 <span class="preprocessor">#endif // KF_H</span> |
455 | | <a name="l00526"></a>00526 <span class="preprocessor"></span> |
456 | | <a name="l00527"></a>00527 |
| 302 | <a name="l00361"></a>00361 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 303 | <a name="l00362"></a>00362 shared_ptr<StateSpace<fsqmat> > to_state_space(<span class="keyword">const</span> mlnorm<sq_T > &ml, ivec &theta_in_A, ivec &theta_in_C){ |
| 304 | <a name="l00363"></a>00363 <span class="comment">//get ids of yrv</span> |
| 305 | <a name="l00364"></a>00364 |
| 306 | <a name="l00365"></a>00365 ivec yids= unique(ml._rv()._ids()); <span class="comment">//yrv is now stored in _yrv</span> |
| 307 | <a name="l00366"></a>00366 ivec dids= unique(ml._rvc()._ids()); <span class="comment">//yrv is now stored in _yrv</span> |
| 308 | <a name="l00367"></a>00367 ivec uids=unique_complement(dids, yids); |
| 309 | <a name="l00368"></a>00368 |
| 310 | <a name="l00369"></a>00369 RV yrv_uni = RV(yids,zeros_i(yids.length())); |
| 311 | <a name="l00370"></a>00370 RV urv_uni = RV(uids,zeros_i(yids.length())); |
| 312 | <a name="l00371"></a>00371 <span class="comment">//We can do only 1d now... :(</span> |
| 313 | <a name="l00372"></a>00372 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a>(yrv_uni._dsize()==urv_uni._dsize()==1, <span class="stringliteral">"Only for SISO so far..."</span> ); |
| 314 | <a name="l00373"></a>00373 |
| 315 | <a name="l00374"></a>00374 RV xrv; <span class="comment">//empty</span> |
| 316 | <a name="l00375"></a>00375 RV Crv; <span class="comment">//empty</span> |
| 317 | <a name="l00376"></a>00376 <span class="keywordtype">int</span> td=ml._rvc().mintd(); |
| 318 | <a name="l00377"></a>00377 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> t=-1;t>=td;t--){ |
| 319 | <a name="l00378"></a>00378 xrv.add(yrv_uni); |
| 320 | <a name="l00379"></a>00379 Crv.add(urv_uni); |
| 321 | <a name="l00380"></a>00380 } |
| 322 | <a name="l00381"></a>00381 |
| 323 | <a name="l00382"></a>00382 <span class="keywordtype">int</span> dimx = xrv._dsize(); |
| 324 | <a name="l00383"></a>00383 |
| 325 | <a name="l00384"></a>00384 theta_in_A = ml._rv().dataind(xrv); |
| 326 | <a name="l00385"></a>00385 theta_in_C = ml._rvc().dataind(xrv); |
| 327 | <a name="l00386"></a>00386 <span class="comment">// some chcek of corretness</span> |
| 328 | <a name="l00387"></a>00387 |
| 329 | <a name="l00388"></a>00388 vec A1row = zeros(xrv._dsize()); |
| 330 | <a name="l00389"></a>00389 vec C1row = zeros(xrv._dsize()); |
| 331 | <a name="l00390"></a>00390 vec theta = ml._A().get_row(0); <span class="comment">// this </span> |
| 332 | <a name="l00391"></a>00391 set_subvector( A1row, theta_in_A, theta); |
| 333 | <a name="l00392"></a>00392 set_subvector( C1row, theta_in_C, theta); |
| 334 | <a name="l00393"></a>00393 |
| 335 | <a name="l00394"></a>00394 StateSpace<fsqmat> stsp=<span class="keyword">new</span> StateSpace<fsqmat>(); |
| 336 | <a name="l00395"></a>00395 mat A=zeros(dimx,dimx); |
| 337 | <a name="l00396"></a>00396 A.set_row(0,A1row); |
| 338 | <a name="l00397"></a>00397 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j=1; j<dimx; j++){A(j,j-1)=1.0;} <span class="comment">// off diagonal</span> |
| 339 | <a name="l00398"></a>00398 mat B=zeros(dimx,1); |
| 340 | <a name="l00399"></a>00399 B(0) = 1.0; |
| 341 | <a name="l00400"></a>00400 mat C=zeros(1,dimx); |
| 342 | <a name="l00401"></a>00401 C.set_row(0,C1row); |
| 343 | <a name="l00402"></a>00402 stsp.set_parameters(A,B,C,zeros(1,1), zeros(dimx,dimx), ml._R()); |
| 344 | <a name="l00403"></a>00403 <span class="keywordflow">return</span> stsp; |
| 345 | <a name="l00404"></a>00404 } |
| 346 | <a name="l00405"></a>00405 |
| 347 | <a name="l00407"></a>00407 |
| 348 | <a name="l00408"></a>00408 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 349 | <a name="l00409"></a>00409 <span class="keywordtype">void</span> StateSpace<sq_T>::set_parameters (<span class="keyword">const</span> mat &A0, <span class="keyword">const</span> mat &B0, <span class="keyword">const</span> mat &C0, <span class="keyword">const</span> mat &D0, <span class="keyword">const</span> sq_T &Q0, <span class="keyword">const</span> sq_T &R0) |
| 350 | <a name="l00410"></a>00410 { |
| 351 | <a name="l00411"></a>00411 dimx = A0.rows(); |
| 352 | <a name="l00412"></a>00412 dimu = B0.cols(); |
| 353 | <a name="l00413"></a>00413 dimy = C0.rows(); |
| 354 | <a name="l00414"></a>00414 |
| 355 | <a name="l00415"></a>00415 A = A0; |
| 356 | <a name="l00416"></a>00416 B = B0; |
| 357 | <a name="l00417"></a>00417 C = C0; |
| 358 | <a name="l00418"></a>00418 D = D0; |
| 359 | <a name="l00419"></a>00419 R = R0; |
| 360 | <a name="l00420"></a>00420 Q = Q0; |
| 361 | <a name="l00421"></a>00421 validate(); |
| 362 | <a name="l00422"></a>00422 } |
| 363 | <a name="l00423"></a>00423 |
| 364 | <a name="l00424"></a>00424 <span class="keyword">template</span><<span class="keyword">class</span> sq_T> |
| 365 | <a name="l00425"></a>00425 <span class="keywordtype">void</span> StateSpace<sq_T>::validate(){ |
| 366 | <a name="l00426"></a>00426 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> (A.cols() == dimx, <span class="stringliteral">"KalmanFull: A is not square"</span>); |
| 367 | <a name="l00427"></a>00427 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> (B.rows() == dimx, <span class="stringliteral">"KalmanFull: B is not compatible"</span>); |
| 368 | <a name="l00428"></a>00428 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> (C.cols() == dimx, <span class="stringliteral">"KalmanFull: C is not square"</span>); |
| 369 | <a name="l00429"></a>00429 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> ( (D.rows() == dimy) || (D.cols() == dimu), <span class="stringliteral">"KalmanFull: D is not compatible"</span>); |
| 370 | <a name="l00430"></a>00430 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> ( (Q.cols() == dimx) || (Q.rows() == dimx), <span class="stringliteral">"KalmanFull: Q is not compatible"</span>); |
| 371 | <a name="l00431"></a>00431 <a class="code" href="bdmerror_8h.html#89a0f906b242b79c5d3d342291b2cab4" title="Throw std::runtime_exception if t is not true and NDEBUG is not defined.">bdm_assert_debug</a> ( (R.cols() == dimy) || (R.rows() == dimy), <span class="stringliteral">"KalmanFull: R is not compatible"</span>); |
| 372 | <a name="l00432"></a>00432 } |
| 373 | <a name="l00433"></a>00433 |
| 374 | <a name="l00434"></a>00434 } |
| 375 | <a name="l00435"></a>00435 <span class="preprocessor">#endif // KF_H</span> |
| 376 | <a name="l00436"></a>00436 <span class="preprocessor"></span> |
| 377 | <a name="l00437"></a>00437 |