TOutput fpa::Base::Functors::GaussianModel< _TInput, _TOutput >::
Evaluate( const TInput& x ) const
{
- TOutput r = TOutput( 0 );
- if( this->m_Model->GetNumberOfSamples( ) > this->m_SupportSize )
+ double v = double( x );
+ double d = double( 0 );
+ if( this->m_N > 1 )
{
- r = this->m_Model->SquaredMahalanobis( TOutput( x ) );
- if( r <= TOutput( 1 ) )
- this->m_Model->AddSample( TOutput( x ) );
+ double N = double( this->m_N );
+ double m = this->m_S1 / N;
+ double s =
+ ( this->m_S2 - ( ( this->m_S1 * this->m_S1 ) / N ) ) /
+ ( N - double( 1 ) );
+ if( s > double( 0 ) )
+ {
+ d = ( v - m );
+ d *= d;
+ d /= s;
+ d = std::sqrt( d );
+ if( d <= double( 1.5 ) ) // 2sigma
+ {
+ this->m_S1 += v;
+ this->m_S2 += v * v;
+ this->m_N += 1;
+
+ } // fi
+ }
+ else
+ {
+ this->m_S1 += v;
+ this->m_S2 += v * v;
+ this->m_N += 1;
+
+ } // fi
}
else
{
- this->m_Model->AddSample( TOutput( x ) );
- if( this->m_Model->GetNumberOfSamples( ) > 2 )
- r = this->m_Model->SquaredMahalanobis( TOutput( x ) );
+ this->m_S1 += v;
+ this->m_S2 += v * v;
+ this->m_N += 1;
} // fi
- if( r < this->m_MinimumCost )
- return( this->m_MinimumCost );
- else
- return( r );
+ return( d );
+
+ /* TODO
+ TOutput r = TOutput( 0 );
+ if( this->m_Model->GetNumberOfSamples( ) > this->m_SupportSize )
+ {
+ r = this->m_Model->SquaredMahalanobis( TOutput( x ) );
+ if( r <= TOutput( 1 ) )
+ this->m_Model->AddSample( TOutput( x ) );
+ }
+ else
+ {
+ this->m_Model->AddSample( TOutput( x ) );
+ if( this->m_Model->GetNumberOfSamples( ) > 2 )
+ r = this->m_Model->SquaredMahalanobis( TOutput( x ) );
+
+ } // fi
+ if( r < this->m_MinimumCost )
+ return( this->m_MinimumCost );
+ else
+ return( r );
+ */
}
// -------------------------------------------------------------------------
template< class _TInput, class _TOutput >
fpa::Base::Functors::GaussianModel< _TInput, _TOutput >::
GaussianModel( )
- : Superclass( ),
- m_SupportSize( 30 ),
- m_MinimumCost( TOutput( 1e-10 ) )
+ : Superclass( )
+ /* TODO
+ ,
+ m_SupportSize( 30 ),
+ m_MinimumCost( TOutput( 1e-10 ) )
+ */
{
- this->m_Model = TModel::New( );
+ /* TODO
+ this->m_Model = TModel::New( );
+ */
+ this->m_S1 = double( 0 );
+ this->m_S2 = double( 0 );
+ this->m_N = 0;
}
// -------------------------------------------------------------------------