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 */
20 namespace Bayesian_filter
21 {
22 
23 
24 template <typename Error_base>
26 /* Indirect state filter
27  * Estimates state using an associated observation error filter
28  */
29 public:
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 
73 private:
74  Error_base& direct;
75 };
76 
77 
78 template <typename Error_base>
80 /* Indirect Kalman filter
81  * Estimates state using an associated observation error filter
82  */
83 public:
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 
140 private:
141  Error_base& direct;
142 };
143 
144 
145 }//namespace
146 #endif
void update()
Definition: indirect.hpp:131
void observe(O_model &h, const FM::Vec &z)
Definition: indirect.hpp:106
Definition: indirect.hpp:79
void predict(P_model &f)
Definition: indirect.hpp:99
Definition: indirect.hpp:25
Definition: bayesException.hpp:20
void predict(P_model &f)
Definition: indirect.hpp:37
Definition: bayesFlt.hpp:488
void observe_error(O_model &h, const FM::Vec &z_error)
Definition: indirect.hpp:58
void update()
Definition: indirect.hpp:67
FMVec< detail::BaseVector > Vec
Definition: uBLASmatrix.hpp:323
void observe(O_model &h, const FM::Vec &z)
Definition: indirect.hpp:44
FM::Vec x
Definition: bayesFlt.hpp:461
Definition: bayesFlt.hpp:452
Indirect_kalman_filter(Error_base &error_filter)
Definition: indirect.hpp:84
void init()
Definition: indirect.hpp:89
Indirect_state_filter(Error_base &error_filter)
Definition: indirect.hpp:30
void observe_error(O_model &h, const FM::Vec &z_error)
Definition: indirect.hpp:122