| 76 | <hr/><a name="_details"></a><h2>Detailed Description</h2> |
| 77 | <p><a class="el" href="classbdm_1_1Kalman.html" title="Common abstract base for Kalman filters.">Kalman</a> filter in square <a class="el" href="classbdm_1_1root.html" title="Root class of BDM objects.">root</a> form. </p> |
| 78 | <p>Trivial example: </p> |
| 79 | <div class="fragment"><pre class="fragment"><span class="preprocessor">#include "<a class="code" href="kalman_8h.html" title="Bayesian Filtering for linear Gaussian models (Kalman Filter) and extensions.">estim/kalman.h</a>"</span> |
| 80 | <span class="keyword">using namespace </span>bdm; |
| 81 | |
| 82 | <span class="comment">// estimation of AR(0) model</span> |
| 83 | <span class="keywordtype">int</span> main() { |
| 84 | <span class="comment">//dimensions</span> |
| 85 | <span class="keywordtype">int</span> dx = 3, dy = 3, du = 1; |
| 86 | <span class="comment">// matrices</span> |
| 87 | mat A = eye ( dx ); |
| 88 | mat B = zeros ( dx, du ); |
| 89 | mat C = eye ( dx ); |
| 90 | mat D = zeros ( dy, du ); |
| 91 | mat Q = eye ( dx ); |
| 92 | mat R = 0.1 * eye ( dy ); |
| 93 | <span class="comment">//prior</span> |
| 94 | mat P0 = 100 * eye ( dx ); |
| 95 | vec mu0 = zeros ( dx ); |
| 96 | <span class="comment">// Estimator</span> |
| 97 | KalmanCh KF; |
| 98 | KF.set_parameters ( A, B, C, D,<span class="comment">/*covariances*/</span> Q, R ); |
| 99 | KF.set_statistics ( mu0, P0 ); |
| 100 | <span class="comment">// Estimation loop</span> |
| 101 | <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < 100; i++ ) { |
| 102 | KF.bayes ( randn ( dx + du ) ); |
| 103 | } |
| 104 | <span class="comment">//print results</span> |
| 105 | cout << <span class="stringliteral">"Posterior estimate of x is: "</span> << endl; |
| 106 | cout << <span class="stringliteral">"mean: "</span> << KF.posterior().mean() << endl; |
| 107 | cout << <span class="stringliteral">"variance: "</span> << KF.posterior().variance() << endl; |
| 108 | } |
| 109 | </pre></div><p>Complete constructor: </p> |
260 | | <hr/><a name="_details"></a><h2>Detailed Description</h2> |
261 | | <p><a class="el" href="classbdm_1_1Kalman.html" title="Common abstract base for Kalman filters.">Kalman</a> filter in square <a class="el" href="classbdm_1_1root.html" title="Root class of BDM objects.">root</a> form. </p> |
262 | | <p>Trivial example: </p> |
263 | | <div class="fragment"><pre class="fragment"><span class="preprocessor">#include "<a class="code" href="kalman_8h.html" title="Bayesian Filtering for linear Gaussian models (Kalman Filter) and extensions.">estim/kalman.h</a>"</span> |
264 | | <span class="keyword">using namespace </span>bdm; |
265 | | |
266 | | <span class="comment">// estimation of AR(0) model</span> |
267 | | <span class="keywordtype">int</span> main() { |
268 | | <span class="comment">//dimensions</span> |
269 | | <span class="keywordtype">int</span> dx = 3, dy = 3, du = 1; |
270 | | <span class="comment">// matrices</span> |
271 | | mat A = eye ( dx ); |
272 | | mat B = zeros ( dx, du ); |
273 | | mat C = eye ( dx ); |
274 | | mat D = zeros ( dy, du ); |
275 | | mat Q = eye ( dx ); |
276 | | mat R = 0.1 * eye ( dy ); |
277 | | <span class="comment">//prior</span> |
278 | | mat P0 = 100 * eye ( dx ); |
279 | | vec mu0 = zeros ( dx ); |
280 | | <span class="comment">// Estimator</span> |
281 | | KalmanCh KF; |
282 | | KF.set_parameters ( A, B, C, D,<span class="comment">/*covariances*/</span> Q, R ); |
283 | | KF.set_statistics ( mu0, P0 ); |
284 | | <span class="comment">// Estimation loop</span> |
285 | | <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i = 0; i < 100; i++ ) { |
286 | | KF.bayes ( randn ( dx + du ) ); |
287 | | } |
288 | | <span class="comment">//print results</span> |
289 | | cout << <span class="stringliteral">"Posterior estimate of x is: "</span> << endl; |
290 | | cout << <span class="stringliteral">"mean: "</span> << KF.posterior().mean() << endl; |
291 | | cout << <span class="stringliteral">"variance: "</span> << KF.posterior().variance() << endl; |
292 | | } |
293 | | </pre></div><p>Complete constructor: </p> |