Nonconvex constrained optimization
Loading...
Searching...
No Matches
panoc.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <alpaqa/export.hpp>
11#include <guanaqo/atomic-stop-signal.hpp>
12
13#include <chrono>
14#include <iostream>
15#include <limits>
16#include <stdexcept>
17#include <string>
18#include <type_traits>
19
20namespace alpaqa {
21
22/// Tuning parameters for the PANOC algorithm.
23/// @ingroup grp_Parameters
24template <Config Conf = DefaultConfig>
27
28 /// Parameters related to the Lipschitz constant estimate and step size.
30 /// Maximum number of inner PANOC iterations.
31 unsigned max_iter = 100;
32 /// Maximum duration.
33 std::chrono::nanoseconds max_time = std::chrono::minutes(5);
34 /// Minimum weight factor between Newton step and projected gradient step.
36 /// Factor to decrease the line search factor by after a line search
37 /// failure.
39 /// Ignore the line search condition and always accept the accelerated step.
40 /// (For testing purposes only).
41 bool force_linesearch = false;
42 /// Parameter β used in the line search (see Algorithm 2 in
43 /// @cite de_marchi_proximal_2022). @f$ 0 < \beta < 1 @f$
45 /// Minimum Lipschitz constant estimate.
47 /// Maximum Lipschitz constant estimate.
49 /// What stopping criterion to use.
51 /// Maximum number of iterations without any progress before giving up.
52 unsigned max_no_progress = 10;
53
54 /// When to print progress. If set to zero, nothing will be printed.
55 /// If set to N != 0, progress is printed every N iterations.
56 unsigned print_interval = 0;
57 /// The precision of the floating point values printed by the solver.
58 int print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
59
60 /// Tolerance factor used in the quadratic upper bound condition that
61 /// determines the step size. Its goal is to account for numerical errors
62 /// in the function and gradient evaluations. If you notice that the step
63 /// size γ becomes very small, you may want to increase this factor.
65 10 * std::numeric_limits<real_t>::epsilon();
66 /// Tolerance factor used in the line search. Its goal is to account for
67 /// numerical errors in the function and gradient evaluations. If you notice
68 /// that accelerated steps are rejected (τ = 0) when getting closer to the
69 /// solution, you may want to increase this factor.
71 10 * std::numeric_limits<real_t>::epsilon();
72
73 /// Use the candidate point rather than the accepted point to update the
74 /// quasi-Newton direction.
76 /// If the step size changes, the direction buffer is flushed. The current
77 /// step will still be used to update the direction, but may still use the
78 /// old step size. If set to true, the current step will be recomputed with
79 /// the new step size as well, to match the step in the candidate iterate.
81 /// When evaluating ψ(x̂) in a candidate point, always evaluate ∇ψ(x̂) as
82 /// well. Can be beneficial if computing ∇ψ(x̂) is not much more expensive
83 /// than computing just ψ(x), and if ∇ψ(x̂) is required in the next iteration
84 /// (e.g. for the stopping criterion, or when using the NoopDirection).
85 bool eager_gradient_eval = false;
86};
87
88template <Config Conf = DefaultConfig>
110
111template <Config Conf = DefaultConfig>
140
141/// PANOC solver for ALM.
142/// @ingroup grp_InnerSolvers
143template <class DirectionT>
145 public:
146 USING_ALPAQA_CONFIG_TEMPLATE(DirectionT::config_t);
147
150 using Direction = DirectionT;
154
156 requires std::default_initializable<Direction>
157 : params(params) {}
162
163 Stats operator()(const Problem &problem, // in
164 const SolveOptions &opts, // in
165 rvec x, // inout
166 rvec y, // inout
167 crvec Σ, // in
168 rvec err_z); // out
169
170 template <class P>
171 Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y,
172 crvec Σ, rvec e) {
173 return operator()(Problem{&problem}, opts, x, y, Σ, e);
174 }
175
176 template <class P>
177 Stats operator()(const P &problem, const SolveOptions &opts, rvec x) {
178 if (problem.get_num_constraints() != 0)
179 throw std::invalid_argument("Missing arguments y, Σ, e");
180 mvec y{nullptr, 0}, Σ{nullptr, 0}, e{nullptr, 0};
181 return operator()(problem, opts, x, y, Σ, e);
182 }
183
184 /// Specify a callable that is invoked with some intermediate results on
185 /// each iteration of the algorithm.
186 /// @see @ref ProgressInfo
188 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
189 this->progress_cb = cb;
190 return *this;
191 }
192
193 std::string get_name() const;
194
195 void stop() { stop_signal.stop(); }
196
197 const Params &get_params() const { return params; }
198
199 private:
201 guanaqo::AtomicStopSignal stop_signal;
202 std::function<void(const ProgressInfo &)> progress_cb;
204
205 public:
207 std::ostream *os = &std::cout;
208};
209
210template <class InnerSolverStats>
212
213template <Config Conf>
216
217 /// Total elapsed time in the inner solver.
218 std::chrono::nanoseconds elapsed_time{};
219 /// Total time spent in the user-provided progress callback.
220 std::chrono::nanoseconds time_progress_callback{};
221 /// Total number of inner PANOC iterations.
222 unsigned iterations = 0;
223 /// Total number of PANOC line search failures.
225 /// Total number of PANOC line search backtracking steps.
227 /// Total number of PANOC step size reductions.
229 /// Total number of times that the L-BFGS direction was not finite.
230 unsigned direction_failures = 0;
231 /// Total number of times that the L-BFGS update was rejected (i.e. it
232 /// could have resulted in a non-positive definite Hessian estimate).
234 /// Total number of times that a line search parameter of @f$ \tau = 1 @f$
235 /// was accepted (i.e. no backtracking necessary).
236 unsigned τ_1_accepted = 0;
237 /// The total number of line searches performed (used for computing the
238 /// average value of @f$ \tau @f$).
239 unsigned count_τ = 0;
240 /// The sum of the line search parameter @f$ \tau @f$ in all iterations
241 /// (used for computing the average value of @f$ \tau @f$).
243 /// The final PANOC step size γ.
245 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
247 /// Final value of the nonsmooth cost @f$ h(\hat x) @f$.
249 /// Final value of the forward-backward envelope, @f$ \varphi_\gamma(x) @f$
250 /// (note that this is in the point @f$ x @f$, not @f$ \hat x @f$).
252};
253
254template <Config Conf>
257 const PANOCStats<Conf> &s) {
258 acc.iterations += s.iterations;
259 acc.elapsed_time += s.elapsed_time;
260 acc.time_progress_callback += s.time_progress_callback;
261 acc.linesearch_failures += s.linesearch_failures;
262 acc.linesearch_backtracks += s.linesearch_backtracks;
263 acc.stepsize_backtracks += s.stepsize_backtracks;
264 acc.direction_failures += s.direction_failures;
265 acc.direction_update_rejected += s.direction_update_rejected;
266 acc.τ_1_accepted += s.τ_1_accepted;
267 acc.count_τ += s.count_τ;
268 acc.sum_τ += s.sum_τ;
269 acc.final_γ = s.final_γ;
270 acc.final_ψ = s.final_ψ;
271 acc.final_h = s.final_h;
272 acc.final_φγ = s.final_φγ;
273 return acc;
274}
275
276// clang-format off
277ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCParams, EigenConfigd);
278ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCParams, EigenConfigf);)
279ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCParams, EigenConfigl);)
280ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCParams, EigenConfigq);)
281
282ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCStats, EigenConfigd);
283ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCStats, EigenConfigf);)
284ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCStats, EigenConfigl);)
285ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCStats, EigenConfigq);)
286
287ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCProgressInfo, EigenConfigd);
288ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCProgressInfo, EigenConfigf);)
289ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCProgressInfo, EigenConfigl);)
290ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANOCProgressInfo, EigenConfigq);)
291// clang-format on
292
293} // namespace alpaqa
PANOC solver for ALM.
Definition panoc.hpp:144
std::string get_name() const
Definition panoc.tpp:20
PANOCSolver(const Params &params, Direction &&direction)
Definition panoc.hpp:158
PANOCSolver(const Params &params)
Definition panoc.hpp:155
Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec e)
Definition panoc.hpp:171
PANOCStats< config_t > Stats
Definition panoc.hpp:151
std::function< void(const ProgressInfo &)> progress_cb
Definition panoc.hpp:202
Stats operator()(const Problem &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec err_z)
Definition panoc.tpp:25
PANOCSolver & 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.
Definition panoc.hpp:188
Direction direction
Definition panoc.hpp:206
InnerSolveOptions< config_t > SolveOptions
Definition panoc.hpp:153
PANOCSolver(const Params &params, const Direction &direction)
Definition panoc.hpp:160
DirectionT Direction
Definition panoc.hpp:150
const Params & get_params() const
Definition panoc.hpp:197
guanaqo::AtomicStopSignal stop_signal
Definition panoc.hpp:201
PANOCProgressInfo< config_t > ProgressInfo
Definition panoc.hpp:152
detail::PANOCHelpers< config_t > Helpers
Definition panoc.hpp:203
Stats operator()(const P &problem, const SolveOptions &opts, rvec x)
Definition panoc.hpp:177
PANOCParams< config_t > Params
Definition panoc.hpp:149
TypeErasedProblem< config_t > Problem
Definition panoc.hpp:148
std::ostream * os
Definition panoc.hpp:207
The main polymorphic minimization problem interface.
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:77
#define ALPAQA_IF_QUADF(...)
Definition config.hpp:223
#define ALPAQA_IF_LONGD(...)
Definition config.hpp:235
#define ALPAQA_IF_FLOAT(...)
Definition config.hpp:229
#define USING_ALPAQA_CONFIG_TEMPLATE(Conf)
Definition config.hpp:81
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition export.hpp:23
LipschitzEstimateParams< config_t > Lipschitz
Definition panoc.hpp:29
bool recompute_last_prox_step_after_stepsize_change
Definition panoc.hpp:80
real_t linesearch_coefficient_update_factor
Definition panoc.hpp:38
std::chrono::nanoseconds max_time
Definition panoc.hpp:33
real_t quadratic_upperbound_tolerance_factor
Definition panoc.hpp:64
Parameters for the estimation of the Lipschitz constant of the gradient of the smooth term of the cos...
Definition lipschitz.hpp:12
Tuning parameters for the PANOC algorithm.
Definition panoc.hpp:25
typename Conf::mvec mvec
Definition config.hpp:89
@ ApproxKKT
Find an ε-approximate KKT point in the ∞-norm:
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
std::chrono::nanoseconds time_progress_callback
Definition panoc.hpp:95
std::chrono::nanoseconds elapsed_time
Definition panoc.hpp:94
typename Conf::real_t real_t
Definition config.hpp:86
InnerStatsAccumulator< FISTAStats< Conf > > & operator+=(InnerStatsAccumulator< FISTAStats< Conf > > &acc, const FISTAStats< Conf > &s)
Definition fista.hpp:191
constexpr const auto inf
Definition config.hpp:112
typename Conf::rvec rvec
Definition config.hpp:91
typename Conf::crvec crvec
Definition config.hpp:92
const TypeErasedProblem< config_t > * problem
Definition panoc.hpp:135
const PANOCParams< config_t > * params
Definition panoc.hpp:136
PANOCProgressInfo & operator=(const PANOCProgressInfo &)=delete