1 #ifndef STAN_MATH_REV_ARR_FUN_LOG_SUM_EXP_HPP 2 #define STAN_MATH_REV_ARR_FUN_LOG_SUM_EXP_HPP 17 using std::numeric_limits;
18 double max = -numeric_limits<double>::infinity();
19 for (
size_t i = 0; i < x.size(); ++i)
23 for (
size_t i = 0; i < x.size(); ++i)
24 if (x[i] != -numeric_limits<double>::infinity())
25 sum +=
exp(x[i].val() -
max);
26 return max +
log(sum);
34 for (
size_t i = 0; i <
size_; ++i) {
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
fvar< T > log(const fvar< T > &x)
double log_sum_exp_as_double(const std::vector< var > &x)
Independent (input) and dependent (output) variables for gradients.
fvar< T > log_sum_exp(const std::vector< fvar< T > > &v)
const double val_
The value of this variable.
fvar< T > exp(const fvar< T > &x)
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
log_sum_exp_vector_vari(const std::vector< var > &x)
int max(const std::vector< int > &x)
Returns the maximum coefficient in the specified column vector.
double calculate_chain(double x, double val)
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...