@@ -20,12 +20,14 @@ namespace stan {
2020namespace math {
2121
2222struct bernoulli_logit_likelihood {
23- template <typename T_theta , typename YVec>
24- inline auto operator ()(const T_theta & theta, const YVec& y,
25- const std::vector<int >& delta_int,
23+ template <typename ThetaVec , typename YVec, typename Mean >
24+ inline auto operator ()(const ThetaVec & theta, const YVec& y,
25+ const std::vector<int >& delta_int, const Mean& mean,
2626 std::ostream* pstream) const {
27- return sum (elt_multiply (theta, y)
28- - elt_multiply (to_vector (delta_int), log (add (1.0 , exp (theta)))));
27+ auto theta_offset = to_ref (add (theta, mean));
28+ return sum (
29+ elt_multiply (theta_offset, y)
30+ - elt_multiply (to_vector (delta_int), log (add (1.0 , exp (theta_offset)))));
2931 }
3032};
3133
@@ -39,19 +41,22 @@ struct bernoulli_logit_likelihood {
3941 * @tparam propto boolean ignored
4042 * @tparam ThetaVec A type inheriting from `Eigen::EigenBase`
4143 * with dynamic sized rows and 1 column.
44+ * @tparam Mean type of the mean of the latent normal distribution
4245 * \laplace_common_template_args
4346 * @param[in] y total counts per group. Second sufficient statistics.
4447 * @param[in] n_samples number of samples per group. First sufficient
45- * statistics.
48+ * statistics.
49+ * @param[in] mean the mean of the latent normal variable.
4650 * \laplace_common_args
4751 * \laplace_options
4852 * \msg_arg
4953 */
50- template <bool propto = false , typename ThetaVec, typename CovarFun,
51- typename CovarArgs, require_eigen_t <ThetaVec>* = nullptr >
54+ template <bool propto = false , typename ThetaVec, typename Mean,
55+ typename CovarFun, typename CovarArgs,
56+ require_eigen_vector_t <ThetaVec>* = nullptr >
5257inline auto laplace_marginal_tol_bernoulli_logit_lpmf (
5358 const std::vector<int >& y, const std::vector<int >& n_samples,
54- CovarFun&& covariance_function, CovarArgs&& covar_args,
59+ const Mean& mean, CovarFun&& covariance_function, CovarArgs&& covar_args,
5560 const ThetaVec& theta_0, double tolerance, int max_num_steps,
5661 const int hessian_block_size, const int solver,
5762 const int max_steps_line_search, std::ostream* msgs) {
@@ -60,7 +65,7 @@ inline auto laplace_marginal_tol_bernoulli_logit_lpmf(
6065 max_num_steps, value_of (theta_0)};
6166 return laplace_marginal_density (
6267 bernoulli_logit_likelihood{},
63- std::forward_as_tuple (to_vector (y), n_samples),
68+ std::forward_as_tuple (to_vector (y), n_samples, mean ),
6469 std::forward<CovarFun>(covariance_function),
6570 std::forward<CovarArgs>(covar_args), ops, msgs);
6671}
@@ -73,21 +78,24 @@ inline auto laplace_marginal_tol_bernoulli_logit_lpmf(
7378 * for more details.
7479 *
7580 * @tparam propto boolean ignored
81+ * @tparam Mean type of the mean of the latent normal distribution
7682 * \laplace_common_template_args
7783 * @param[in] y total counts per group. Second sufficient statistics.
7884 * @param[in] n_samples number of samples per group. First sufficient
79- * statistics.
85+ * statistics.
86+ * @param[in] mean the mean of the latent normal variable.
8087 * \laplace_common_args
8188 * \msg_arg
8289 */
83- template <bool propto = false , typename CovarFun, typename CovarArgs>
90+ template <bool propto = false , typename Mean, typename CovarFun,
91+ typename CovarArgs>
8492inline auto laplace_marginal_bernoulli_logit_lpmf (
8593 const std::vector<int >& y, const std::vector<int >& n_samples,
86- CovarFun&& covariance_function, CovarArgs&& covar_args,
94+ const Mean& mean, CovarFun&& covariance_function, CovarArgs&& covar_args,
8795 std::ostream* msgs) {
8896 return laplace_marginal_density (
8997 bernoulli_logit_likelihood{},
90- std::forward_as_tuple (to_vector (y), n_samples),
98+ std::forward_as_tuple (to_vector (y), n_samples, mean ),
9199 std::forward<CovarFun>(covariance_function),
92100 std::forward<CovarArgs>(covar_args), laplace_options_default{}, msgs);
93101}
0 commit comments