]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Extensions/Algorithms/IterativeGaussianModelEstimator.hxx
Image visualization objects updated
[cpPlugins.git] / lib / cpPlugins / Extensions / Algorithms / IterativeGaussianModelEstimator.hxx
index c8c652f6462cb70171d1bb631d9ac85fa6a22f56..bf87054cf79a25fc68047b3365315b9627e015a1 100644 (file)
@@ -36,31 +36,6 @@ UpdateModel( )
   else
     this->m_Cov.fill( S( 0 ) );
 
-  /* TODO
-     TMatrix Es = ( this->m_S1 * this->m_S1.transpose( ) );
-     for( unsigned int i = 0; i < D; ++i )
-     {
-     this->m_Mean[ i ][ 0 ] = this->m_S1[ i ][ 0 ];
-     if( this->m_N > 0 )
-     this->m_Mean[ i ][ 0 ] /= S( this->m_N );
-
-     for( unsigned int j = 0; j < D; ++j )
-     {
-     this->m_Cov[ i ][ j ] = S( 0 );
-     if( this->m_N > 0 )
-     this->m_Cov[ i ][ j ] -= Es[ i ][ j ] / S( this->m_N );
-     if( this->m_N > 1 )
-     {
-     this->m_Cov[ i ][ j ] += this->m_S2[ i ][ j ];
-     this->m_Cov[ i ][ j ] /= S( this->m_N - 1 );
-
-     } // fi
-
-     } // rof
-
-     } // rof
-  */
-
   // Compute inverse and determinant
   S det = vnl_determinant( this->m_Cov );
   if( !( det > S( 0 ) ) )
@@ -98,15 +73,6 @@ UpdateModel( )
 
   } // rof
   this->m_Updated = true;
-
-  /* DEBUG:
-     std::cout << "--------------------" << std::endl;
-     std::cout << this->m_Cov << std::endl;
-     std::cout << "--------------------" << std::endl;
-     std::cout << this->m_InvCov << std::endl;
-     std::cout << "--------------------" << std::endl;
-     std::cout << this->m_Mean << std::endl;
-  */
 }
 
 // -------------------------------------------------------------------------
@@ -118,10 +84,23 @@ Probability( const V& sample ) const
   TMatrix c( D, 1 );
   for( unsigned int d = 0; d < D; ++d )
     c[ d ][ 0 ] = S( sample[ d ] ) - this->m_Mean[ d ][ 0 ];
-  double v = double( ( c.transpose( ) * ( this->m_InvCov * c ) )[ 0 ][ 0 ] );
-  v /= double( 2 );
+  if( S( 0 ) < this->m_DensityCoeff )
+  {
+    // Covariance is NOT null
+    double v = double( ( c.transpose( ) * ( this->m_InvCov * c ) )[ 0 ][ 0 ] );
+    v /= double( 2 );
 
-  return( S( std::exp( -v ) ) );
+    return( S( std::exp( -v ) ) );
+  }
+  else
+  {
+    // Covariance is null
+    bool equal = true;
+    for( unsigned int d = 0; d < D && equal; ++d )
+      equal &= !( S( 0 ) < S( std::fabs( double( c[ d ][ 0 ] ) ) ) );
+    return( ( equal )? S( 1 ): S( 0 ) );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
@@ -187,23 +166,6 @@ AddSample( const V& sample )
   this->m_S1 += s;
   this->m_S2 += s * s.transpose( );
 
-  /* DEBUG:
-     std::cout
-     << sample[ 0 ] << " " << sample[ 1 ] << " " << sample[ 2 ] << std::endl;
-  */
-
-  /* TODO
-     {
-     this->m_S1[ i ][ 0 ] += S( sample[ i ] );
-     for( unsigned int j = i; j < D; ++j )
-     {
-     this->m_S2[ i ][ j ] += S( sample[ i ] ) * S( sample[ j ] );
-     this->m_S2[ j ][ i ] = this->m_S2[ i ][ j ];
-
-     } // rof
-
-     } // rof
-  */
   this->m_Updated = false;
   this->Modified( );
 }