4 namespace til { namespace math {
7 //---------------------------------------------------------------------------
11 //-------------------------------------------------------------------------
13 template < typename T >
16 // NB: testing K >= 0 is actually not needed.
23 return 2 * K * (ax - K);
27 //-------------------------------------------------------------------------
31 //---------------------------------------------------------------------------
33 template < typename T >
36 return detail::ahuber(std::abs(x), K);
39 //---------------------------------------------------------------------------
41 template < typename T >
58 //---------------------------------------------------------------------------
60 template < typename T >
78 //---------------------------------------------------------------------------
80 /// Constructor with Gaussian standard deviation.
81 template < typename TPrec >
82 Gaussian<TPrec>::Gaussian(prec_type sigma)
84 this->setSigma(sigma);
87 //---------------------------------------------------------------------------
89 template < typename TPrec >
91 Gaussian<TPrec>::setSigma(prec_type sigma)
94 m_2var = 2 * sigma * sigma;
95 if (m_2var < 128 * std::numeric_limits<prec_type>::epsilon())
97 throw StandardDeviationTooSmall();
101 //---------------------------------------------------------------------------
103 template < typename TPrec >
104 typename Gaussian<TPrec>::prec_type
105 Gaussian<TPrec>::operator()(prec_type x) const
107 return squared_input(x*x);
110 //---------------------------------------------------------------------------
112 template < typename TPrec >
113 typename Gaussian<TPrec>::prec_type
114 Gaussian<TPrec>::squared_input(prec_type x2) const
116 return std::exp(-x2 / m_2var);
119 //---------------------------------------------------------------------------
121 }} // namespace til::math