1#ifndef STAN_MATH_MIX_PROB_LAPLACE_MARGINAL_BERNOULLI_LOGIT_LPMF_HPP
2#define STAN_MATH_MIX_PROB_LAPLACE_MARGINAL_BERNOULLI_LOGIT_LPMF_HPP
42 template <
typename ThetaVec,
typename YVec,
typename Mean>
43 inline auto operator()(
const ThetaVec& theta,
const YVec& y,
44 const std::vector<int>& y_index, Mean&&
mean,
45 std::ostream* msgs)
const {
46 Eigen::VectorXd counts_per_group = Eigen::VectorXd::Zero(theta.size());
47 Eigen::VectorXd n_per_group = Eigen::VectorXd::Zero(theta.size());
49 for (
int i = 0; i < theta.size(); i++) {
50 counts_per_group(y_index[i] - 1) += y[i];
51 n_per_group(y_index[i] - 1) += 1;
82template <
bool propto =
false,
typename Mean,
typename CovarFun,
83 typename CovarArgs,
typename OpsTuple>
85 const std::vector<int>& y,
const std::vector<int>& y_index, Mean&&
mean,
86 int hessian_block_size, CovarFun&& covariance_function,
87 CovarArgs&& covar_args, OpsTuple&& ops, std::ostream* msgs) {
90 options.hessian_block_size = hessian_block_size;
93 std::forward_as_tuple(
to_vector(y), y_index, std::forward<Mean>(
mean)),
94 std::forward<CovarFun>(covariance_function),
95 std::forward<CovarArgs>(covar_args), std::move(options), msgs);
116template <
bool propto =
false,
typename Mean,
typename CovarFun,
119 const std::vector<int>& y,
const std::vector<int>& y_index, Mean&&
mean,
120 int hessian_block_size, CovarFun&& covariance_function,
121 CovarArgs&& covar_args, std::ostream* msgs) {
125 std::forward_as_tuple(
to_vector(y), y_index, std::forward<Mean>(
mean)),
126 std::forward<CovarFun>(covariance_function),
127 std::forward<CovarArgs>(covar_args), options, msgs);
elt_multiply_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_multiply(T_a &&a, T_b &&b)
addition_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > add(T_a &&a, T_b &&b)
auto to_vector(T_x &&x)
Returns input matrix reshaped into a vector.
Reference for calculations of marginal and its gradients: Margossian et al (2020),...
constexpr auto tuple_to_laplace_options(Options &&ops)
scalar_type_t< T > mean(const T &m)
Returns the sample mean (i.e., average) of the coefficients in the specified std vector,...
auto laplace_marginal_density(LLFun &&ll_fun, LLTupleArgs &&ll_args, CovarFun &&covariance_function, CovarArgs &&covar_args, const laplace_options< InitTheta > &options, std::ostream *msgs)
For a latent Gaussian model with global parameters phi, latent variables theta, and observations y,...
fvar< T > log1p_exp(const fvar< T > &x)
auto laplace_marginal_bernoulli_logit_lpmf(const std::vector< int > &y, const std::vector< int > &y_index, Mean &&mean, int hessian_block_size, CovarFun &&covariance_function, CovarArgs &&covar_args, std::ostream *msgs)
Wrapper function around the laplace_marginal function for a logistic Bernoulli likelihood.
auto laplace_marginal_tol_bernoulli_logit_lpmf(const std::vector< int > &y, const std::vector< int > &y_index, Mean &&mean, int hessian_block_size, CovarFun &&covariance_function, CovarArgs &&covar_args, OpsTuple &&ops, std::ostream *msgs)
Wrapper function around the laplace_marginal function for a logistic Bernoulli likelihood.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
auto operator()(const ThetaVec &theta, const YVec &y, const std::vector< int > &y_index, Mean &&mean, std::ostream *msgs) const
Returns the lpmf for a Bernoulli with a logit link across multiple groups.