00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkKalmanLinearEstimator_h
00018 #define __itkKalmanLinearEstimator_h
00019
00020 #include "itkMacro.h"
00021
00022 #include <vnl/vnl_vector_fixed.h>
00023 #include <vnl/vnl_matrix_fixed.h>
00024
00025 namespace itk
00026 {
00027
00040 template <class T, unsigned int VEstimatorDimension>
00041 class KalmanLinearEstimator
00042 {
00043 public:
00046 itkStaticConstMacro( Dimension, unsigned int,
00047 VEstimatorDimension);
00048
00051 typedef vnl_vector_fixed<T,VEstimatorDimension> VectorType;
00052
00055 typedef vnl_matrix_fixed<T,VEstimatorDimension,VEstimatorDimension> MatrixType;
00056
00061 typedef T ValueType;
00062
00067 void UpdateWithNewMeasure( const ValueType & newMeasure,
00068 const VectorType & newPredictor );
00069
00073 void ClearEstimation(void)
00074 { m_Estimator = 0; }
00075
00078 void ClearVariance(void)
00079 {
00080 m_Variance.set_identity();
00081 }
00082
00089 void SetVariance(const ValueType & var = 1.0)
00090 {
00091 m_Variance.set_identity();
00092 m_Variance *= var;
00093 }
00094
00100 void SetVariance(const MatrixType & m)
00101 { m_Variance = m; }
00102
00105 const VectorType & GetEstimator(void) const
00106 { return m_Estimator; }
00107
00110 const MatrixType & GetVariance(void) const
00111 { return m_Variance; }
00112
00113 private:
00118 void UpdateVariance( const VectorType & );
00119
00122 VectorType m_Estimator;
00123
00130 MatrixType m_Variance;
00131
00132 };
00133
00134
00135 template <class T, unsigned int VEstimatorDimension>
00136 void
00137 KalmanLinearEstimator<T,VEstimatorDimension>
00138 ::UpdateWithNewMeasure( const ValueType & newMeasure,
00139 const VectorType & newPredictor )
00140 {
00141 ValueType measurePrediction = dot_product( newPredictor , m_Estimator );
00142
00143 ValueType errorMeasurePrediction = newMeasure - measurePrediction;
00144
00145 VectorType Corrector = m_Variance * newPredictor;
00146
00147 for( unsigned int j=0; j<VEstimatorDimension; j++)
00148 {
00149 m_Estimator(j) += Corrector(j) * errorMeasurePrediction;
00150 }
00151
00152 UpdateVariance( newPredictor );
00153
00154 }
00155
00156
00157 template <class T, unsigned int VEstimatorDimension>
00158 void
00159 KalmanLinearEstimator<T,VEstimatorDimension>
00160 ::UpdateVariance( const VectorType & newPredictor )
00161 {
00162 VectorType aux = m_Variance * newPredictor;
00163
00164 ValueType denominator = 1.0/(1.0 + dot_product( aux , newPredictor ) );
00165
00166 unsigned pos = 0;
00167 for( unsigned int col=0; col<VEstimatorDimension; col++)
00168 {
00169 for( unsigned int row=0; row<VEstimatorDimension; row++)
00170 {
00171 m_Variance(col,row) -= aux(col)*aux(row)*denominator;
00172 pos++;
00173 }
00174 }
00175 }
00176
00177 }
00178
00179 #endif