alpaqa 0.0.1
Nonconvex constrained optimization
decl/structured-panoc-lbfgs.hpp
Go to the documentation of this file.
1#pragma once
2
11
12#include <atomic>
13#include <chrono>
14#include <limits>
15#include <string>
16
17namespace alpaqa {
18
19/// Tuning parameters for the second order PANOC algorithm.
21 /// Parameters related to the Lipschitz constant estimate and step size.
23 /// Maximum number of inner PANOC iterations.
24 unsigned max_iter = 100;
25 /// Maximum duration.
26 std::chrono::microseconds max_time = std::chrono::minutes(5);
27 /// Minimum weight factor between Newton step and projected gradient step.
28 real_t τ_min = 1. / 256;
29 /// Minimum Lipschitz constant estimate.
30 real_t L_min = 1e-5;
31 /// Maximum Lipschitz constant estimate.
32 real_t L_max = 1e20;
33 /// Factor used in update for exponentially weighted nonmonotone line search.
34 /// Zero means monotone line search.
36 /// What stopping criterion to use.
38 /// Maximum number of iterations without any progress before giving up.
39 unsigned max_no_progress = 10;
40
41 /// When to print progress. If set to zero, nothing will be printed.
42 /// If set to N != 0, progress is printed every N iterations.
43 unsigned print_interval = 0;
44
46 10 * std::numeric_limits<real_t>::epsilon();
47
50
51 bool hessian_vec = true;
54
56
58};
59
61 unsigned k;
79};
80
84 std::chrono::microseconds elapsed_time;
85 unsigned iterations = 0;
86 unsigned linesearch_failures = 0;
87 unsigned lbfgs_failures = 0;
88 unsigned lbfgs_rejected = 0;
89 unsigned τ_1_accepted = 0;
90 unsigned count_τ = 0;
92};
93
94/// Second order PANOC solver for ALM.
95/// @ingroup grp_InnerSolvers
97 public:
101
103 : params(params), lbfgs(lbfgsparams) {}
104
105 Stats operator()(const Problem &problem, // in
106 crvec Σ, // in
107 real_t ε, // in
108 bool always_overwrite_results, // in
109 rvec x, // inout
110 rvec y, // inout
111 rvec err_z); // out
112
114 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
115 this->progress_cb = cb;
116 return *this;
117 }
118
119 std::string get_name() const { return "StructuredPANOCLBFGSSolver"; }
120
121 void stop() { stop_signal.stop(); }
122
123 const Params &get_params() const { return params; }
124
125 private:
128 std::function<void(const ProgressInfo &)> progress_cb;
129
130 public:
132};
133
134template <class InnerSolverStats>
136
137template <>
139 /// Total elapsed time in the inner solver.
140 std::chrono::microseconds elapsed_time;
141 /// Total number of inner PANOC iterations.
142 unsigned iterations = 0;
143 /// Total number of PANOC line search failures.
144 unsigned linesearch_failures = 0;
145 /// Total number of times that the L-BFGS direction was not finite.
146 unsigned lbfgs_failures = 0;
147 /// Total number of times that the L-BFGS update was rejected (i.e. it
148 /// could have resulted in a non-positive definite Hessian estimate).
149 unsigned lbfgs_rejected = 0;
150 /// Total number of times that a line search parameter of @f$ \tau = 1 @f$
151 /// was accepted (i.e. no backtracking necessary).
152 unsigned τ_1_accepted = 0;
153 /// The total number of line searches performed (used for computing the
154 /// average value of @f$ \tau @f$).
155 unsigned count_τ = 0;
156 /// The sum of the line search parameter @f$ \tau @f$ in all iterations
157 /// (used for computing the average value of @f$ \tau @f$).
158 real_t sum_τ = 0;
159};
160
163 const StructuredPANOCLBFGSStats &s) {
164 acc.iterations += s.iterations;
165 acc.elapsed_time += s.elapsed_time;
170 acc.count_τ += s.count_τ;
171 acc.sum_τ += s.sum_τ;
172 return acc;
173}
174
175} // namespace alpaqa
Limited memory Broyden–Fletcher–Goldfarb–Shanno (L-BFGS) algorithm.
Definition: decl/lbfgs.hpp:29
Second order PANOC solver for ALM.
std::function< void(const ProgressInfo &)> progress_cb
StructuredPANOCLBFGSSolver(Params params, LBFGSParams lbfgsparams)
StructuredPANOCLBFGSSolver & set_progress_callback(std::function< void(const ProgressInfo &)> cb)
Stats operator()(const Problem &problem, crvec Σ, real_t ε, bool always_overwrite_results, rvec x, rvec y, rvec err_z)
int Σ
Definition: test.py:72
int ε
Definition: test.py:73
LipschitzEstimateParams Lipschitz
Parameters related to the Lipschitz constant estimate and step size.
InnerStatsAccumulator< PolymorphicInnerSolverWrapper::Stats > & operator+=(InnerStatsAccumulator< PolymorphicInnerSolverWrapper::Stats > &acc, const PolymorphicInnerSolverWrapper::Stats &s)
@ ApproxKKT
Find an ε-approximate KKT point in the ∞-norm:
Eigen::Ref< const vec > crvec
Default type for immutable references to vectors.
Definition: vec.hpp:18
constexpr real_t inf
Definition: vec.hpp:26
unsigned max_no_progress
Maximum number of iterations without any progress before giving up.
real_t L_max
Maximum Lipschitz constant estimate.
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
Definition: solverstatus.hpp:7
@ Unknown
Initial value.
std::chrono::microseconds max_time
Maximum duration.
double real_t
Default floating point type.
Definition: vec.hpp:8
unsigned print_interval
When to print progress.
real_t τ_min
Minimum weight factor between Newton step and projected gradient step.
real_t L_min
Minimum Lipschitz constant estimate.
LBFGSStepSize
Which method to use to select the L-BFGS step size.
unsigned max_iter
Maximum number of inner PANOC iterations.
PANOCStopCrit stop_crit
What stopping criterion to use.
Eigen::Ref< vec > rvec
Default type for mutable references to vectors.
Definition: vec.hpp:16
real_t nonmonotone_linesearch
Factor used in update for exponentially weighted nonmonotone line search.
Parameters for the LBFGS and SpecializedLBFGS classes.
Definition: decl/lbfgs.hpp:12
Tuning parameters for the second order PANOC algorithm.
problem
Definition: main.py:16
def cb(it)
Definition: rosenbrock.py:56
Problem description for minimization problems.