39 #ifndef SHARK_CORE_MATH_H 40 #define SHARK_CORE_MATH_H 42 #include <boost/math/constants/constants.hpp> 43 #include <boost/math/special_functions/sign.hpp> 44 #include <boost/utility/enable_if.hpp> 47 #include <type_traits> 65 static const double SQRT_2_PI = boost::math::constants::root_two_pi<double>();
71 return boost::math::constants::ln_two<T>()*std::numeric_limits<T>::max_exponent;
76 return boost::math::constants::ln_two<T>()*std::numeric_limits<T>::min_exponent;
81 inline typename boost::enable_if<std::is_arithmetic<T>, T>::type
sqr(
const T & x) {
86 template <
class T>
inline T
cube(
const T & x) {
95 typename boost::enable_if<std::is_arithmetic<T>, T>::type
sigmoid(T x){
96 if(x < minExpInput<T>()) {
99 if(x > maxExpInput<T>()) {
102 return 1. / (1.+ std::exp(-x));
113 if(x > maxExpInput<T>()){
115 return 0.9 * std::numeric_limits<long double>::max();
130 if(x> -std::numeric_limits<T>::epsilon() && x < std::numeric_limits<T>::epsilon()){
132 return boost::math::sign(x)*std::numeric_limits<T>::min_exponent;
147 typename boost::enable_if<std::is_arithmetic<T>, T>::type
softPlus(T x){
148 if(x > maxExpInput<T>()){
151 if(x < minExpInput<T>()){
154 return std::log(1+std::exp(x));
168 return std::log(1.0f+std::exp(
float(x)));