Loading [MathJax]/extensions/TeX/AMSsymbols.js
Automatic Differentiation
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
laplace_marginal_poisson_log_lpmf.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_MIX_PROB_LAPLACE_MARGINAL_POISSON_LOG_LPMF_HPP
2#define STAN_MATH_MIX_PROB_LAPLACE_MARGINAL_POISSON_LOG_LPMF_HPP
3
12
13namespace stan {
14namespace math {
15
31 template <typename Theta, typename YVec, typename Mean,
33 inline auto operator()(const Theta& theta, const YVec& y,
34 const std::vector<int>& y_index, Mean&& mean,
35 std::ostream* /*pstream*/) const {
36 Eigen::VectorXd counts_per_group = Eigen::VectorXd::Zero(theta.size());
37 Eigen::VectorXd n_per_group = Eigen::VectorXd::Zero(theta.size());
38
39 for (int i = 0; i < theta.size(); i++) {
40 counts_per_group(y_index[i] - 1) += y[i];
41 n_per_group(y_index[i] - 1) += 1;
42 }
43
44 auto theta_offset = to_ref(add(theta, mean));
45
46 return -sum(lgamma(add(counts_per_group, 1)))
47 + dot_product(theta_offset, counts_per_group)
48 - dot_product(n_per_group, exp(theta_offset));
49 }
50};
51
71template <bool propto = false, typename ThetaVec, typename Mean,
72 typename CovarFun, typename CovarArgs,
75 const std::vector<int>& y, const std::vector<int>& y_index, Mean&& mean,
76 CovarFun&& covariance_function, CovarArgs&& covar_args,
77 const ThetaVec& theta_0, double tolerance, int max_num_steps,
78 const int hessian_block_size, const int solver,
79 const int max_steps_line_search, std::ostream* msgs) {
80 laplace_options_user_supplied ops{hessian_block_size, solver,
81 max_steps_line_search, tolerance,
82 max_num_steps, value_of(theta_0)};
85 std::forward_as_tuple(y, y_index, std::forward<Mean>(mean)),
86 covariance_function, std::forward<CovarArgs>(covar_args), ops, msgs);
87}
88
105template <bool propto = false, typename CovarFun, typename CovarArgs,
106 typename Mean>
107inline auto laplace_marginal_poisson_log_lpmf(const std::vector<int>& y,
108 const std::vector<int>& y_index,
109 Mean&& mean,
110 CovarFun&& covariance_function,
111 CovarArgs&& covar_args,
112 std::ostream* msgs) {
115 std::forward_as_tuple(y, y_index, std::forward<Mean>(mean)),
116 covariance_function, std::forward<CovarArgs>(covar_args),
118}
119
120} // namespace math
121} // namespace stan
122
123#endif
require_t< is_eigen_vector< std::decay_t< T > > > require_eigen_vector_t
Require type satisfies is_eigen_vector.
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,...
Definition mean.hpp:20
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition value_of.hpp:18
auto laplace_marginal_poisson_log_lpmf(const std::vector< int > &y, const std::vector< int > &y_index, Mean &&mean, CovarFun &&covariance_function, CovarArgs &&covar_args, std::ostream *msgs)
Wrapper function around the laplace_marginal function for a log poisson likelihood.
fvar< T > lgamma(const fvar< T > &x)
Return the natural logarithm of the gamma function applied to the specified argument.
Definition lgamma.hpp:21
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
Definition sum.hpp:23
auto laplace_marginal_tol_poisson_log_lpmf(const std::vector< int > &y, const std::vector< int > &y_index, 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 log poisson likelihood.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:18
auto dot_product(const T_a &a, const T_b &b)
Returns the dot product of the specified vectors.
fvar< T > exp(const fvar< T > &x)
Definition exp.hpp:15
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 Theta &theta, const YVec &y, const std::vector< int > &y_index, Mean &&mean, std::ostream *) const
Returns the lpmf for a Poisson with a log link across multiple groups.