Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkKalmanLinearEstimator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkKalmanLinearEstimator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2002/09/11 19:39:01 $
00007   Version:   $Revision: 1.10 $
00008 
00009   Copyright (c) 2002 Insight Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
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 } // end namespace itk
00178 
00179 #endif

Generated at Fri May 21 01:14:58 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000