1#ifndef STAN_MATH_PRIM_FUN_POISSON_BINOMIAL_LOG_PROBS_HPP
2#define STAN_MATH_PRIM_FUN_POISSON_BINOMIAL_LOG_PROBS_HPP
25template <
typename T_theta,
typename T_scalar = scalar_type_t<T_theta>,
26 require_vector_t<T_theta>* =
nullptr>
28 int y,
const T_theta& theta) {
29 int size_theta = theta.size();
33 Eigen::Matrix<T_scalar, Eigen::Dynamic, Eigen::Dynamic> alpha(y + 1,
38 for (
int i = 0; i < size_theta; ++i) {
40 alpha(0, i + 1) = alpha(0, i) + log1m_theta[i];
43 for (
int j = 0; j < std::min(y, i); ++j) {
44 alpha(j + 1, i + 1) =
log_mix(theta[i], alpha(j, i), alpha(j + 1, i));
49 alpha(i + 1, i + 1) = alpha(i, i) + log_theta[i];
53 return alpha.col(size_theta);
56template <
typename T_y,
typename T_theta, require_vt_
integral<T_y>* =
nullptr>
60 std::vector<Eigen::Matrix<T_scalar, Eigen::Dynamic, 1>> result(max_sizes);
64 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>>.
Eigen::Matrix< T_scalar, -1, 1 > 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 > log_mix(const fvar< T > &theta, const fvar< T > &lambda1, const fvar< T > &lambda2)
Return the log mixture density with specified mixing proportion and log densities and its derivative ...
fvar< T > log1m(const fvar< T > &x)
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 ...