1 #ifndef STAN_SERVICES_OPTIMIZE_DO_BFGS_OPTIMIZE_HPP
2 #define STAN_SERVICES_OPTIMIZE_DO_BFGS_OPTIMIZE_HPP
19 template<
typename Model,
typename BFGSOptimizer,
typename RNGT,
20 typename StartIterationCallback>
24 std::vector<double> &cont_vector,
25 std::vector<int> &disc_vector,
30 StartIterationCallback& interrupt) {
33 std::stringstream msg;
34 msg <<
"initial log joint probability = " << lp;
37 if (save_iterations) {
39 lp, cont_vector, disc_vector,
60 bfgs.params_r(cont_vector);
63 ret != 0 || !bfgs.note().empty(), refresh)) {
65 msg <<
" " << std::setw(7) << bfgs.iter_num() <<
" ";
66 msg <<
" " << std::setw(12) << std::setprecision(6)
68 msg <<
" " << std::setw(12) << std::setprecision(6)
69 << bfgs.prev_step_size() <<
" ";
70 msg <<
" " << std::setw(12) << std::setprecision(6)
71 << bfgs.curr_g().norm() <<
" ";
72 msg <<
" " << std::setw(10) << std::setprecision(4)
73 << bfgs.alpha() <<
" ";
74 msg <<
" " << std::setw(10) << std::setprecision(4)
75 << bfgs.alpha0() <<
" ";
76 msg <<
" " << std::setw(7)
77 << bfgs.grad_evals() <<
" ";
78 msg <<
" " << bfgs.note() <<
" ";
82 if (save_iterations) {
84 lp, cont_vector, disc_vector,
91 info(
"Optimization terminated normally: ");
94 info(
"Optimization terminated with error: ");
97 info(
" " + bfgs.get_code_string(ret));
Probability, optimization and sampling library.
void write_iteration(Model &model, RNG &base_rng, double lp, std::vector< double > &cont_vector, std::vector< int > &disc_vector, interface_callbacks::writer::base_writer &message_writer, interface_callbacks::writer::base_writer ¶meter_writer)
bool do_print(const int n, const bool special, const int refresh)
Indicates whether it should print on the current iteration.
base_writer is an abstract base class defining the interface for Stan writer callbacks.
int do_bfgs_optimize(Model &model, BFGSOptimizer &bfgs, RNGT &base_rng, double &lp, std::vector< double > &cont_vector, std::vector< int > &disc_vector, interface_callbacks::writer::base_writer &output, interface_callbacks::writer::base_writer &info, bool save_iterations, int refresh, StartIterationCallback &interrupt)