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_density_est()

template<typename LLFun , typename LLTupleArgs , typename CovarFun , typename ThetaVec , typename CovarArgs , require_t< is_all_arithmetic_scalar< ThetaVec, CovarArgs > > * = nullptr, require_eigen_vector_t< ThetaVec > * = nullptr>
auto stan::math::internal::laplace_marginal_density_est ( LLFun &&  ll_fun,
LLTupleArgs &&  ll_args,
ThetaVec &&  theta_0,
CovarFun &&  covariance_function,
CovarArgs &&  covar_args,
const laplace_options options,
std::ostream *  msgs 
)
inline

For a latent Gaussian model with hyperparameters phi and latent variables theta, and observations y, this function computes an approximation of the log marginal density, p(y | phi).

This is done by marginalizing out theta, using a Laplace approxmation. The latter is obtained by finding the mode, via Newton's method, and computing the Hessian of the likelihood.

The convergence criterion for the Newton is a small change in log marginal density. The user controls the tolerance (i.e. threshold under which change is deemed small enough) and maximum number of steps.

A description of this algorithm can be found in:

  • (2023) Margossian, "General Adjoint-Differentiated Laplace approximation", https://arxiv.org/pdf/2306.14976. Additional references include:
  • (2020) Margossian et al, "HMC using an adjoint-differentiated Laplace...", NeurIPS, https://arxiv.org/abs/2004.12550.
  • (2006) Rasmussen and Williams, "Gaussian Processes for Machine Learning", second edition, MIT Press, algorithm 3.1.

Variables needed for the gradient or generating quantities are stored by reference.

Template Parameters
LLFunType with a valid operator(ThetaVec, InnerLLTupleArgs) where InnerLLTupleArgs are the elements of LLTupleArgs
LLTupleArgsA tuple whose elements follow the types required for LLFun
ThetaVecA type inheriting from Eigen::EigenBase with dynamic sized rows and 1 column.
CovarFunA functor with an operator()(CovarArgsElements..., {TrainTupleElements...| PredTupleElements...}) method. The operator() method should accept as arguments the inner elements of CovarArgs. The return type of the operator() method should be a type inheriting from Eigen::EigenBase with dynamic sized rows and columns.
CovarArgsA tuple of types to passed as the first arguments of CovarFun::operator()
Parameters
[in]ll_funA log likelihood functor
[in]ll_argsTuple containing parameters for LLFun
[in]theta_0the initial guess for the Laplace approximation.
[in]covariance_functiona function which returns the prior covariance.
[in]covar_argsarguments for the covariance function.
[in]optionsA set of options for tuning the solver
[in,out]msgsstream for messages from likelihood and covariance
Returns
A struct containing
  1. lmd the log marginal density, p(y | phi)
  2. covariance the evaluated covariance function for the latent gaussian variable
  3. theta a vector to store the mode
  4. W_r A sparse matrix containing the square root of the negative hessian, if solver 1 or 2 are used.
  5. L cholesky decomposition of stabilized inverse covariance
  6. a element in the Newton step
  7. l_grad the log density of the likelihood, evaluated at the mode

Definition at line 454 of file laplace_marginal_density.hpp.