alpaqa 1.0.0a14
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 std::chrono::nanoseconds time_progress_callback{};
37 unsigned iterations = 0;
38 real_t final_ψ = 0;
39 unsigned lbfgs_rejected = 0;
40};
41
59
60/// L-BFGS-B solver for ALM.
61/// @ingroup grp_InnerSolvers
63 public:
65
71
72 LBFGSBSolver(const Params &params) : params(params) {}
73
74 Stats operator()(const Problem &problem, // in
75 const SolveOptions &opts, // in
76 rvec x, // inout
77 rvec y, // inout
78 crvec Σ, // in
79 rvec err_z); // out
80
81 template <class P>
82 Stats operator()(const P &problem, const SolveOptions &opts, rvec u, rvec y,
83 crvec Σ, rvec e) {
84 return operator()(Problem{&problem}, opts, u, y, Σ, e);
85 }
86
87 /// Specify a callable that is invoked with some intermediate results on
88 /// each iteration of the algorithm.
89 /// @see @ref ProgressInfo
91 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
92 this->progress_cb = cb;
93 return *this;
94 }
95
96 std::string get_name() const;
97
98 void stop() { stop_signal.stop(); }
99
100 const Params &get_params() const { return params; }
101
102 private:
105 std::function<void(const ProgressInfo &)> progress_cb;
106
107 public:
108 std::ostream *os = &std::cout;
109};
110
111} // namespace alpaqa::lbfgsb
112
113namespace alpaqa {
114
115template <class InnerSolverStats>
117
118template <>
119struct InnerStatsAccumulator<lbfgsb::LBFGSBStats> {
121
122 /// Total elapsed time in the inner solver.
123 std::chrono::nanoseconds elapsed_time{};
124 /// Total time spent in the user-provided progress callback.
125 std::chrono::nanoseconds time_progress_callback{};
126 /// Total number of inner PANOC iterations.
127 unsigned iterations = 0;
128 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
129 real_t final_ψ = 0;
130 /// Total number of times that the L-BFGS update was rejected (i.e. it
131 /// could have resulted in a non-positive definite Hessian estimate).
132 unsigned lbfgs_rejected = 0;
133};
134
137 const lbfgsb::LBFGSBStats &s) {
139 acc.elapsed_time += s.elapsed_time;
140 acc.time_progress_callback += s.time_progress_callback;
141 acc.final_ψ = s.final_ψ;
142 acc.lbfgs_rejected += s.lbfgs_rejected;
143 return acc;
144}
145
146} // namespace alpaqa
The main polymorphic minimization problem interface.
L-BFGS-B solver for ALM.
Stats operator()(const P &problem, const SolveOptions &opts, rvec u, rvec y, crvec Σ, rvec e)
std::function< void(const ProgressInfo &)> progress_cb
LBFGSBSolver & set_progress_callback(std::function< void(const ProgressInfo &)> cb)
Specify a callable that is invoked with some intermediate results on each iteration of the algorithm.
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.
const TypeErasedProblem< config_t > * problem
std::chrono::nanoseconds time_progress_callback
std::chrono::nanoseconds elapsed_time
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
typename Conf::real_t real_t
Definition config.hpp:65
InnerStatsAccumulator< FISTAStats< Conf > > & operator+=(InnerStatsAccumulator< FISTAStats< Conf > > &acc, const FISTAStats< Conf > &s)
Definition fista.hpp:189
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 FISTA iterations.
Definition fista.hpp:176
Double-precision double configuration.
Definition config.hpp:135