Thanks for the replies!
I added the options following the example codes in the User manual:
functions {
real partial_sum_2_lpmf(
... // other arguments
// Laplace approximation options
data tuple(vector, real, int, int, int, int) laplace_ops
){
... // codes for LL calculation with laplace_marginal_tol()
}
}
data {
// options for Laplace approximation
real<lower=0> laplace_tol; // tolerance for optimizer
int<lower=0> laplace_max_iter; // maximum number of steps for optimizer
int<lower=1, upper=3> laplace_solver; // Newton solver type being used
}
transformed data{
// For laplace approximation
tuple(vector[M-1], real, int, int, int, int) laplace_ops = generate_laplace_options(M-1);
laplace_ops.2 = laplace_tol; // tolerance for optimizer
laplace_ops.3 = laplace_max_iter; // maximum number of steps for optimizer
laplace_ops.4 = laplace_solver; // solver type being used
}
However, when I tried to compile the Stan program, I got errors with the message:
Compiling Stan program...
In file included from /var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:3:
In file included from stan/lib/stan_math/stan/math/mix.hpp:10:
In file included from stan/lib/stan_math/stan/math/mix/functor.hpp:11:
In file included from stan/lib/stan_math/stan/math/mix/functor/laplace_base_rng.hpp:5:
In file included from stan/lib/stan_math/stan/math/mix/functor/laplace_marginal_density.hpp:5:
stan/lib/stan_math/stan/math/mix/functor/laplace_marginal_density_estimator.hpp:157:30: error: no matching function for call to 'forward'
157 | value_of(std::get<0>(std::forward<Ops>(ops))),
| ^~~~~~~~~~~~~~~~~
stan/lib/stan_math/stan/math/mix/prob/laplace_marginal.hpp:38:19: note: in instantiation of function template specialization 'stan::math::internal::tuple_to_laplace_options<const std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int> &>' requested here
38 | = internal::tuple_to_laplace_options(std::forward<OpsTuple>(ops));
| ^
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:1401:23: note: in instantiation of function template specialization 'stan::math::laplace_marginal_tol<false, glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::ll_function_functor__, std::tuple<const int &, std::vector<int> &&, const int &, const Eigen::Matrix<double, -1, -1> &, Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, 1, true> &&, const Eigen::Map<Eigen::Matrix<double, -1, -1>> &>, glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::cov_function_functor__, std::tuple<const Eigen::Matrix<double, -1, -1> &, const int &>, const std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int> &>' requested here
1401 | stan::math::laplace_marginal_tol(ll_function_functor__(),
| ^
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/Rtmp
mH8MbS/model-5fad2d23e8fa.hpp:531:12: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::partial_sum_2_lpmf<false, std::vector<int>, int, unsigned long, int, std::vector<std::vector<int>>, std::vector<int>, std::vector<std::vector<double>>, std::vector<Eigen::Matrix<double, -1, -1>>, Eigen::Transpose<const Eigen::Matrix<double, -1, -1>>, int, Eigen::Map<Eigen::Matrix<double, -1, -1>>, std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int>, nullptr>' requested here
531 | return partial_sum_2_lpmf<propto__>(idx_y, (start + 1), (end + 1),
| ^
/Users/a1239028/.cmdstan/cmdstan-2.39.0/stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:216:10: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::partial_sum_2_lpmf_rsfunctor__<false>::operator()<std::vector<int>, int, unsigned long, int, std::vector<std::vector<int>>, std::vector<int>, std::vector<std::vector<double>>, std::vector<Eigen::Matrix<double, -1, -1>>, Eigen::Transpose<const Eigen::Matrix<double, -1, -1>>, int, Eigen::Map<Eigen::Matrix<double, -1, -1>>, std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int>, nullptr>' requested here
216 | return ReduceFunction()(std::forward<Vec>(vmapped), 0, vmapped.size() - 1,
| ^
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:2676:12: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model::log_prob_impl<false, false, Eigen::Matrix<double, -1, 1>, Eigen::Matrix<int, -1, 1>, nullptr, nullptr, nullptr>' requested here
2676 | return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
| ^
/Users/a1239028/.cmdstan/cmdstan-2.39.0/stan/src/stan/model/model_base_crtp.hpp:93:50: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model::log_prob<false, false, double>' requested here
93 | return static_cast<const M*>(this)->template log_prob<false, false, double>(
| ^
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:1467:3: note: in instantiation of member function 'stan::model::model_base_crtp<gl
m_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model>::log_prob' requested here
1467 | ~glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model()
| ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__utility/forward.h:25:1: note: candidate function template not viable: 1st argument ('const std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int>') would lose const qualifier
25 | forward(_LIBCPP_LIFETIMEBOUND __libcpp_remove_reference_t<_Tp>& __t) _NOEXCEPT {
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__utility/forward.h:31:1: note: candidate function template not viable: 1st argument ('const std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int>') would lose const qualifier
31 | forward(_LIBCPP_LIFETIMEBOUND __libcpp_remove_reference_t<_Tp>&& __t) _NOEXCEPT {
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:3:
In file included from stan/lib/stan_math/stan/math/mix.hpp:33:
In file included from stan/lib/stan_math/stan/math/mix/prob.hpp:8:
stan/lib/stan_math/stan/math/mix/prob/laplace_marginal.hpp:38:9: error: no matching function for call to 'tuple_to_laplace_options'
38 | = internal::tuple_to_laplace_options(std::forward<OpsTuple>(ops));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:1401:23: note: in instantiation of function template specialization 'stan::math::laplace_marginal_tol<false, glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::ll_function_functor__, std::tuple<const int &, std::vector<int> &&, const int &, const Eigen::Matrix<stan::math::var_value<double>, -1, -1> &, Eigen::Block<Eigen::Matrix<stan::math::var_value<double>, -1, -1>, -1, 1, true> &&, const Eigen::Map<Eigen::Matrix<double, -1, -1>> &>, glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::cov_function_functor__, std::tuple<const Eigen::Matrix<stan::math::var_value<double>, -1, -1> &, const int &>, const std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int> &>' requested here
1401 | stan::math::laplace_marginal_tol(ll_function_functor__(),
| ^
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:531:12: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::partial_sum_2_lpmf<false, std::vector<int>, int, unsigned long, int, std::vector<std::vector<int>>, std::vector<int>, std::vector<std::vector<double>>, std::vector<Eigen::Matrix<stan::math::var_value<double>, -1, -1>>, Eigen::Transpose<const Eigen::Matrix<stan::math::var_value<double>, -1, -1>>, in
t, Eigen::Map<Eigen::Matrix<double, -1, -1>>, std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int>, nullptr>' requested here
531 | return partial_sum_2_lpmf<propto__>(idx_y, (start + 1), (end + 1),
| ^
/Users/a1239028/.cmdstan/cmdstan-2.39.0/stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:216:10: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::partial_sum_2_lpmf_rsfunctor__<false>::operator()<std::vector<int>, int, unsigned long, int, std::vector<std::vector<int>>, std::vector<int>, std::vector<std::vector<double>>, std::vector<Eigen::Matrix<stan::math::var_value<double>, -1, -1>>, Eigen::Transpose<const Eigen::Matrix<stan::math::var_value<double>, -1, -1>>, int, Eigen::Map<Eigen::Matrix<double, -1, -1>>, std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int>, nullptr>' requested here
216 | return ReduceFunction()(std::forward<Vec>(vmapped), 0, vmapped.size() - 1,
| ^
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:2676:12: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model::log_prob_impl<false, false, Eigen::Matrix<stan::math::var_value<double>, -1, 1>, Eigen::Matrix<int, -1, 1>, nullptr, nullptr, nullptr>' requested here
2676 | return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
| ^
/Users/a1239028/.cmdstan/cmdstan-2.39.0/stan/src/stan/model/model_base_crtp.hpp:98:50: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model::log_prob<false, false, stan::math::var_value<doubl
e>>' requested here
98 | return static_cast<const M*>(this)->template log_prob<false, false>(theta,
| ^
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:1467:3: note: in instantiation of member function 'stan::model::model_base_crtp<glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model>::log_prob' requested here
1467 | ~glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model()
| ^
stan/lib/stan_math/stan/math/mix/functor/laplace_marginal_density_estimator.hpp:110:23: note: candidate template ignored: substitution failure [with Options = const std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int> &]
110 | inline constexpr auto tuple_to_laplace_options(Options&& ops) {
| ^
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:1401:11: error: no matching function for call to 'laplace_marginal_tol'
1401 | stan::math::laplace_marginal_tol(ll_function_functor__(),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:531:12: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::partial_sum_2_lpmf<true, std::vector<int>, int, unsigned long, int, std::vector<std::vector<int>>, std::vector<int>, std::vector<std::vector<double>>, std::vector<Eigen::Matrix<double, -1, -1>>, Eigen::Transpose<const Eigen::Matrix<double, -1, -1>>, int, Eigen::Map<Eigen::Matrix<double, -1, -1>>, std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int>, nullptr>' requested here
531 | return partial_sum_2_lpmf<propto__>(idx_y, (start + 1), (end + 1),
| ^
/Users/a1239028/.cmdstan/cmdstan-2.39.0/stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:216:10: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::partial_sum_2_lpmf_rsfunctor__<true>::operator()<std::vector<int>, int, unsigned long, int, std::vector<std::vector<int>>, std::vector<int>, std::vector<std::vector<double>>, std::vector<Eigen::Matrix<double, -1, -1>>, Eigen::Transpose<const Eigen::Matrix<double, -1, -1>>, int, Eigen::Map<Eigen::Matrix<double, -1, -1>>, std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int>, nullptr>' requested here
216 | return ReduceFunction()(std::forward<Vec>(vmapped), 0, vmapped.size() - 1,
| ^
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:2676:12: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_app
roximation_model_namespace::glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model::log_prob_impl<true, false, Eigen::Matrix<double, -1, 1>, Eigen::Matrix<int, -1, 1>, nullptr, nullptr, nullptr>' requested here
2676 | return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
| ^
/Users/a1239028/.cmdstan/cmdstan-2.39.0/stan/src/stan/model/model_base_crtp.hpp:115:50: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model::log_prob<true, false, double>' requested here
115 | return static_cast<const M*>(this)->template log_prob<true, false>(theta,
| ^
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:1467:3: note: in instantiation of member function 'stan::model::model_base_crtp<glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model>::log_prob_propto' requested here
1467 | ~glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model()
| ^
stan/lib/stan_math/stan/math/mix/prob/laplace_marginal.hpp:32:13:
note: candidate template ignored: substitution failure [with propto = false, LFun = ll_function_functor__, LArgs = tuple<const int &, vector<int, allocator<int>> &&, const int &, const Matrix<double, -1, -1, 0, -1, -1> &, Block<Matrix<double, -1, -1, 0, -1, -1>, -1, 1, true> &&, const Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0>> &>, CovarFun = cov_function_functor__, CovarArgs = tuple<const Matrix<double, -1, -1, 0, -1, -1> &, const int &>, OpsTuple = const std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int> &]
32 | inline auto laplace_marginal_tol(LFun&& L_f, LArgs&& l_args,
| ^
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:1401:11: error: no matching function for call to 'laplace_marginal_tol'
1401 | stan::math::laplace_marginal_tol(ll_function_functor__(),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:531:12: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::partial_sum_2_lpmf<true, std::vector<int>, int, unsigned long, int, std::vector<std::vector<int>>, std::vector<int>, std::vector<std::vector<double>>, std::vector<Eigen::Matrix<stan::math::var_value<double>, -1, -1>>, Eigen::Transpose<const Eigen::Matrix<stan::math::var_value<double>, -1, -1>>, int, Eigen::Map<Eigen::Matrix<double, -1, -1>>, std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int>, nullptr>' requested here
531 | return partial_sum_2_lpmf<propto__>(idx_y, (start + 1), (end + 1),
| ^
/Users/a1239028/.cmdstan/cmdstan-2.39.0/stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:216:10: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::partial_sum_2_lpmf_rsfunctor__<true>::operator()<std::vector<int>, int, unsigned long, int, std::vector<std::vector<int>>, std::vector<int>, std::vector<std::vector<double>>, std::vector<Eigen::Matrix<stan::math::var_value<double>, -1, -1>>, Eigen::Transpose<const Eigen::Matrix<stan::math::var_value<double>, -1, -1>>, int, Eigen::Map<Eigen::Matrix<double, -1, -1>>, std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int>, nullptr>' requested here
216 | return ReduceFunction()(std::forward<Vec>(vmapped), 0, vmapped.size() - 1,
| ^
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:2676:12: note: in instantiation of fu
nction template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model::log_prob_impl<true, false, Eigen::Matrix<stan::math::var_value<double>, -1, 1>, Eigen::Matrix<int, -1, 1>, nullptr, nullptr, nullptr>' requested here
2676 | return log_prob_impl<propto__, jacobian__>(params_r, params_i, pstream);
| ^
/Users/a1239028/.cmdstan/cmdstan-2.39.0/stan/src/stan/model/model_base_crtp.hpp:120:50: note: in instantiation of function template specialization 'glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model::log_prob<true, false, stan::math::var_value<double>>' requested here
120 | return
static_cast<const M*>(this)->template log_prob<true, false>(theta,
| ^
/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.hpp:1467:3: note: in instantiation of member function 'stan::model::model_base_crtp<glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model_namespace::glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model>::log_prob_propto' requested here
1467 | ~glm_logistic_normal_multinomial_isometric_single_laplace_approximation_model()
| ^
stan/lib/stan_math/stan/math/mix/prob/laplace_marginal.hpp:32:13: note: candidate template ignored: substitution failure [with propto = false, LFun = ll_function_functor__, LArgs = tuple<const int &, vector<int, allocator<int>> &&, const int &, const Matrix<var_value<double, void>, -1, -1, 0, -1, -1> &, Block<Matrix<var_value<double, void>, -1, -1, 0, -1, -1>, -1, 1, true> &&, const Map<Matrix<double, -1, -1, 0, -1, -1>, 0, Stride<0, 0>> &>, CovarFun = cov_function_functor__, CovarArgs = tuple<const Matrix<var_value<double, void>, -1, -1, 0, -1, -1> &, const int &>, OpsTuple = const std::tuple<Eigen::Matrix<double, -1, 1>, double, int, int, int, int> &]
32 | inline auto laplace_marginal_tol(LFun&& L_f, LArgs&& l_args,
| ^
4 errors generated.
make: *** [/var/folders/11/bb8zxz8j0fx1lv3_s0mbhkr00000gp/T/RtmpmH8MbS/model-5fad2d23e8fa.o] Error 1
Scanning through it, it seems to be a tuple signature mismatch with stan_math function expectations, but I cannot figure out where I did things wrongly.
Also, the documentation for control parameters have a weird chunk of code that reads:
tuple(vector[theta_size], real, int, int, int, int, int) laplace_ops = generate_laplace_options(theta_size);
// Modify solver type
laplace_ops.5 = 2;
// Turn off fallthrough
laplace_ops.7 = 0;
There appears to be one extra int element in the returned tuple that differs from the signature in all other variants in the section.