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> 45 #include <boost/type_traits/is_arithmetic.hpp> 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<boost::is_arithmetic<T>, T>::type
sqr(
const T & x) {
86 template <
class T>
inline T
cube(
const T & x) {
95 typename boost::enable_if<boost::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>()){
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<boost::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)));
198 double trigamma1 = 1.6449340668482264365;
199 double tetragamma1 = -2.404113806319188570799476;
207 if((x <= 0) && (std::floor(x) == x)) {
208 return -std::numeric_limits<double>::infinity();
215 double pi = boost::math::constants::pi<double>();
216 double s = std::sin(pi*x);
217 double ddz_cot_pi_x=-pi / (s * s);
218 return -
trigamma(1-x) - pi * ddz_cot_pi_x;
224 return 1/(x*x) + trigamma1 + tetragamma1*x;
239 double t = (b4 + r*(b6 + r*(b8 + r*b10)));
240 result += 0.5*r + (1 + r*(b2 + r*t))/x;
261 double tetragamma1 = -2.404113806319188570799476;
262 double pentagamma1 = 6.49393940226682914909602217;
270 if((x <= 0) && (std::floor(x) == x)) {
271 throw SHARKEXCEPTION(
"[tetragamma] negative whole numbers ar enot allowed");
281 double pi = boost::math::constants::pi<double>();
282 double s_pi_x = std::sin(pi*x);
283 double c_pi_x = std::cos(pi*x);
284 double ddz2_cot_pi_x=2*
sqr(pi)*c_pi_x/
cube(s_pi_x);
291 return -2/
cube(x) + tetragamma1 + pentagamma1*x;
308 double t = (5*b4 + r*(7*b6 + r*(9*b8 + r*11*b10)));
309 result -= r/x + r*(1 + r*(3*b2 + r*t));