From a225dd6731960f488f30d17141eafb5cc65f37f8 Mon Sep 17 00:00:00 2001 From: Zhi Ling <1336265834@qq.com> Date: Tue, 19 Nov 2024 15:21:19 +0800 Subject: [PATCH] fix issues --- stan/math/prim/prob/beta_neg_binomial_rng.hpp | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/stan/math/prim/prob/beta_neg_binomial_rng.hpp b/stan/math/prim/prob/beta_neg_binomial_rng.hpp index 7cd566f8640..19d0e49f7cf 100644 --- a/stan/math/prim/prob/beta_neg_binomial_rng.hpp +++ b/stan/math/prim/prob/beta_neg_binomial_rng.hpp @@ -9,7 +9,7 @@ namespace stan { namespace math { /** \ingroup prob_dists - * Return a beta-negative binomial random variate with given number of + * Return a beta-negative binomial random variate with the given number of * successes, prior success, and prior failure parameters, using the given * random number generator. * @@ -22,17 +22,16 @@ namespace math { * @tparam RNG type of random number generator * * @param r (Sequence of) number of successes parameter(s) - * @param alpha (Sequence of) positive success parameter(s) - * @param beta (Sequence of) positive failure parameter(s) + * @param alpha (Sequence of) prior success parameter(s) + * @param beta (Sequence of) prior failure parameter(s) * @param rng random number generator - * @return (Sequence of) beta-binomial random variate(s) - * @throw std::domain_error if r is negative, or alpha or beta are nonpositive + * @return (Sequence of) beta-negative binomial random variate(s) + * @throw std::domain_error if r, alpha, or beta are nonpositive * @throw std::invalid_argument if non-scalar arguments are of different sizes */ -template -inline typename VectorBuilder::type -beta_neg_binomial_rng(const T_r &r, const T_alpha &alpha, const T_beta &beta, - RNG &rng) { +template +inline auto beta_neg_binomial_rng(const T_r &r, const T_alpha &alpha, + const T_beta &beta, RNG &rng) { using T_r_ref = ref_type_t; using T_alpha_ref = ref_type_t; using T_beta_ref = ref_type_t; @@ -55,8 +54,8 @@ beta_neg_binomial_rng(const T_r &r, const T_alpha &alpha, const T_beta &beta, size_t size_p = stan::math::size(p); VectorBuilder odds_ratio_p(size_p); for (size_t n = 0; n < size_p; ++n) { - odds_ratio_p[n] = stan::math::exp(stan::math::log(p_vec.val(n)) - - stan::math::log((1 - p_vec.val(n)))); + odds_ratio_p[n] + = stan::math::exp(stan::math::log(p_vec.val(n)) - log1m(p_vec.val(n))); } return neg_binomial_rng(r_ref, odds_ratio_p.data(), rng);