1#ifndef STAN_MATH_PRIM_FUN_POISSON_BINOMIAL_LOG_PROBS_HPP
2#define STAN_MATH_PRIM_FUN_POISSON_BINOMIAL_LOG_PROBS_HPP
24template <
typename T_theta,
typename T_scalar = scalar_type_t<T_theta>,
25 require_eigen_vector_t<T_theta>* =
nullptr>
27 int size_theta = theta.size();
31 Eigen::Matrix<T_scalar, Eigen::Dynamic, Eigen::Dynamic> alpha(size_theta + 1,
36 for (
int i = 0; i < size_theta; ++i) {
38 alpha(i + 1, 0) = alpha(i, 0) + log1m_theta[i];
41 for (
int j = 0; j < std::min(y, i); ++j) {
42 alpha(i + 1, j + 1) =
log_sum_exp(alpha(i, j) + log_theta[i],
43 alpha(i, j + 1) + log1m_theta[i]);
48 alpha(i + 1, i + 1) = alpha(i, i) + log_theta(i);
52 return alpha.row(size_theta);
55template <
typename T_y,
typename T_theta, require_vt_
integral<T_y>* =
nullptr>
59 std::vector<Eigen::Matrix<T_scalar, Eigen::Dynamic, 1>> result(max_sizes);
63 for (
size_t i = 0; i < max_sizes; ++i) {
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...
int64_t size_mvt(const ScalarT &)
Provides the size of a multivariate argument.
int64_t size(const T &m)
Returns the size (number of the elements) of a matrix_cl or var_value<matrix_cl<T>>.
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...
fvar< T > log(const fvar< T > &x)
fvar< T > log1m(const fvar< T > &x)
fvar< T > log_sum_exp(const fvar< T > &x1, const fvar< T > &x2)
typename plain_type< T >::type plain_type_t
typename scalar_type< T >::type scalar_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...