1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPEXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__
6 #define __CPEXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__
9 #include <itkConceptChecking.h>
10 #include <itkObject.h>
11 #include <itkObjectFactory.h>
13 #include <itkCovariantVector.h>
14 #include <itkMatrix.h>
16 #include <itkVector.h>
18 namespace cpExtensions
23 * Recursive formulation taken from:
24 * http://lmb.informatik.uni-freiburg.de/lectures/mustererkennung/Englische_Folien/07_c_ME_en.pdf
26 template< class _TScalar, unsigned int _VDimension >
27 class IterativeGaussianModelEstimator
31 typedef IterativeGaussianModelEstimator Self;
32 typedef itk::Object Superclass;
33 typedef itk::SmartPointer< Self > Pointer;
34 typedef itk::SmartPointer< const Self > ConstPointer;
36 typedef _TScalar TScalar;
37 itkStaticConstMacro( Dimension, unsigned int, _VDimension );
39 // Begin concept checking
40 #ifdef ITK_USE_CONCEPT_CHECKING
42 ScalarTypeHasFloatResolution,
43 ( itk::Concept::IsFloatingPoint< _TScalar > )
46 // End concept checking
48 typedef itk::Matrix< TScalar, Dimension, Dimension > TMatrix;
49 typedef itk::Vector< TScalar, Dimension > TVector;
53 itkTypeMacro( IterativeGaussianModelEstimator, itkObject );
55 itkGetConstMacro( Mean, TVector );
56 itkGetConstMacro( Covariance, TMatrix );
57 itkGetConstMacro( UnbiasedCovariance, TMatrix );
58 itkGetConstMacro( NumberOfSamples, unsigned long );
60 itkSetMacro( Mean, TVector );
61 itkSetMacro( Covariance, TMatrix );
62 itkSetMacro( NumberOfSamples, unsigned long );
67 template< class _TOtherScalar >
68 void AddSample( const _TOtherScalar& x1, ... );
70 template< class _TOtherScalar >
71 void AddSample( const _TOtherScalar* array );
73 template< class _TOtherScalar >
74 void AddSample( const vnl_vector< _TOtherScalar >& v );
76 template< class _TOtherScalar >
78 const itk::CovariantVector< _TOtherScalar, _VDimension >& v
81 template< class _TOtherScalar >
82 void AddSample( const itk::Point< _TOtherScalar, _VDimension >& p );
84 template< class _TOtherScalar >
85 void AddSample( const itk::Vector< _TOtherScalar, _VDimension >& v );
87 template< class _TOtherScalar >
88 _TScalar SquaredMahalanobis( const _TOtherScalar& x1, ... ) const;
90 template< class _TOtherScalar >
91 _TScalar SquaredMahalanobis( const _TOtherScalar* array ) const;
93 template< class _TOtherScalar >
94 _TScalar SquaredMahalanobis(
95 const vnl_vector< _TOtherScalar >& v
98 template< class _TOtherScalar >
99 _TScalar SquaredMahalanobis(
100 const itk::CovariantVector< _TOtherScalar, _VDimension >& v
103 template< class _TOtherScalar >
104 _TScalar SquaredMahalanobis(
105 const itk::Point< _TOtherScalar, _VDimension >& p
108 template< class _TOtherScalar >
109 _TScalar SquaredMahalanobis(
110 const itk::Vector< _TOtherScalar, _VDimension >& v
113 template< class _TOtherScalar >
114 _TScalar Density( const _TOtherScalar& x1, ... ) const;
116 template< class _TOtherScalar >
117 _TScalar Density( const _TOtherScalar* array ) const;
119 template< class _TOtherScalar >
121 const vnl_vector< _TOtherScalar >& v
124 template< class _TOtherScalar >
126 const itk::CovariantVector< _TOtherScalar, _VDimension >& v
129 template< class _TOtherScalar >
131 const itk::Point< _TOtherScalar, _VDimension >& p
134 template< class _TOtherScalar >
136 const itk::Vector< _TOtherScalar, _VDimension >& v
140 IterativeGaussianModelEstimator( );
141 virtual ~IterativeGaussianModelEstimator( );
144 void _AddSample( const TVector& v ) const;
145 _TScalar _SquaredMahalanobis( const TVector& v ) const;
146 _TScalar _Density( const TVector& v ) const;
149 // Purposely not implemented
150 IterativeGaussianModelEstimator( const Self& other );
151 void operator=( const Self& other );
154 // Recursive avg/cov values
155 mutable unsigned long m_NumberOfSamples;
156 mutable TVector m_Mean;
157 mutable TMatrix m_Covariance;
158 mutable TMatrix m_UnbiasedCovariance;
159 mutable bool m_InverseUpdated;
160 mutable TMatrix m_InverseUnbiasedCovariance;
167 #include <cpExtensions/Algorithms/IterativeGaussianModelEstimator.hxx>
169 #endif // __CPEXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__