Nonconvex constrained optimization
Loading...
Searching...
No Matches
zerofpr.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 <string>
17#include <type_traits>
18
19namespace alpaqa {
20
21/// Tuning parameters for the ZeroFPR algorithm.
22/// @ingroup grp_Parameters
23template <Config Conf = DefaultConfig>
26
27 /// Parameters related to the Lipschitz constant estimate and step size.
29 /// Maximum number of inner ZeroFPR iterations.
30 unsigned max_iter = 100;
31 /// Maximum duration.
32 std::chrono::nanoseconds max_time = std::chrono::minutes(5);
33 /// Minimum weight factor between Newton step and projected gradient step.
35 /// Ignore the line search condition and always accept the accelerated step.
36 /// (For testing purposes only).
37 bool force_linesearch = false;
38 /// Parameter β used in the line search (see Algorithm 2 in
39 /// @cite de_marchi_proximal_2022). @f$ 0 < \beta < 1 @f$
41 /// Minimum Lipschitz constant estimate.
43 /// Maximum Lipschitz constant estimate.
45 /// What stopping criterion to use.
47 /// Maximum number of iterations without any progress before giving up.
48 unsigned max_no_progress = 10;
49
50 /// When to print progress. If set to zero, nothing will be printed.
51 /// If set to N != 0, progress is printed every N iterations.
52 unsigned print_interval = 0;
53 /// The precision of the floating point values printed by the solver.
54 int print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
55
56 /// Tolerance factor used in the quadratic upper bound condition that
57 /// determines the step size. Its goal is to account for numerical errors
58 /// in the function and gradient evaluations. If you notice that the step
59 /// size γ becomes very small, you may want to increase this factor.
61 10 * std::numeric_limits<real_t>::epsilon();
62 /// Tolerance factor used in the line search. Its goal is to account for
63 /// numerical errors in the function and gradient evaluations. If you notice
64 /// that accelerated steps are rejected (τ = 0) when getting closer to the
65 /// solution, you may want to increase this factor.
67 10 * std::numeric_limits<real_t>::epsilon();
68
69 /// Use the candidate point rather than the accepted point to update the
70 /// quasi-Newton direction.
72 /// Use the point generated by the accelerator rather than the accepted
73 /// point to update the quasi-Newton direction.
75 /// If the step size changes, the direction buffer is flushed. The current
76 /// step will still be used to update the direction, but may still use the
77 /// old step size. If set to true, the current step will be recomputed with
78 /// the new step size as well, to match the step in the candidate iterate.
80 /// Update the direction between current forward-backward point and the
81 /// candidate iterate instead of between the current iterate and the
82 /// candidate iterate.
84};
85
86template <Config Conf = DefaultConfig>
108
109template <Config Conf = DefaultConfig>
138
139/// ZeroFPR solver for ALM.
140/// @ingroup grp_InnerSolvers
141template <class DirectionT>
143 public:
144 USING_ALPAQA_CONFIG_TEMPLATE(DirectionT::config_t);
145
148 using Direction = DirectionT;
152
154 requires std::default_initializable<Direction>
155 : params(params) {}
160
161 Stats operator()(const Problem &problem, // in
162 const SolveOptions &opts, // in
163 rvec x, // inout
164 rvec y, // inout
165 crvec Σ, // in
166 rvec err_z); // out
167
168 template <class P>
169 Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y,
170 crvec Σ, rvec e) {
171 return operator()(Problem{&problem}, opts, x, y, Σ, e);
172 }
173
174 template <class P>
175 Stats operator()(const P &problem, const SolveOptions &opts, rvec x) {
176 if (problem.get_num_constraints() != 0)
177 throw std::invalid_argument("Missing arguments y, Σ, e");
178 mvec y{nullptr, 0}, Σ{nullptr, 0}, e{nullptr, 0};
179 return operator()(problem, opts, x, y, Σ, e);
180 }
181
182 /// Specify a callable that is invoked with some intermediate results on
183 /// each iteration of the algorithm.
184 /// @see @ref ProgressInfo
186 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
187 this->progress_cb = cb;
188 return *this;
189 }
190
191 std::string get_name() const;
192
193 void stop() { stop_signal.stop(); }
194
195 const Params &get_params() const { return params; }
196
197 private:
199 guanaqo::AtomicStopSignal stop_signal;
200 std::function<void(const ProgressInfo &)> progress_cb;
202
203 public:
205 std::ostream *os = &std::cout;
206};
207
208template <class InnerSolverStats>
210
211template <Config Conf>
214
215 /// Total elapsed time in the inner solver.
216 std::chrono::nanoseconds elapsed_time{};
217 /// Total time spent in the user-provided progress callback.
218 std::chrono::nanoseconds time_progress_callback{};
219 /// Total number of inner ZeroFPR iterations.
220 unsigned iterations = 0;
221 /// Total number of ZeroFPR line search failures.
223 /// Total number of ZeroFPR line search backtracking steps.
225 /// Total number of ZeroFPR step size reductions.
227 /// Total number of times that the L-BFGS direction was not finite.
228 unsigned direction_failures = 0;
229 /// Total number of times that the L-BFGS update was rejected (i.e. it
230 /// could have resulted in a non-positive definite Hessian estimate).
232 /// Total number of times that a line search parameter of @f$ \tau = 1 @f$
233 /// was accepted (i.e. no backtracking necessary).
234 unsigned τ_1_accepted = 0;
235 /// The total number of line searches performed (used for computing the
236 /// average value of @f$ \tau @f$).
237 unsigned count_τ = 0;
238 /// The sum of the line search parameter @f$ \tau @f$ in all iterations
239 /// (used for computing the average value of @f$ \tau @f$).
241 /// The final ZeroFPR step size γ.
243 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
245 /// Final value of the nonsmooth cost @f$ h(\hat x) @f$.
247 /// Final value of the forward-backward envelope, @f$ \varphi_\gamma(x) @f$
248 /// (note that this is in the point @f$ x @f$, not @f$ \hat x @f$).
250};
251
252template <Config Conf>
255 const ZeroFPRStats<Conf> &s) {
256 acc.iterations += s.iterations;
257 acc.elapsed_time += s.elapsed_time;
258 acc.time_progress_callback += s.time_progress_callback;
259 acc.linesearch_failures += s.linesearch_failures;
260 acc.linesearch_backtracks += s.linesearch_backtracks;
261 acc.stepsize_backtracks += s.stepsize_backtracks;
262 acc.direction_failures += s.direction_failures;
263 acc.direction_update_rejected += s.direction_update_rejected;
264 acc.τ_1_accepted += s.τ_1_accepted;
265 acc.count_τ += s.count_τ;
266 acc.sum_τ += s.sum_τ;
267 acc.final_γ = s.final_γ;
268 acc.final_ψ = s.final_ψ;
269 acc.final_h = s.final_h;
270 acc.final_φγ = s.final_φγ;
271 return acc;
272}
273
274// clang-format off
275ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRParams, EigenConfigd);
276ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRParams, EigenConfigf);)
277ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRParams, EigenConfigl);)
278ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRParams, EigenConfigq);)
279
280ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRStats, EigenConfigd);
281ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRStats, EigenConfigf);)
282ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRStats, EigenConfigl);)
283ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRStats, EigenConfigq);)
284
285ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRProgressInfo, EigenConfigd);
286ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRProgressInfo, EigenConfigf);)
287ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRProgressInfo, EigenConfigl);)
288ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRProgressInfo, EigenConfigq);)
289// clang-format on
290
291} // namespace alpaqa
The main polymorphic minimization problem interface.
ZeroFPR solver for ALM.
Definition zerofpr.hpp:142
std::string get_name() const
Definition zerofpr.tpp:20
ZeroFPRProgressInfo< config_t > ProgressInfo
Definition zerofpr.hpp:150
ZeroFPRSolver(const Params &params, const Direction &direction)
Definition zerofpr.hpp:158
ZeroFPRSolver(const Params &params)
Definition zerofpr.hpp:153
Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec e)
Definition zerofpr.hpp:169
ZeroFPRSolver & 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 zerofpr.hpp:186
std::function< void(const ProgressInfo &)> progress_cb
Definition zerofpr.hpp:200
Stats operator()(const Problem &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec err_z)
Definition zerofpr.tpp:25
ZeroFPRParams< config_t > Params
Definition zerofpr.hpp:147
InnerSolveOptions< config_t > SolveOptions
Definition zerofpr.hpp:151
ZeroFPRStats< config_t > Stats
Definition zerofpr.hpp:149
const Params & get_params() const
Definition zerofpr.hpp:195
guanaqo::AtomicStopSignal stop_signal
Definition zerofpr.hpp:199
detail::PANOCHelpers< config_t > Helpers
Definition zerofpr.hpp:201
ZeroFPRSolver(const Params &params, Direction &&direction)
Definition zerofpr.hpp:156
Stats operator()(const P &problem, const SolveOptions &opts, rvec x)
Definition zerofpr.hpp:175
TypeErasedProblem< config_t > Problem
Definition zerofpr.hpp:146
std::ostream * os
Definition zerofpr.hpp:205
#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 zerofpr.hpp:28
std::chrono::nanoseconds max_time
Definition zerofpr.hpp:32
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 ZeroFPR algorithm.
Definition zerofpr.hpp:24
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 zerofpr.hpp:93
std::chrono::nanoseconds elapsed_time
Definition zerofpr.hpp:92
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
ZeroFPRProgressInfo & operator=(const ZeroFPRProgressInfo &)=delete
const TypeErasedProblem< config_t > * problem
Definition zerofpr.hpp:133
const ZeroFPRParams< config_t > * params
Definition zerofpr.hpp:134