1 #ifndef __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__DISCRETE__POISSON_HPP__
2 #define __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__DISCRETE__POISSON_HPP__
18 template <
bool propto,
19 typename T_n,
typename T_rate,
25 static const char*
function =
"stan::prob::poisson_log(%1%)";
45 "Rate parameter", &logp, Policy()))
48 "Rate parameter", &logp, Policy()))
52 "Random variable",
"Rate parameter",
65 for (
size_t i = 0; i < size; i++)
68 for (
size_t i = 0; i < size; i++)
69 if (lambda_vec[i] == 0 && n_vec[i] != 0)
76 for (
size_t i = 0; i < size; i++) {
77 if (!(lambda_vec[i] == 0 && n_vec[i] == 0)) {
79 logp -=
lgamma(n_vec[i] + 1.0);
87 operands_and_partials.
d_x1[i] += n_vec[i] /
value_of(lambda_vec[i]) - 1.0;
92 return operands_and_partials.
to_var(logp);
95 template <
bool propto,
105 template <
typename T_n,
112 return poisson_log<false>(n,lambda,Policy());
116 template <
typename T_n,
129 template <
bool propto,
130 typename T_n,
typename T_log_rate,
136 static const char*
function =
"stan::prob::poisson_log_log(%1%)";
157 "Log rate parameter", &logp, Policy()))
161 "Random variable",
"Log rate parameter",
175 for (
size_t i = 0; i < size; i++)
176 if (std::numeric_limits<double>::infinity() == alpha_vec[i])
178 for (
size_t i = 0; i < size; i++)
179 if (-std::numeric_limits<double>::infinity() == alpha_vec[i]
189 for (
size_t i = 0; i < size; i++) {
190 if (!(alpha_vec[i] == -std::numeric_limits<double>::infinity()
193 logp -=
lgamma(n_vec[i] + 1.0);
200 operands_and_partials.
d_x1[i] += n_vec[i] -
exp(
value_of(alpha_vec[i]));
202 return operands_and_partials.
to_var(logp);
205 template <
bool propto,
215 template <
typename T_n,
222 return poisson_log_log<false>(n,alpha,Policy());
226 template <
typename T_n,
var multiply_log(const var &a, const var &b)
Return the value of a*log(b).
double value_of(const agrad::var &v)
Return the value of the specified variable.
var lgamma(const stan::agrad::var &a)
The log gamma function for variables (C99).
var exp(const var &a)
Return the exponentiation of the specified variable (cmath).
boost::math::tools::promote_args< T_a, T_b >::type multiply_log(T_a a, T_b b)
double value_of(T x)
Return the value of the specified scalar argument converted to a double value.
bool check_not_nan(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
Checks if the variable y is nan.
bool check_consistent_sizes(const char *function, const T1 &x1, const T2 &x2, const char *name1, const char *name2, T_result *result, const Policy &)
bool check_nonnegative(const char *function, const T_y &y, const char *name, T_result *result, const Policy &)
boost::math::policies::policy default_policy
Default error-handling policy from Boost.
return_type< T_rate >::type poisson_log(const T_n &n, const T_rate &lambda, const Policy &)
return_type< T_log_rate >::type poisson_log_log(const T_n &n, const T_log_rate &alpha, const Policy &)
Probability, optimization and sampling library.
size_t length(const T &x)
size_t max_size(const T1 &x1, const T2 &x2)
int isinf(const stan::agrad::var &a)
Checks if the given number is infinite.
A variable implementation that stores operands and derivatives with respect to the variable.
VectorView< double *, is_vector< T1 >::value > d_x1
T_return_type to_var(double logp)
Metaprogram to determine if a type has a base scalar type that can be assigned to type double.
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...
boost::math::tools::promote_args< typename scalar_type< T1 >::type, typename scalar_type< T2 >::type, typename scalar_type< T3 >::type, typename scalar_type< T4 >::type, typename scalar_type< T5 >::type, typename scalar_type< T6 >::type >::type type