alpaqa sparse
Nonconvex constrained optimization
Loading...
Searching...
No Matches
lbfgsb-adapter.hpp
Go to the documentation of this file.
1#pragma once
2
7#include <alpaqa/lbfgsb-adapter-export.h>
10
11#include <chrono>
12#include <iostream>
13
14namespace alpaqa::lbfgsb {
15
18
19 unsigned memory = 10;
20 unsigned max_iter = 1000;
21 std::chrono::nanoseconds max_time = std::chrono::minutes(5);
22 PANOCStopCrit stop_crit = PANOCStopCrit::ProjGradUnitNorm;
23 int print = -1;
24 unsigned print_interval = 0;
25 int print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
26};
27
30
31 SolverStatus status = SolverStatus::Busy;
32 real_t ε = inf<config_t>;
33 std::chrono::nanoseconds elapsed_time{};
34 unsigned iterations = 0;
35 real_t final_ψ = 0;
36 unsigned lbfgs_rejected = 0;
37};
38
39/// L-BFGS-B solver for ALM.
40/// @ingroup grp_InnerSolvers
42 public:
44
49
50 LBFGSBSolver(const Params &params) : params(params) {}
51
52 Stats operator()(const Problem &problem, // in
53 const SolveOptions &opts, // in
54 rvec x, // inout
55 rvec y, // inout
56 crvec Σ, // in
57 rvec err_z); // out
58
59 template <class P>
60 Stats operator()(const P &problem, const SolveOptions &opts, rvec u, rvec y,
61 crvec Σ, rvec e) {
62 return operator()(Problem::template make<P>(problem), opts, u, y, Σ, e);
63 }
64
65 std::string get_name() const;
66
67 void stop() { stop_signal.stop(); }
68
69 const Params &get_params() const { return params; }
70
71 private:
74
75 public:
76 std::ostream *os = &std::cout;
77};
78
79} // namespace alpaqa::lbfgsb
80
81namespace alpaqa {
82
83template <class InnerSolverStats>
85
86template <>
87struct InnerStatsAccumulator<lbfgsb::LBFGSBStats> {
89
90 /// Total elapsed time in the inner solver.
91 std::chrono::nanoseconds elapsed_time{};
92 /// Total number of inner PANOC iterations.
93 unsigned iterations = 0;
94 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
95 real_t final_ψ = 0;
96 /// Total number of times that the L-BFGS update was rejected (i.e. it
97 /// could have resulted in a non-positive definite Hessian estimate).
98 unsigned lbfgs_rejected = 0;
99};
100
103 const lbfgsb::LBFGSBStats &s) {
105 acc.elapsed_time += s.elapsed_time;
106 acc.final_ψ = s.final_ψ;
107 acc.lbfgs_rejected += s.lbfgs_rejected;
108 return acc;
109}
110
111} // namespace alpaqa
L-BFGS-B solver for ALM.
Stats operator()(const P &problem, const SolveOptions &opts, rvec u, rvec y, crvec Σ, rvec e)
LBFGSBSolver(const Params &params)
const Params & get_params() const
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:56
std::chrono::nanoseconds elapsed_time
InnerStatsAccumulator< PANOCOCPStats< Conf > > & operator+=(InnerStatsAccumulator< PANOCOCPStats< Conf > > &acc, const PANOCOCPStats< Conf > &s)
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
typename Conf::real_t real_t
Definition config.hpp:65
constexpr const auto inf
Definition config.hpp:85
typename Conf::rvec rvec
Definition config.hpp:69
typename Conf::crvec crvec
Definition config.hpp:70
unsigned iterations
Total number of inner PANOC iterations.
Double-precision double configuration.
Definition config.hpp:135