Bayes++ Bayesian Filtering Classes Release 2014.5 - Copyright (c) 2003,2004,2005,2006,2011,2012,2014 Michael Stevens
indirect.hpp
Go to the documentation of this file.
1#ifndef _BAYES_FILTER_INDIRECT
2#define _BAYES_FILTER_INDIRECT
3
4/*
5 * Bayes++ the Bayesian Filtering Library
6 * Copyright (c) 2002 Michael Stevens
7 * See accompanying Bayes++.htm for terms and conditions of use.
8 *
9 * $Id$
10 */
11
12/*
13 * Indirect Filter Adaptor
14 * Hides the details of the indirect operation of the filter
15 * The error filter uses the same linear models as the direct filter,
16 * observation error computation (subtraction) is linear!
17 */
18
19/* Filter namespace */
20namespace Bayesian_filter
21{
22
23
24template <typename Error_base>
26/* Indirect state filter
27 * Estimates state using an associated observation error filter
28 */
29public:
30 Indirect_state_filter (Error_base& error_filter)
31 : State_filter(error_filter.x.size()), direct(error_filter)
32 { // Construct and zero initial error filter
33 direct.x.clear();
34 }
35
36 template <typename P_model>
37 void predict (P_model& f)
38 {
39 x = f.f(x);
40 direct.predict(f); // May be optimised for linear f as x = 0
41 };
42
43 template <typename O_model>
44 void observe (O_model& h, const FM::Vec& z)
45 {
46 // Observe error (explicit temporary)
47 FM::Vec z_error(z.size());
48 z_error = h.h(x);
49 z_error -= z;
50 direct.observe (h, z_error);
51 // Update State estimate with error
52 x -= direct.x;
53 // Reset the error
54 direct.x.clear();
55 }
56
57 template <typename O_model>
58 void observe_error (O_model& h, const FM::Vec& z_error)
59 {
60 direct.observe (h, z_error);
61 // Update State estimate with error
62 x -= direct.x;
63 // Reset the error
64 direct.x.clear();
65 }
66
67 void update ()
68 /* Update filters state
69 Updates x(k|k)
70 */
71 {}
72
73private:
74 Error_base& direct;
75};
76
77
78template <typename Error_base>
80/* Indirect Kalman filter
81 * Estimates state using an associated observation error filter
82 */
83public:
84 Indirect_kalman_filter (Error_base& error_filter)
85 : Kalman_state_filter(error_filter.x.size()), direct(error_filter)
86 {
87 }
88
89 void init ()
90 /* Initialise from state and state covariance
91 */
92 {
93 direct.x.clear(); // Zero initial error
94 direct.X = X;
95 direct.init();
96 }
97
98 template <typename P_model>
99 void predict (P_model& f)
100 {
101 x = f.f(x);
102 direct.predict(f); // May be optimised for linear f as x = 0
103 };
104
105 template <typename O_model>
106 void observe (O_model& h, const FM::Vec& z)
107 {
108 // Observe error (explicit temporary)
109 FM::Vec z_error(z.size());
110 z_error = h.h(x);
111 z_error -= z;
112 direct.observe (h, z_error);
113 direct.update();
114 // Update State estimate with error
115 x -= direct.x;
116 // Reset the error
117 direct.x.clear();
118 direct.init ();
119 }
120
121 template <typename O_model>
122 void observe_error (O_model& h, const FM::Vec& z_error)
123 {
124 direct.observe (h, z_error);
125 // Update State estimate with error
126 x -= direct.x;
127 // Reset the error
128 direct.clear();
129 }
130
131 void update ()
132 /* Update filters state
133 Updates x(k|k)
134 */
135 {
136 direct.update();
137 X = direct.X;
138 }
139
140private:
141 Error_base& direct;
142};
143
144
145}//namespace
146#endif
Definition indirect.hpp:79
void init()
Definition indirect.hpp:89
void update()
Definition indirect.hpp:131
void observe_error(O_model &h, const FM::Vec &z_error)
Definition indirect.hpp:122
void observe(O_model &h, const FM::Vec &z)
Definition indirect.hpp:106
void predict(P_model &f)
Definition indirect.hpp:99
Indirect_kalman_filter(Error_base &error_filter)
Definition indirect.hpp:84
Definition indirect.hpp:25
void predict(P_model &f)
Definition indirect.hpp:37
Indirect_state_filter(Error_base &error_filter)
Definition indirect.hpp:30
void update()
Definition indirect.hpp:67
void observe(O_model &h, const FM::Vec &z)
Definition indirect.hpp:44
void observe_error(O_model &h, const FM::Vec &z_error)
Definition indirect.hpp:58
Definition bayesFlt.hpp:489
FM::SymMatrix X
Definition bayesFlt.hpp:491
Definition bayesFlt.hpp:453
FM::Vec x
Definition bayesFlt.hpp:461
FMVec< detail::BaseVector > Vec
Definition uBLASmatrix.hpp:323
Definition bayesException.hpp:21