1 // -------------------------------------------------------------------------
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // -------------------------------------------------------------------------
5 #ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__HXX__
6 #define __CPPLUGINS__EXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__HXX__
10 // -------------------------------------------------------------------------
11 template< class S, unsigned int D >
12 template< class V, class M >
14 cpPlugins::Extensions::Algorithms::IterativeGaussianModelEstimator< S, D >::
15 GetModel( V& m, M& E ) const
17 TMatrix Es = ( this->m_S1 * this->m_S1.transpose( ) );
19 for( unsigned int i = 0; i < D; ++i )
21 m[ i ] = this->m_S1[ i ][ 0 ];
23 m[ i ] /= double( this->m_N );
25 for( unsigned int j = 0; j < D; ++j )
27 E[ i ][ j ] = double( 0 );
29 E[ i ][ j ] -= double( Es[ i ][ j ] / S( this->m_N ) );
32 E[ i ][ j ] += double( this->m_S2[ i ][ j ] );
33 E[ i ][ j ] /= double( this->m_N - 1 );
42 // -------------------------------------------------------------------------
43 template< class S, unsigned int D >
45 cpPlugins::Extensions::Algorithms::IterativeGaussianModelEstimator< S, D >::
49 this->m_S1.set_size( D, 1 );
50 this->m_S2.set_size( D, D );
51 this->m_S1.fill( S( 0 ) );
52 this->m_S2.fill( S( 0 ) );
56 // -------------------------------------------------------------------------
57 template< class S, unsigned int D >
60 cpPlugins::Extensions::Algorithms::IterativeGaussianModelEstimator< S, D >::
61 AddSample( const V& sample )
63 for( unsigned int i = 0; i < D; ++i )
65 this->m_S1[ i ][ 0 ] += S( sample[ i ] );
66 for( unsigned int j = i; j < D; ++j )
68 this->m_S2[ i ][ j ] += S( sample[ i ] ) * S( sample[ j ] );
69 this->m_S2[ j ][ i ] = this->m_S2[ i ][ j ];
78 // -------------------------------------------------------------------------
79 template< class S, unsigned int D >
81 cpPlugins::Extensions::Algorithms::IterativeGaussianModelEstimator< S, D >::
82 AddSample( const S& s_x, const S& s_y, ... )
86 std::va_list args_lst;
87 va_start( args_lst, s_y );
90 for( unsigned int d = 2; d < D; ++d )
91 sample[ d ] = S( va_arg( args_lst, double ) );
93 this->AddSample( sample );
96 // -------------------------------------------------------------------------
97 template< class S, unsigned int D >
98 cpPlugins::Extensions::Algorithms::IterativeGaussianModelEstimator< S, D >::
99 IterativeGaussianModelEstimator( )
105 // -------------------------------------------------------------------------
106 template< class S, unsigned int D >
107 cpPlugins::Extensions::Algorithms::IterativeGaussianModelEstimator< S, D >::
108 ~IterativeGaussianModelEstimator( )
112 #endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__ITERATIVEGAUSSIANMODELESTIMATOR__HXX__