alpaqa 1.0.0a9
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>
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.
22template <Config Conf = DefaultConfig>
25
26 /// Parameters related to the Lipschitz constant estimate and step size.
28 /// Maximum number of inner ZeroFPR iterations.
29 unsigned max_iter = 100;
30 /// Maximum duration.
31 std::chrono::nanoseconds max_time = std::chrono::minutes(5);
32 /// Minimum weight factor between Newton step and projected gradient step.
34 /// Ignore the line search condition and always accept the accelerated step.
35 /// (For testing purposes only).
36 bool force_linesearch = false;
37 /// Parameter β used in the line search (see Algorithm 2 in
38 /// @cite de_marchi_proximal_2022). @f$ 0 < \beta < 1 @f$
40 /// Minimum Lipschitz constant estimate.
42 /// Maximum Lipschitz constant estimate.
44 /// What stopping criterion to use.
46 /// Maximum number of iterations without any progress before giving up.
47 unsigned max_no_progress = 10;
48
49 /// When to print progress. If set to zero, nothing will be printed.
50 /// If set to N != 0, progress is printed every N iterations.
51 unsigned print_interval = 0;
52 /// The precision of the floating point values printed by the solver.
53 int print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
54
56 10 * std::numeric_limits<real_t>::epsilon();
58 10 * std::numeric_limits<real_t>::epsilon();
59
63};
64
65template <Config Conf = DefaultConfig>
68
70 real_t ε = inf<config_t>;
71 std::chrono::nanoseconds elapsed_time{};
72 std::chrono::nanoseconds time_progress_callback{};
73 unsigned iterations = 0;
74 unsigned linesearch_failures = 0;
76 unsigned stepsize_backtracks = 0;
77 unsigned lbfgs_failures = 0;
78 unsigned lbfgs_rejected = 0;
79 unsigned τ_1_accepted = 0;
80 unsigned count_τ = 0;
86};
87
88template <Config Conf = DefaultConfig>
91
92 unsigned k;
110 unsigned outer_iter;
113};
114
115/// ZeroFPR solver for ALM.
116/// @ingroup grp_InnerSolvers
117template <class DirectionT>
119 public:
120 USING_ALPAQA_CONFIG_TEMPLATE(DirectionT::config_t);
121
124 using Direction = DirectionT;
128
130 requires std::default_initializable<Direction>
131 : params(params) {}
133 : params(params), direction(std::move(direction)) {}
136
137 Stats operator()(const Problem &problem, // in
138 const SolveOptions &opts, // in
139 rvec x, // inout
140 rvec y, // inout
141 crvec Σ, // in
142 rvec err_z); // out
143
144 template <class P>
145 Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y,
146 crvec Σ, rvec e) {
147 return operator()(Problem::template make<P>(problem), opts, x, y, Σ, e);
148 }
149
150 template <class P>
151 Stats operator()(const P &problem, const SolveOptions &opts, rvec x) {
152 if (problem.get_m() != 0)
153 throw std::invalid_argument("Missing arguments y, Σ, e");
154 mvec y{nullptr, 0}, Σ{nullptr, 0}, e{nullptr, 0};
155 return operator()(problem, opts, x, y, Σ, e);
156 }
157
158 /// Specify a callable that is invoked with some intermediate results on
159 /// each iteration of the algorithm.
160 /// @see @ref ProgressInfo
162 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
163 this->progress_cb = cb;
164 return *this;
165 }
166
167 std::string get_name() const;
168
169 void stop() { stop_signal.stop(); }
170
171 const Params &get_params() const { return params; }
172
173 private:
176 std::function<void(const ProgressInfo &)> progress_cb;
178
179 public:
181 std::ostream *os = &std::cout;
182};
183
184template <class InnerSolverStats>
186
187template <Config Conf>
190
191 /// Total elapsed time in the inner solver.
192 std::chrono::nanoseconds elapsed_time{};
193 /// Total time spent in the user-provided progress callback.
194 std::chrono::nanoseconds time_progress_callback{};
195 /// Total number of inner ZeroFPR iterations.
196 unsigned iterations = 0;
197 /// Total number of ZeroFPR line search failures.
198 unsigned linesearch_failures = 0;
199 /// Total number of ZeroFPR line search backtracking steps.
200 unsigned linesearch_backtracks = 0;
201 /// Total number of ZeroFPR step size reductions.
202 unsigned stepsize_backtracks = 0;
203 /// Total number of times that the L-BFGS direction was not finite.
204 unsigned lbfgs_failures = 0;
205 /// Total number of times that the L-BFGS update was rejected (i.e. it
206 /// could have resulted in a non-positive definite Hessian estimate).
207 unsigned lbfgs_rejected = 0;
208 /// Total number of times that a line search parameter of @f$ \tau = 1 @f$
209 /// was accepted (i.e. no backtracking necessary).
210 unsigned τ_1_accepted = 0;
211 /// The total number of line searches performed (used for computing the
212 /// average value of @f$ \tau @f$).
213 unsigned count_τ = 0;
214 /// The sum of the line search parameter @f$ \tau @f$ in all iterations
215 /// (used for computing the average value of @f$ \tau @f$).
216 real_t sum_τ = 0;
217 /// The final ZeroFPR step size γ.
218 real_t final_γ = 0;
219 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
220 real_t final_ψ = 0;
221 /// Final value of the nonsmooth cost @f$ h(\hat x) @f$.
222 real_t final_h = 0;
223 /// Final value of the forward-backward envelope, @f$ \varphi_\gamma(x) @f$
224 /// (note that this is in the point @f$ x @f$, not @f$ \hat x @f$).
225 real_t final_φγ = 0;
226};
227
228template <Config Conf>
231 const ZeroFPRStats<Conf> &s) {
232 acc.iterations += s.iterations;
233 acc.elapsed_time += s.elapsed_time;
234 acc.time_progress_callback += s.time_progress_callback;
235 acc.linesearch_failures += s.linesearch_failures;
236 acc.linesearch_backtracks += s.linesearch_backtracks;
237 acc.stepsize_backtracks += s.stepsize_backtracks;
238 acc.lbfgs_failures += s.lbfgs_failures;
239 acc.lbfgs_rejected += s.lbfgs_rejected;
240 acc.τ_1_accepted += s.τ_1_accepted;
241 acc.count_τ += s.count_τ;
242 acc.sum_τ += s.sum_τ;
243 acc.final_γ = s.final_γ;
244 acc.final_ψ = s.final_ψ;
245 acc.final_h = s.final_h;
246 acc.final_φγ = s.final_φγ;
247 return acc;
248}
249
250// clang-format off
251ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRParams, EigenConfigd);
252ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRParams, EigenConfigf);)
253ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRParams, EigenConfigl);)
254ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRParams, EigenConfigq);)
255
256ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRStats, EigenConfigd);
257ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRStats, EigenConfigf);)
258ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRStats, EigenConfigl);)
259ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRStats, EigenConfigq);)
260
261ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRProgressInfo, EigenConfigd);
262ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRProgressInfo, EigenConfigf);)
263ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRProgressInfo, EigenConfigl);)
264ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRProgressInfo, EigenConfigq);)
265// clang-format on
266
267} // namespace alpaqa
The main polymorphic minimization problem interface.
ZeroFPR solver for ALM.
Definition: zerofpr.hpp:118
std::string get_name() const
Definition: zerofpr.tpp:20
ZeroFPRSolver(const Params &params, const Direction &direction)
Definition: zerofpr.hpp:134
ZeroFPRSolver(const Params &params)
Definition: zerofpr.hpp:129
Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec e)
Definition: zerofpr.hpp:145
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:162
std::function< void(const ProgressInfo &)> progress_cb
Definition: zerofpr.hpp:176
Stats operator()(const Problem &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec err_z)
Definition: zerofpr.tpp:25
InnerSolveOptions< config_t > SolveOptions
Definition: zerofpr.hpp:127
ZeroFPRStats< config_t > Stats
Definition: zerofpr.hpp:125
AtomicStopSignal stop_signal
Definition: zerofpr.hpp:175
DirectionT Direction
Definition: zerofpr.hpp:124
const Params & get_params() const
Definition: zerofpr.hpp:171
ZeroFPRSolver(const Params &params, Direction &&direction)
Definition: zerofpr.hpp:132
Stats operator()(const P &problem, const SolveOptions &opts, rvec x)
Definition: zerofpr.hpp:151
TypeErasedProblem< config_t > Problem
Definition: zerofpr.hpp:122
std::ostream * os
Definition: zerofpr.hpp:181
#define USING_ALPAQA_CONFIG(Conf)
Definition: config.hpp:54
#define ALPAQA_IF_QUADF(...)
Definition: config.hpp:171
#define ALPAQA_IF_LONGD(...)
Definition: config.hpp:183
#define ALPAQA_IF_FLOAT(...)
Definition: config.hpp:177
#define USING_ALPAQA_CONFIG_TEMPLATE(Conf)
Definition: config.hpp:58
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition: export.hpp:21
unsigned stepsize_backtracks
Definition: zerofpr.hpp:76
unsigned lbfgs_rejected
Definition: zerofpr.hpp:78
typename Conf::mvec mvec
Definition: config.hpp:65
@ ApproxKKT
Find an ε-approximate KKT point in the ∞-norm:
real_t linesearch_tolerance_factor
Definition: zerofpr.hpp:57
LipschitzEstimateParams< config_t > Lipschitz
Parameters related to the Lipschitz constant estimate and step size.
Definition: zerofpr.hpp:27
unsigned τ_1_accepted
Definition: zerofpr.hpp:79
unsigned lbfgs_failures
Definition: zerofpr.hpp:77
const TypeErasedProblem< config_t > * problem
Definition: zerofpr.hpp:111
InnerStatsAccumulator< PANOCOCPStats< Conf > > & operator+=(InnerStatsAccumulator< PANOCOCPStats< Conf > > &acc, const PANOCOCPStats< Conf > &s)
Definition: panoc-ocp.hpp:255
unsigned max_no_progress
Maximum number of iterations without any progress before giving up.
Definition: zerofpr.hpp:47
real_t L_max
Maximum Lipschitz constant estimate.
Definition: zerofpr.hpp:43
bool update_direction_from_prox_step
Definition: zerofpr.hpp:62
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
@ Busy
In progress.
std::chrono::nanoseconds time_progress_callback
Definition: zerofpr.hpp:72
bool recompute_last_prox_step_after_lbfgs_flush
Definition: zerofpr.hpp:61
std::chrono::nanoseconds elapsed_time
Definition: zerofpr.hpp:71
typename Conf::real_t real_t
Definition: config.hpp:63
unsigned linesearch_backtracks
Definition: zerofpr.hpp:75
real_t min_linesearch_coefficient
Minimum weight factor between Newton step and projected gradient step.
Definition: zerofpr.hpp:33
std::chrono::nanoseconds max_time
Maximum duration.
Definition: zerofpr.hpp:31
real_t quadratic_upperbound_tolerance_factor
Definition: zerofpr.hpp:55
bool force_linesearch
Ignore the line search condition and always accept the accelerated step.
Definition: zerofpr.hpp:36
real_t linesearch_strictness_factor
Parameter β used in the line search (see Algorithm 2 in ).
Definition: zerofpr.hpp:39
typename Conf::rvec rvec
Definition: config.hpp:67
typename Conf::crvec crvec
Definition: config.hpp:68
unsigned linesearch_failures
Definition: zerofpr.hpp:74
unsigned print_interval
When to print progress.
Definition: zerofpr.hpp:51
int print_precision
The precision of the floating point values printed by the solver.
Definition: zerofpr.hpp:53
real_t L_min
Minimum Lipschitz constant estimate.
Definition: zerofpr.hpp:41
bool update_direction_in_candidate
Definition: zerofpr.hpp:60
unsigned iterations
Definition: zerofpr.hpp:73
const ZeroFPRParams< config_t > * params
Definition: zerofpr.hpp:112
SolverStatus status
Definition: zerofpr.hpp:69
unsigned max_iter
Maximum number of inner ZeroFPR iterations.
Definition: zerofpr.hpp:29
PANOCStopCrit stop_crit
What stopping criterion to use.
Definition: zerofpr.hpp:45
Tuning parameters for the ZeroFPR algorithm.
Definition: zerofpr.hpp:23