1 #ifndef STAN__MATH__MATRIX__LOG_SUM_EXP_HPP
2 #define STAN__MATH__MATRIX__LOG_SUM_EXP_HPP
6 #include <boost/math/tools/promotion.hpp>
28 template <
int R,
int C>
30 using std::numeric_limits;
33 double max = -numeric_limits<double>::infinity();
34 for (
int i = 0; i < x.size(); i++)
39 for (
int i = 0; i < x.size(); i++)
40 if (x(i) != -numeric_limits<double>::infinity())
43 return max +
log(sum);
boost::math::tools::promote_args< T1, T2 >::type log_sum_exp(const T2 &a, const T1 &b)
Calculates the log sum of exponetials without overflow.
Eigen::Matrix< T, Rows, Cols > exp(const Eigen::Matrix< T, Rows, Cols > &m)
Return the element-wise exponentiation of the matrix or vector.
double max(const double a, const double b)
Eigen::Matrix< T, Rows, Cols > log(const Eigen::Matrix< T, Rows, Cols > &m)
Return the element-wise logarithm of the matrix or vector.
double sum(std::vector< double > &x)
fvar< T > log(const fvar< T > &x)
fvar< T > exp(const fvar< T > &x)