Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
log1p_exp.hpp
Go to the documentation of this file.
1 #ifndef STAN__MATH__FUNCTIONS__LOG1P_EXP_HPP
2 #define STAN__MATH__FUNCTIONS__LOG1P_EXP_HPP
3 
4 #include <boost/math/tools/promotion.hpp>
6 
7 namespace stan {
8  namespace math {
9 
42  template <typename T>
43  inline typename boost::math::tools::promote_args<T>::type
44  log1p_exp(const T a) {
45  using std::exp;
46  // like log_sum_exp below with b=0.0; prevents underflow
47  if (a > 0.0)
48  return a + log1p(exp(-a));
49  return log1p(exp(a));
50  }
51 
52  }
53 }
54 
55 #endif
boost::math::tools::promote_args< T >::type log1p_exp(const T a)
Calculates the log of 1 plus the exponential of the specified value without overflow.
Definition: log1p_exp.hpp:44
boost::math::tools::promote_args< T >::type log1p(const T x)
Return the natural logarithm of one plus the specified value.
Definition: log1p.hpp:39
Eigen::Matrix< T, Rows, Cols > exp(const Eigen::Matrix< T, Rows, Cols > &m)
Return the element-wise exponentiation of the matrix or vector.
Definition: exp.hpp:18
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:16

     [ Stan Home Page ] © 2011–2014, Stan Development Team.