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 ) ) )
} // 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;
- */
}
// -------------------------------------------------------------------------
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
}
// -------------------------------------------------------------------------
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( );
}