11 return "LBFGSBSolver";
29 using std::chrono::nanoseconds;
30 auto start_time = std::chrono::steady_clock::now();
31 auto os = opts.os ? opts.os : this->os;
32 auto max_time = nanoseconds::max();
34 max_time = std::min(max_time, *opts.max_time);
37 const auto n = problem.get_n();
38 const auto m = problem.get_m();
39 const auto &C = problem.get_box_C();
41 vec work_n(n), work_m(m);
44 struct BreakException {
48 ::LBFGSpp::LBFGSBParam<real_t> effective_params = params;
49 effective_params.epsilon = opts.tolerance;
50 effective_params.epsilon_rel = 0;
51 ::LBFGSpp::LBFGSBSolver<real_t> solver{effective_params};
54 auto eval_f_grad_f = [&](
crvec xk,
rvec grad) {
56 if (stop_signal.stop_requested()) {
61 auto time_elapsed = std::chrono::steady_clock::now() - start_time;
62 bool out_of_time = time_elapsed > max_time;
64 if (opts.always_overwrite_results)
67 s.
final_ψ = problem.eval_ψ(xk, y, Σ, work_m);
71 const auto ψx = problem.eval_ψ_grad_ψ(xk, y, Σ, grad, work_n, work_m);
73 if (!std::isfinite(ψx)) {
74 if (opts.always_overwrite_results)
85 C.lowerbound, C.upperbound);
87 if (
static_cast<int>(s.
iterations) == effective_params.max_iterations)
89 }
catch (
const BreakException &e) {
91 }
catch (
const std::exception &e) {
93 *os <<
"[LBFGSB] Exception: " << e.what() << std::endl;
95 auto time_elapsed = std::chrono::steady_clock::now() - start_time;
96 s.
elapsed_time = duration_cast<nanoseconds>(time_elapsed);
99 s.
ε = solver.final_grad_norm();
103 opts.always_overwrite_results) {
105 s.
final_ψ = problem.eval_ψ(x_solve, y, Σ, ŷ);
106 if (err_z.size() > 0)
107 err_z = Σ.asDiagonal().inverse() * (ŷ - y);
std::string get_name() const
Stats operator()(const Problem &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec err_z)
std::chrono::nanoseconds elapsed_time
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
@ Interrupted
Solver was interrupted by the user.
@ MaxTime
Maximum allowed execution time exceeded.
@ Exception
An unexpected exception was thrown.
@ MaxIter
Maximum number of iterations exceeded.
@ Converged
Converged and reached given tolerance.
@ NotFinite
Intermediate results were infinite or not-a-number.
typename Conf::crvec crvec