1#ifndef STAN_MATH_MIX_PROB_LAPLACE_MARGINAL_NEG_BINOMIAL_2_LOG_LPMF_HPP
2#define STAN_MATH_MIX_PROB_LAPLACE_MARGINAL_NEG_BINOMIAL_2_LOG_LPMF_HPP
27 template <
typename ThetaVec,
typename Eta,
typename Mean,
29 inline auto operator()(
const ThetaVec& theta,
const Eta& eta,
30 const std::vector<int>& y,
31 const std::vector<int>& y_index, Mean&&
mean,
32 std::ostream* pstream)
const {
33 Eigen::VectorXi n_per_group = Eigen::VectorXi::Zero(theta.size());
34 Eigen::VectorXi counts_per_group = Eigen::VectorXi::Zero(theta.size());
36 for (
int i = 0; i < y.size(); i++) {
37 n_per_group[y_index[i] - 1]++;
38 counts_per_group[y_index[i] - 1] += y[i];
40 Eigen::Map<const Eigen::VectorXi> y_map(y.data(), y.size());
43 auto log_eta_plus_exp_theta =
eval(
log(
add(eta,
exp(theta_offset))));
47 subtract(theta_offset, log_eta_plus_exp_theta)),
74template <
bool propto =
false,
typename Eta,
typename ThetaVec,
typename Mean,
75 typename CovarFun,
typename CovarArgs,
78 const std::vector<int>& y,
const std::vector<int>& y_index,
const Eta& eta,
79 Mean&&
mean, CovarFun&& covariance_function, CovarArgs&& covar_args,
80 const ThetaVec& theta_0,
double tolerance,
int max_num_steps,
81 const int hessian_block_size,
const int solver,
82 const int max_steps_line_search, std::ostream* msgs) {
84 max_steps_line_search, tolerance,
88 std::forward_as_tuple(eta, y, y_index, std::forward<Mean>(
mean)),
89 std::forward<CovarFun>(covariance_function),
90 std::forward<CovarArgs>(covar_args), ops, msgs);
111template <
bool propto =
false,
typename Eta,
typename Mean,
typename CovarFun,
114 const std::vector<int>& y,
const std::vector<int>& y_index,
const Eta& eta,
115 Mean&&
mean, CovarFun&& covariance_function, CovarArgs&& covar_args,
116 std::ostream* msgs) {
119 std::forward_as_tuple(eta, y, y_index, std::forward<Mean>(
mean)),
120 std::forward<CovarFun>(covariance_function),
125 template <
typename ThetaVec,
typename Eta,
typename Mean,
127 inline auto operator()(
const ThetaVec& theta,
const Eta& eta,
128 const std::vector<int>& y,
129 const std::vector<int>& n_per_group,
130 const std::vector<int>& counts_per_group, Mean&&
mean,
131 std::ostream* pstream)
const {
132 Eigen::Map<const Eigen::VectorXi> y_map(y.data(), y.size());
133 Eigen::Map<const Eigen::VectorXi> n_per_group_map(n_per_group.data(),
135 Eigen::Map<const Eigen::VectorXi> counts_per_group_map(
136 counts_per_group.data(), counts_per_group.size());
139 auto log_eta_plus_exp_theta =
eval(
log(
add(eta,
exp(theta_offset))));
144 subtract(theta_offset, log_eta_plus_exp_theta)),
171template <
bool propto =
false,
typename Eta,
typename ThetaVec,
typename Mean,
172 typename CovarFun,
typename CovarArgs,
175 const std::vector<int>& y,
const std::vector<int>& n_per_group,
176 const std::vector<int>& counts_per_group,
const Eta& eta, Mean&&
mean,
177 CovarFun&& covariance_function, CovarArgs&& covar_args,
178 const ThetaVec& theta_0,
double tolerance,
int max_num_steps,
179 const int hessian_block_size,
const int solver,
180 const int max_steps_line_search, std::ostream* msgs) {
182 max_steps_line_search, tolerance,
186 std::forward_as_tuple(eta, y, n_per_group, counts_per_group,
187 std::forward<Mean>(
mean)),
188 std::forward<CovarFun>(covariance_function),
189 std::forward<CovarArgs>(covar_args), ops, msgs);
210template <
bool propto =
false,
typename Eta,
typename Mean,
typename CovarFun,
213 const std::vector<int>& y,
const std::vector<int>& n_per_group,
214 const std::vector<int>& counts_per_group,
const Eta& eta, Mean&&
mean,
215 CovarFun&& covariance_function, CovarArgs&& covar_args,
216 std::ostream* msgs) {
219 std::forward_as_tuple(eta, y, n_per_group, counts_per_group,
220 std::forward<Mean>(
mean)),
221 std::forward<CovarFun>(covariance_function),
require_t< is_eigen_vector< std::decay_t< T > > > require_eigen_vector_t
Require type satisfies is_eigen_vector.
require_all_t< is_eigen_vector< std::decay_t< Types > >... > require_all_eigen_vector_t
Require all of the types satisfy is_eigen_vector.
elt_multiply_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > elt_multiply(T_a &&a, T_b &&b)
subtraction_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > subtract(T_a &&a, T_b &&b)
binomial_coefficient_log_< as_operation_cl_t< T1 >, as_operation_cl_t< T2 > > binomial_coefficient_log(T1 &&a, T2 &&b)
addition_< as_operation_cl_t< T_a >, as_operation_cl_t< T_b > > add(T_a &&a, T_b &&b)
Reference for calculations of marginal and its gradients: Margossian et al (2020),...
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_tol_neg_binomial_2_log_lpmf(const std::vector< int > &y, const std::vector< int > &y_index, const Eta &eta, Mean &&mean, CovarFun &&covariance_function, CovarArgs &&covar_args, const ThetaVec &theta_0, double tolerance, int max_num_steps, const int hessian_block_size, const int solver, const int max_steps_line_search, std::ostream *msgs)
Wrapper function around the laplace_marginal function for a negative binomial likelihood.
auto laplace_marginal_neg_binomial_2_log_summary_lpmf(const std::vector< int > &y, const std::vector< int > &n_per_group, const std::vector< int > &counts_per_group, const Eta &eta, Mean &&mean, CovarFun &&covariance_function, CovarArgs &&covar_args, std::ostream *msgs)
Wrapper function around the laplace_marginal function for a negative binomial likelihood.
auto laplace_marginal_neg_binomial_2_log_lpmf(const std::vector< int > &y, const std::vector< int > &y_index, const Eta &eta, Mean &&mean, CovarFun &&covariance_function, CovarArgs &&covar_args, std::ostream *msgs)
Wrapper function around the laplace_marginal function for a negative binomial likelihood.
T eval(T &&arg)
Inputs which have a plain_type equal to the own time are forwarded unmodified (for Eigen expressions ...
T value_of(const fvar< T > &v)
Return the value of the specified variable.
fvar< T > log(const fvar< T > &x)
auto multiply(const Mat1 &m1, const Mat2 &m2)
Return the product of the specified matrices.
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
auto laplace_marginal_tol_neg_binomial_2_log_summary_lpmf(const std::vector< int > &y, const std::vector< int > &n_per_group, const std::vector< int > &counts_per_group, const Eta &eta, Mean &&mean, CovarFun &&covariance_function, CovarArgs &&covar_args, const ThetaVec &theta_0, double tolerance, int max_num_steps, const int hessian_block_size, const int solver, const int max_steps_line_search, std::ostream *msgs)
Wrapper function around the laplace_marginal function for a negative binomial likelihood.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
fvar< T > exp(const fvar< T > &x)
double 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,...
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
auto operator()(const ThetaVec &theta, const Eta &eta, const std::vector< int > &y, const std::vector< int > &n_per_group, const std::vector< int > &counts_per_group, Mean &&mean, std::ostream *pstream) const
auto operator()(const ThetaVec &theta, const Eta &eta, const std::vector< int > &y, const std::vector< int > &y_index, Mean &&mean, std::ostream *pstream) const