]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Algorithms/IterativeGaussianModelEstimator.h
...
[cpPlugins.git] / lib / cpExtensions / Algorithms / IterativeGaussianModelEstimator.h
1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
4
5 #ifndef __CPEXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__
6 #define __CPEXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__
7
8 #include <vector>
9 #include <itkConceptChecking.h>
10 #include <itkObject.h>
11 #include <vnl/vnl_matrix.h>
12
13 namespace cpExtensions
14   {
15     namespace Algorithms
16     {
17       /**
18        */
19       template< class S, unsigned int D >
20       class IterativeGaussianModelEstimator
21         : public itk::Object
22       {
23       public:
24         typedef IterativeGaussianModelEstimator Self;
25         typedef itk::Object                     Superclass;
26         typedef itk::SmartPointer< Self >       Pointer;
27         typedef itk::SmartPointer< const Self > ConstPointer;
28
29         typedef S TScalar;
30         itkStaticConstMacro( Dimension, unsigned int, D );
31
32         // Begin concept checking
33 #ifdef ITK_USE_CONCEPT_CHECKING
34         itkConceptMacro(
35           ScalarTypeHasFloatResolution,
36           ( itk::Concept::IsFloatingPoint< S > )
37           );
38 #endif
39         // End concept checking
40
41         typedef vnl_matrix< S >        TMatrix;
42         typedef std::vector< TMatrix > TMatrices;
43
44       public:
45         itkNewMacro( Self );
46         itkTypeMacro( IterativeGaussianModelEstimator, itkObject );
47
48       public:
49         unsigned long GetNumberOfSamples( ) const
50           { return( ( unsigned long )( this->m_N ) ); }
51         const TMatrix& GetMu( ) const
52           { return( this->m_M ); }
53         const TMatrix& GetOmega( ) const
54           { return( this->m_O ); }
55
56         void SetNumberOfSamples( unsigned long n );
57         void SetMu( const TMatrix& m );
58         void SetOmega( const TMatrix& O );
59
60         bool SaveModelToFile( const std::string& filename ) const;
61         bool LoadModelFromFile( const std::string& filename );
62
63         template< class V >
64         S Probability( const V& sample ) const;
65
66         S Probability( const S& s_x, const S& s_y, ... ) const;
67
68         template< class V, class M >
69         void GetModel( V& m, M& E ) const;
70
71         void Clear( );
72
73         template< class V >
74         void AddSample( const V& sample );
75
76         void AddSample( const S& s_x, const S& s_y, ... );
77
78       protected:
79         IterativeGaussianModelEstimator( );
80         virtual ~IterativeGaussianModelEstimator( );
81
82       protected:
83         void _UpdateModel( ) const;
84
85       private:
86         // Purposely not implemented
87         IterativeGaussianModelEstimator( const Self& other );
88         void operator=( const Self& other );
89
90       protected:
91         S m_N;
92         TMatrix m_M;
93         TMatrix m_O;
94
95         mutable bool m_Updated;
96         mutable TMatrix m_Cov;
97         mutable TMatrix m_Inv;
98         mutable S m_Norm;
99       };
100
101     } // ecapseman
102
103 } // ecapseman
104
105 #include <cpExtensions/Algorithms/IterativeGaussianModelEstimator.hxx>
106
107 #endif // __CPEXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__H__
108
109 // eof - $RCSfile$