]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Base/Functors/GaussianModel.hxx
...
[FrontAlgorithms.git] / lib / 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( 2 ) ) // 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   std::cout << v << " " << d << std::endl;
49   return( d );
50
51   /* TODO
52      TOutput r = TOutput( 0 );
53      if( this->m_Model->GetNumberOfSamples( ) > this->m_SupportSize )
54      {
55      r = this->m_Model->SquaredMahalanobis( TOutput( x ) );
56      if( r <= TOutput( 1 ) )
57      this->m_Model->AddSample( TOutput( x ) );
58      }
59      else
60      {
61      this->m_Model->AddSample( TOutput( x ) );
62      if( this->m_Model->GetNumberOfSamples( ) > 2 )
63      r = this->m_Model->SquaredMahalanobis( TOutput( x ) );
64
65      } // fi
66      if( r < this->m_MinimumCost )
67      return( this->m_MinimumCost );
68      else
69      return( r );
70   */
71 }
72
73 // -------------------------------------------------------------------------
74 template< class _TInput, class _TOutput >
75 fpa::Base::Functors::GaussianModel< _TInput, _TOutput >::
76 GaussianModel( )
77   : Superclass( )
78   /* TODO
79      ,
80      m_SupportSize( 30 ),
81      m_MinimumCost( TOutput( 1e-10 ) )
82   */
83 {
84   /* TODO
85      this->m_Model = TModel::New( );
86   */
87   this->m_S1 = double( 0 );
88   this->m_S2 = double( 0 );
89   this->m_N = 0;
90 }
91
92 // -------------------------------------------------------------------------
93 template< class _TInput, class _TOutput >
94 fpa::Base::Functors::GaussianModel< _TInput, _TOutput >::
95 ~GaussianModel( )
96 {
97 }
98
99 #endif // __fpa__Base__Functors__GaussianModel__hxx__
100
101 // eof - $RCSfile$