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: 2005/05/06 18:53:39 $
00007   Version:   $Revision: 1.16 $
00008 
00009   Copyright (c) Insight Software 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 ITK_EXPORT 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 = VectorType(T(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   }
00095 
00101   void SetVariance(const MatrixType & m)
00102   { m_Variance = m; }
00103 
00106   const VectorType & GetEstimator(void) const
00107   { return m_Estimator; }
00108 
00111   const MatrixType & GetVariance(void) const
00112   { return m_Variance; }
00113 
00114 private:  
00119   void UpdateVariance( const VectorType  & );
00120 
00123   VectorType  m_Estimator;
00124 
00131   MatrixType m_Variance;
00132 
00133 };
00134 
00135 
00136 template <class T, unsigned int VEstimatorDimension>
00137 void
00138 KalmanLinearEstimator<T,VEstimatorDimension>
00139 ::UpdateWithNewMeasure( const ValueType  & newMeasure, 
00140                         const VectorType & newPredictor   )
00141 {
00142   ValueType measurePrediction = dot_product( newPredictor , m_Estimator );
00143   
00144   ValueType errorMeasurePrediction = newMeasure - measurePrediction;
00145 
00146   VectorType Corrector = m_Variance * newPredictor;
00147 
00148   for( unsigned int j=0; j<VEstimatorDimension; j++) 
00149     {
00150     m_Estimator(j) += Corrector(j) * errorMeasurePrediction;
00151     }
00152   
00153   UpdateVariance( newPredictor );
00154 
00155 }
00156 
00157 
00158 template <class T, unsigned int VEstimatorDimension>
00159 void
00160 KalmanLinearEstimator<T,VEstimatorDimension>
00161 ::UpdateVariance( const VectorType & newPredictor )
00162 {  
00163   VectorType aux =  m_Variance * newPredictor;
00164 
00165   ValueType denominator = 1.0/(1.0 +  dot_product( aux , newPredictor ) );
00166 
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       }
00173     }
00174 }
00175 
00176 } // end namespace itk
00177 
00178 #endif
00179 

Generated at Mon Mar 12 01:26:38 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000