alpaqa dll
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>
9#include <guanaqo/atomic-stop-signal.hpp>
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
18struct LBFGSB_ADAPTER_EXPORT LBFGSBParams {
20
21 unsigned memory = 10;
22 unsigned max_iter = 1000;
23 std::chrono::nanoseconds max_time = std::chrono::minutes(5);
25 int print = -1;
26 unsigned print_interval = 0;
27 int print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
28};
29
30struct LBFGSB_ADAPTER_EXPORT LBFGSBStats {
32
35 std::chrono::nanoseconds elapsed_time{};
36 std::chrono::nanoseconds time_progress_callback{};
37 unsigned iterations = 0;
40};
41
59
60/// L-BFGS-B solver for ALM.
61/// @ingroup grp_InnerSolvers
62class LBFGSB_ADAPTER_EXPORT LBFGSBSolver {
63 public:
65
71
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:
104 guanaqo::AtomicStopSignal stop_signal;
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$.
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).
133};
134
137 const lbfgsb::LBFGSBStats &s) {
138 acc.iterations += s.iterations;
139 acc.elapsed_time += s.elapsed_time;
140 acc.time_progress_callback += s.time_progress_callback;
141 acc.final_ψ = s.final_ψ;
142 acc.direction_update_rejected += s.direction_update_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
Stats operator()(const Problem &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec err_z)
InnerSolveOptions< config_t > SolveOptions
LBFGSBProgressInfo ProgressInfo
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
guanaqo::AtomicStopSignal stop_signal
TypeErasedProblem< config_t > Problem
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:77
std::chrono::nanoseconds max_time
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
unsigned direction_update_rejected
Total number of times that the L-BFGS update was rejected (i.e.
@ ProjGradUnitNorm
∞-norm of the projected gradient with unit step size:
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
std::chrono::nanoseconds time_progress_callback
Total time spent in the user-provided progress callback.
std::chrono::nanoseconds elapsed_time
Total elapsed time in the inner solver.
typename Conf::real_t real_t
Definition config.hpp:86
real_t final_ψ
Final value of the smooth cost .
InnerStatsAccumulator< FISTAStats< Conf > > & operator+=(InnerStatsAccumulator< FISTAStats< Conf > > &acc, const FISTAStats< Conf > &s)
Definition fista.hpp:189
constexpr const auto inf
Definition config.hpp:112
typename Conf::rvec rvec
Definition config.hpp:91
typename Conf::crvec crvec
Definition config.hpp:92
unsigned iterations
Total number of inner PANOC iterations.
Double-precision double configuration.
Definition config.hpp:176