ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkKalmanLinearEstimator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkKalmanLinearEstimator_h
19 #define itkKalmanLinearEstimator_h
20 
21 #include "itkMacro.h"
22 
23 #include "vnl/vnl_vector_fixed.h"
24 #include "vnl/vnl_matrix_fixed.h"
25 
26 namespace itk
27 {
41 template< typename T, unsigned int VEstimatorDimension >
43 {
44 public:
47  static constexpr unsigned int Dimension = VEstimatorDimension;
48 
51  using VectorType = vnl_vector_fixed< T, VEstimatorDimension >;
52 
55  using MatrixType = vnl_matrix_fixed< T, VEstimatorDimension, VEstimatorDimension >;
56 
61  using ValueType = T;
62 
67  void UpdateWithNewMeasure(const ValueType & newMeasure,
68  const VectorType & newPredictor);
69 
74  { m_Estimator = VectorType( T(0) ); }
75 
79  {
80  m_Variance.set_identity();
81  }
82 
89  void SetVariance(const ValueType & var = 1.0)
90  {
91  m_Variance.set_identity();
92  m_Variance *= var;
93  }
95 
101  void SetVariance(const MatrixType & m)
102  { m_Variance = m; }
103 
106  const VectorType & GetEstimator() const
107  { return m_Estimator; }
108 
111  const MatrixType & GetVariance() const
112  { return m_Variance; }
113 
114 private:
119  void UpdateVariance(const VectorType &);
120 
124 
132 };
133 
134 template< typename T, unsigned int VEstimatorDimension >
135 void
138  const VectorType & newPredictor)
139 {
140  ValueType measurePrediction = dot_product(newPredictor, m_Estimator);
141 
142  ValueType errorMeasurePrediction = newMeasure - measurePrediction;
143 
144  VectorType Corrector = m_Variance * newPredictor;
145 
146  for ( unsigned int j = 0; j < VEstimatorDimension; j++ )
147  {
148  m_Estimator(j) += Corrector(j) * errorMeasurePrediction;
149  }
150 
151  UpdateVariance(newPredictor);
152 }
153 
154 template< typename T, unsigned int VEstimatorDimension >
155 void
157 ::UpdateVariance(const VectorType & newPredictor)
158 {
159  VectorType aux = m_Variance * newPredictor;
160 
161  ValueType denominator = 1.0 / ( 1.0 + dot_product(aux, newPredictor) );
162 
163  for ( unsigned int col = 0; col < VEstimatorDimension; col++ )
164  {
165  for ( unsigned int row = 0; row < VEstimatorDimension; row++ )
166  {
167  m_Variance(col, row) -= aux(col) * aux(row) * denominator;
168  }
169  }
170 }
171 } // end namespace itk
172 
173 #endif
void UpdateWithNewMeasure(const ValueType &newMeasure, const VectorType &newPredictor)
const MatrixType & GetVariance() const
vnl_vector_fixed< T, VEstimatorDimension > VectorType
Implement a linear recursive estimator.
const VectorType & GetEstimator() const
void SetVariance(const MatrixType &m)
static constexpr unsigned int Dimension
void UpdateVariance(const VectorType &)
void SetVariance(const ValueType &var=1.0)
vnl_matrix_fixed< T, VEstimatorDimension, VEstimatorDimension > MatrixType