ITK  6.0.0
Insight Toolkit
itkKalmanLinearEstimator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 {
42 template <typename T, unsigned int VEstimatorDimension>
44 {
45 public:
46 
49  static constexpr unsigned int Dimension = VEstimatorDimension;
50 
53  using VectorType = vnl_vector_fixed<T, VEstimatorDimension>;
54 
57  using MatrixType = vnl_matrix_fixed<T, VEstimatorDimension, VEstimatorDimension>;
58 
63  using ValueType = T;
64 
69  void
70  UpdateWithNewMeasure(const ValueType & newMeasure, const VectorType & newPredictor);
71 
75  void
77  {
78  m_Estimator = VectorType(T(0));
79  }
80 
83  void
85  {
86  m_Variance.set_identity();
87  }
88 
95  void
96  SetVariance(const ValueType & var = 1.0)
97  {
98  m_Variance.set_identity();
99  m_Variance *= var;
100  }
108  void
110  {
111  m_Variance = m;
112  }
113 
116  const VectorType &
117  GetEstimator() const
118  {
119  return m_Estimator;
120  }
121 
124  const MatrixType &
125  GetVariance() const
126  {
127  return m_Variance;
128  }
129 
130 private:
135  void
136  UpdateVariance(const VectorType &);
137 
141 
149 };
150 
151 template <typename T, unsigned int VEstimatorDimension>
152 void
154  const VectorType & newPredictor)
155 {
156  ValueType measurePrediction = dot_product(newPredictor, m_Estimator);
157 
158  ValueType errorMeasurePrediction = newMeasure - measurePrediction;
159 
160  VectorType Corrector = m_Variance * newPredictor;
161 
162  for (unsigned int j = 0; j < VEstimatorDimension; ++j)
163  {
164  m_Estimator(j) += Corrector(j) * errorMeasurePrediction;
165  }
166 
167  UpdateVariance(newPredictor);
168 }
169 
170 template <typename T, unsigned int VEstimatorDimension>
171 void
173 {
174  VectorType aux = m_Variance * newPredictor;
175 
176  ValueType denominator = 1.0 / (1.0 + dot_product(aux, newPredictor));
177 
178  for (unsigned int col = 0; col < VEstimatorDimension; ++col)
179  {
180  for (unsigned int row = 0; row < VEstimatorDimension; ++row)
181  {
182  m_Variance(col, row) -= aux(col) * aux(row) * denominator;
183  }
184  }
185 }
186 } // end namespace itk
187 
188 #endif
itk::KalmanLinearEstimator::GetEstimator
const VectorType & GetEstimator() const
Definition: itkKalmanLinearEstimator.h:117
itk::KalmanLinearEstimator::MatrixType
vnl_matrix_fixed< T, VEstimatorDimension, VEstimatorDimension > MatrixType
Definition: itkKalmanLinearEstimator.h:57
itk::KalmanLinearEstimator::UpdateVariance
void UpdateVariance(const VectorType &)
Definition: itkKalmanLinearEstimator.h:172
itk::KalmanLinearEstimator::VectorType
vnl_vector_fixed< T, VEstimatorDimension > VectorType
Definition: itkKalmanLinearEstimator.h:53
itk::KalmanLinearEstimator::ValueType
T ValueType
Definition: itkKalmanLinearEstimator.h:63
itk::KalmanLinearEstimator::m_Estimator
VectorType m_Estimator
Definition: itkKalmanLinearEstimator.h:140
itkMacro.h
itk::KalmanLinearEstimator::GetVariance
const MatrixType & GetVariance() const
Definition: itkKalmanLinearEstimator.h:125
itk::KalmanLinearEstimator::SetVariance
void SetVariance(const ValueType &var=1.0)
Definition: itkKalmanLinearEstimator.h:96
itk::KalmanLinearEstimator::ClearVariance
void ClearVariance()
Definition: itkKalmanLinearEstimator.h:84
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::KalmanLinearEstimator::Dimension
static constexpr unsigned int Dimension
Definition: itkKalmanLinearEstimator.h:49
itk::KalmanLinearEstimator::m_Variance
MatrixType m_Variance
Definition: itkKalmanLinearEstimator.h:148
itk::KalmanLinearEstimator::SetVariance
void SetVariance(const MatrixType &m)
Definition: itkKalmanLinearEstimator.h:109
itk::KalmanLinearEstimator::ClearEstimation
void ClearEstimation()
Definition: itkKalmanLinearEstimator.h:76
itk::KalmanLinearEstimator
Implement a linear recursive estimator.
Definition: itkKalmanLinearEstimator.h:43
itk::KalmanLinearEstimator::UpdateWithNewMeasure
void UpdateWithNewMeasure(const ValueType &newMeasure, const VectorType &newPredictor)
Definition: itkKalmanLinearEstimator.h:153