]> Creatis software - FrontAlgorithms.git/blob - libs/fpa/Base/Functors/GaussianModel.hxx
...
[FrontAlgorithms.git] / libs / fpa / Base / Functors / GaussianModel.hxx
1 #ifndef __fpa__Base__Functors__GaussianModel__hxx__
2 #define __fpa__Base__Functors__GaussianModel__hxx__
3
4 // -------------------------------------------------------------------------
5 template< class _TInput, class _TOutput >
6 typename fpa::Base::Functors::GaussianModel< _TInput, _TOutput >::
7 TOutput fpa::Base::Functors::GaussianModel< _TInput, _TOutput >::
8 Evaluate( const TInput& x ) const
9 {
10   double v = double( x );
11   double d = double( 0 );
12   if( this->m_N > 1 )
13   {
14     double N = double( this->m_N );
15     double m = this->m_S1 / N;
16     double s =
17       ( this->m_S2 - ( ( this->m_S1 * this->m_S1 ) / N ) ) /
18       ( N - double( 1 ) );
19     if( s > double( 0 ) )
20     {
21       d = ( v - m );
22       d *= d;
23       d /= s;
24       d = std::sqrt( d );
25       if( d <= double( 1.5 ) ) // 2sigma
26       {
27         this->m_S1 += v;
28         this->m_S2 += v * v;
29         this->m_N += 1;
30
31       } // fi
32     }
33     else
34     {
35       this->m_S1 += v;
36       this->m_S2 += v * v;
37       this->m_N += 1;
38
39     } // fi
40   }
41   else
42   {
43     this->m_S1 += v;
44     this->m_S2 += v * v;
45     this->m_N += 1;
46
47   } // fi
48   return( d );
49
50   /* TODO
51      TOutput r = TOutput( 0 );
52      if( this->m_Model->GetNumberOfSamples( ) > this->m_SupportSize )
53      {
54      r = this->m_Model->SquaredMahalanobis( TOutput( x ) );
55      if( r <= TOutput( 1 ) )
56      this->m_Model->AddSample( TOutput( x ) );
57      }
58      else
59      {
60      this->m_Model->AddSample( TOutput( x ) );
61      if( this->m_Model->GetNumberOfSamples( ) > 2 )
62      r = this->m_Model->SquaredMahalanobis( TOutput( x ) );
63
64      } // fi
65      if( r < this->m_MinimumCost )
66      return( this->m_MinimumCost );
67      else
68      return( r );
69   */
70 }
71
72 // -------------------------------------------------------------------------
73 template< class _TInput, class _TOutput >
74 fpa::Base::Functors::GaussianModel< _TInput, _TOutput >::
75 GaussianModel( )
76   : Superclass( )
77   /* TODO
78      ,
79      m_SupportSize( 30 ),
80      m_MinimumCost( TOutput( 1e-10 ) )
81   */
82 {
83   /* TODO
84      this->m_Model = TModel::New( );
85   */
86   this->m_S1 = double( 0 );
87   this->m_S2 = double( 0 );
88   this->m_N = 0;
89 }
90
91 // -------------------------------------------------------------------------
92 template< class _TInput, class _TOutput >
93 fpa::Base::Functors::GaussianModel< _TInput, _TOutput >::
94 ~GaussianModel( )
95 {
96 }
97
98 #endif // __fpa__Base__Functors__GaussianModel__hxx__
99
100 // eof - $RCSfile$