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
26namespace itk
27{
42template <typename T, unsigned int VEstimatorDimension>
44{
45public:
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 &
118 {
119 return m_Estimator;
120 }
121
124 const MatrixType &
126 {
127 return m_Variance;
128 }
129
130private:
135 void
136 UpdateVariance(const VectorType &);
137
141
149};
150
151template <typename T, unsigned int VEstimatorDimension>
152void
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
170template <typename T, unsigned int VEstimatorDimension>
171void
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
Implement a linear recursive estimator.
void UpdateVariance(const VectorType &)
const MatrixType & GetVariance() const
vnl_vector_fixed< T, VEstimatorDimension > VectorType
vnl_matrix_fixed< T, VEstimatorDimension, VEstimatorDimension > MatrixType
const VectorType & GetEstimator() const
void SetVariance(const MatrixType &m)
void UpdateWithNewMeasure(const ValueType &newMeasure, const VectorType &newPredictor)
void SetVariance(const ValueType &var=1.0)
static constexpr unsigned int Dimension
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....