1 #ifndef STAN_MATH_PRIM_MAT_PROB_POISSON_LOG_GLM_LPMF_HPP 2 #define STAN_MATH_PRIM_MAT_PROB_POISSON_LOG_GLM_LPMF_HPP 44 template <
bool propto,
typename T_y,
typename T_x,
typename T_alpha,
47 const T_y& y,
const T_x& x,
const T_alpha& alpha,
const T_beta&
beta) {
48 static const char*
function =
"poisson_log_glm_lpmf";
51 typedef typename std::conditional<
53 Eigen::Array<typename partials_return_type<T_alpha>::type, -1, 1>,
60 const size_t N = x.rows();
61 const size_t M = x.cols();
66 if (is_vector<T_alpha>::value)
68 "Vector of dependent variables", y);
75 T_partials_return logp(0);
86 Matrix<T_partials_return, Dynamic, 1> theta = x_val * beta_val_vec;
89 Matrix<T_partials_return, Dynamic, 1> theta_derivative
91 double theta_derivative_sum =
sum(theta_derivative);
95 check_finite(
function,
"Matrix of independent variables", theta);
106 -
exp(theta.array()));
112 ops_partials.
edge3_.partials_ = x_val.transpose() * theta_derivative;
115 ops_partials.
edge1_.partials_
116 = (beta_val_vec * theta_derivative.transpose()).
transpose();
119 if (is_vector<T_alpha>::value)
120 ops_partials.
edge2_.partials_ = theta_derivative;
122 ops_partials.
edge2_.partials_[0] = theta_derivative_sum;
124 return ops_partials.
build(logp);
127 template <
typename T_y,
typename T_x,
typename T_alpha,
typename T_beta>
129 const T_y& y,
const T_x& x,
const T_alpha& alpha,
const T_beta&
beta) {
130 return poisson_log_glm_lpmf<false>(y, x, alpha,
beta);
fvar< T > sum(const std::vector< fvar< T > > &m)
Return the sum of the entries of the specified standard vector.
const Eigen::Matrix< T, Eigen::Dynamic, 1 > & as_column_vector_or_scalar(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &a)
Converts input argument to a column vector or a scalar.
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
bool isfinite(const stan::math::var &v)
Checks if the given number has finite value.
boost::math::tools::promote_args< double, typename partials_type< typename scalar_type< T >::type >::type, typename partials_return_type< T_pack... >::type >::type type
fvar< T > lgamma(const fvar< T > &x)
Return the natural logarithm of the gamma function applied to the specified argument.
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...
This template builds partial derivatives with respect to a set of operands.
bool size_zero(T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
fvar< T > beta(const fvar< T > &x1, const fvar< T > &x2)
Return fvar with the beta function applied to the specified arguments and its gradient.
void check_consistent_size(const char *function, const char *name, const T &x, size_t expected_size)
Check if the dimension of x is consistent, which is defined to be expected_size if x is a vector or 1...
boost::math::tools::promote_args< double, typename scalar_type< T >::type, typename return_type< Types_pack... >::type >::type type
fvar< T > exp(const fvar< T > &x)
T_return_type build(double value)
Build the node to be stored on the autodiff graph.
double as_scalar(const std::vector< T > &a)
Converts input to a scalar.
matrix_cl transpose(const matrix_cl &src)
Takes the transpose of the matrix on the OpenCL device.
internal::ops_partials_edge< double, Op2 > edge2_
return_type< T_x, T_alpha, T_beta >::type poisson_log_glm_lpmf(const T_y &y, const T_x &x, const T_alpha &alpha, const T_beta &beta)
Returns the log PMF of the Generalized Linear Model (GLM) with Poisson distribution and log link func...
Eigen::ArrayWrapper< const Eigen::Matrix< T, R, C > > as_array_or_scalar(const Eigen::Matrix< T, R, C > &v)
Converts a matrix type to an array.
void check_consistent_sizes(const char *function, const char *name1, const T1 &x1, const char *name2, const T2 &x2)
Check if the dimension of x1 is consistent with x2.
internal::ops_partials_edge< double, Op3 > edge3_
internal::ops_partials_edge< double, Op1 > edge1_