alpaqa 1.0.0a13
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
16/// Tuning parameters for the L-BFGS-B solver @ref LBFGSBSolver.
17/// @ingroup grp_Parameters
20
21 unsigned memory = 10;
22 unsigned max_iter = 1000;
23 std::chrono::nanoseconds max_time = std::chrono::minutes(5);
24 PANOCStopCrit stop_crit = PANOCStopCrit::ProjGradUnitNorm;
25 int print = -1;
26 unsigned print_interval = 0;
27 int print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
28};
29
32
33 SolverStatus status = SolverStatus::Busy;
34 real_t ε = inf<config_t>;
35 std::chrono::nanoseconds elapsed_time{};
36 unsigned iterations = 0;
37 real_t final_ψ = 0;
38 unsigned lbfgs_rejected = 0;
39};
40
41/// L-BFGS-B solver for ALM.
42/// @ingroup grp_InnerSolvers
44 public:
46
51
52 LBFGSBSolver(const Params &params) : params(params) {}
53
54 Stats operator()(const Problem &problem, // in
55 const SolveOptions &opts, // in
56 rvec x, // inout
57 rvec y, // inout
58 crvec Σ, // in
59 rvec err_z); // out
60
61 template <class P>
62 Stats operator()(const P &problem, const SolveOptions &opts, rvec u, rvec y,
63 crvec Σ, rvec e) {
64 return operator()(Problem{&problem}, opts, u, y, Σ, e);
65 }
66
67 std::string get_name() const;
68
69 void stop() { stop_signal.stop(); }
70
71 const Params &get_params() const { return params; }
72
73 private:
76
77 public:
78 std::ostream *os = &std::cout;
79};
80
81} // namespace alpaqa::lbfgsb
82
83namespace alpaqa {
84
85template <class InnerSolverStats>
87
88template <>
89struct InnerStatsAccumulator<lbfgsb::LBFGSBStats> {
91
92 /// Total elapsed time in the inner solver.
93 std::chrono::nanoseconds elapsed_time{};
94 /// Total number of inner PANOC iterations.
95 unsigned iterations = 0;
96 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
97 real_t final_ψ = 0;
98 /// Total number of times that the L-BFGS update was rejected (i.e. it
99 /// could have resulted in a non-positive definite Hessian estimate).
100 unsigned lbfgs_rejected = 0;
101};
102
105 const lbfgsb::LBFGSBStats &s) {
107 acc.elapsed_time += s.elapsed_time;
108 acc.final_ψ = s.final_ψ;
109 acc.lbfgs_rejected += s.lbfgs_rejected;
110 return acc;
111}
112
113} // 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
Tuning parameters for the L-BFGS-B solver LBFGSBSolver.
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