Automatic Differentiation
 
Loading...
Searching...
No Matches
poisson_binomial_cdf.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_PROB_POISSON_BINOMIAL_CDF_HPP
2#define STAN_MATH_PRIM_PROB_POISSON_BINOMIAL_CDF_HPP
3
18
19namespace stan {
20namespace math {
21
35template <bool propto, typename T_y, typename T_theta>
37 const T_theta& theta) {
38 static constexpr const char* function = "poisson_binomial_cdf";
39
40 auto size_theta = size_mvt(theta);
41 if (size_theta > 1) {
42 check_consistent_sizes(function, "Successes variables", y,
43 "Probability parameters", theta);
44 }
45
46 auto max_sz = std::max(stan::math::size(y), size_theta);
47 scalar_seq_view<T_y> y_vec(y);
48 vector_seq_view<T_theta> theta_vec(theta);
49
50 for (size_t i = 0; i < max_sz; ++i) {
51 check_bounded(function, "Successes variable", y_vec[i], 0,
52 theta_vec[i].size());
53 check_finite(function, "Probability parameters", theta_vec[i]);
54 check_bounded(function, "Probability parameters", theta_vec[i], 0.0, 1.0);
55 }
56
57 return_type_t<T_theta> lcdf = 0.0;
58 for (size_t i = 0; i < max_sz; ++i) {
59 auto x = log_sum_exp(poisson_binomial_log_probs(y_vec[i], theta_vec[i]));
60 lcdf += x;
61 }
62 return exp(lcdf);
63}
64
65template <typename T_y, typename T_theta>
67 const T_theta& theta) {
68 return poisson_binomial_cdf<false>(y, theta);
69}
70
71} // namespace math
72} // namespace stan
73#endif
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
This class provides a low-cost wrapper for situations where you either need an Eigen Vector or RowVec...
return_type_t< T_theta > poisson_binomial_cdf(const T_y &y, const T_theta &theta)
Returns the CDF for the Poisson-binomial distribution evaluated at the specified number of successes ...
int64_t size_mvt(const ScalarT &)
Provides the size of a multivariate argument.
Definition size_mvt.hpp:25
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
Definition size.hpp:19
plain_type_t< T_theta > poisson_binomial_log_probs(int y, const T_theta &theta)
Returns the last row of the log probability matrix of the Poisson-Binomial distribution given the num...
void check_bounded(const char *function, const char *name, const T_y &y, const T_low &low, const T_high &high)
Check if the value is between the low and high values, inclusively.
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
fvar< T > log_sum_exp(const fvar< T > &x1, const fvar< T > &x2)
fvar< T > exp(const fvar< T > &x)
Definition exp.hpp:13
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...