alpaqa matlab
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.
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 /// If the step size changes, the direction buffer is flushed. The current
73 /// step will still be used to update the direction, but may still use the
74 /// old step size. If set to true, the current step will be recomputed with
75 /// the new step size as well, to match the step in the candidate iterate.
77 /// Update the direction between current forward-backward point and the
78 /// candidate iterate instead of between the current iterate and the
79 /// candidate iterate.
81};
82
83template <Config Conf = DefaultConfig>
86
89 std::chrono::nanoseconds elapsed_time{};
90 std::chrono::nanoseconds time_progress_callback{};
91 unsigned iterations = 0;
92 unsigned linesearch_failures = 0;
94 unsigned stepsize_backtracks = 0;
95 unsigned lbfgs_failures = 0;
96 unsigned lbfgs_rejected = 0;
97 unsigned τ_1_accepted = 0;
98 unsigned count_τ = 0;
104};
105
106template <Config Conf = DefaultConfig>
133
134/// ZeroFPR solver for ALM.
135/// @ingroup grp_InnerSolvers
136template <class DirectionT>
138 public:
139 USING_ALPAQA_CONFIG_TEMPLATE(DirectionT::config_t);
140
147
149 requires std::default_initializable<Direction>
150 : params(params) {}
155
156 Stats operator()(const Problem &problem, // in
157 const SolveOptions &opts, // in
158 rvec x, // inout
159 rvec y, // inout
160 crvec Σ, // in
161 rvec err_z); // out
162
163 template <class P>
164 Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y,
165 crvec Σ, rvec e) {
166 return operator()(Problem{&problem}, opts, x, y, Σ, e);
167 }
168
169 template <class P>
170 Stats operator()(const P &problem, const SolveOptions &opts, rvec x) {
171 if (problem.get_m() != 0)
172 throw std::invalid_argument("Missing arguments y, Σ, e");
173 mvec y{nullptr, 0}, Σ{nullptr, 0}, e{nullptr, 0};
174 return operator()(problem, opts, x, y, Σ, e);
175 }
176
177 /// Specify a callable that is invoked with some intermediate results on
178 /// each iteration of the algorithm.
179 /// @see @ref ProgressInfo
181 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
182 this->progress_cb = cb;
183 return *this;
184 }
185
186 std::string get_name() const;
187
188 void stop() { stop_signal.stop(); }
189
190 const Params &get_params() const { return params; }
191
192 private:
195 std::function<void(const ProgressInfo &)> progress_cb;
197
198 public:
200 std::ostream *os = &std::cout;
201};
202
203template <class InnerSolverStats>
205
206template <Config Conf>
209
210 /// Total elapsed time in the inner solver.
211 std::chrono::nanoseconds elapsed_time{};
212 /// Total time spent in the user-provided progress callback.
213 std::chrono::nanoseconds time_progress_callback{};
214 /// Total number of inner ZeroFPR iterations.
215 unsigned iterations = 0;
216 /// Total number of ZeroFPR line search failures.
217 unsigned linesearch_failures = 0;
218 /// Total number of ZeroFPR line search backtracking steps.
219 unsigned linesearch_backtracks = 0;
220 /// Total number of ZeroFPR step size reductions.
221 unsigned stepsize_backtracks = 0;
222 /// Total number of times that the L-BFGS direction was not finite.
223 unsigned lbfgs_failures = 0;
224 /// Total number of times that the L-BFGS update was rejected (i.e. it
225 /// could have resulted in a non-positive definite Hessian estimate).
226 unsigned lbfgs_rejected = 0;
227 /// Total number of times that a line search parameter of @f$ \tau = 1 @f$
228 /// was accepted (i.e. no backtracking necessary).
229 unsigned τ_1_accepted = 0;
230 /// The total number of line searches performed (used for computing the
231 /// average value of @f$ \tau @f$).
232 unsigned count_τ = 0;
233 /// The sum of the line search parameter @f$ \tau @f$ in all iterations
234 /// (used for computing the average value of @f$ \tau @f$).
235 real_t sum_τ = 0;
236 /// The final ZeroFPR step size γ.
237 real_t final_γ = 0;
238 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
239 real_t final_ψ = 0;
240 /// Final value of the nonsmooth cost @f$ h(\hat x) @f$.
241 real_t final_h = 0;
242 /// Final value of the forward-backward envelope, @f$ \varphi_\gamma(x) @f$
243 /// (note that this is in the point @f$ x @f$, not @f$ \hat x @f$).
244 real_t final_φγ = 0;
245};
246
247template <Config Conf>
250 const ZeroFPRStats<Conf> &s) {
252 acc.elapsed_time += s.elapsed_time;
253 acc.time_progress_callback += s.time_progress_callback;
254 acc.linesearch_failures += s.linesearch_failures;
255 acc.linesearch_backtracks += s.linesearch_backtracks;
256 acc.stepsize_backtracks += s.stepsize_backtracks;
257 acc.lbfgs_failures += s.lbfgs_failures;
258 acc.lbfgs_rejected += s.lbfgs_rejected;
259 acc.τ_1_accepted += s.τ_1_accepted;
260 acc.count_τ += s.count_τ;
261 acc.sum_τ += s.sum_τ;
262 acc.final_γ = s.final_γ;
263 acc.final_ψ = s.final_ψ;
264 acc.final_h = s.final_h;
265 acc.final_φγ = s.final_φγ;
266 return acc;
267}
268
269// clang-format off
270ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRParams, EigenConfigd);
271ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRParams, EigenConfigf);)
272ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRParams, EigenConfigl);)
274
275ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRStats, EigenConfigd);
276ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRStats, EigenConfigf);)
277ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRStats, EigenConfigl);)
279
280ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRProgressInfo, EigenConfigd);
281ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRProgressInfo, EigenConfigf);)
282ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRProgressInfo, EigenConfigl);)
283ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, ZeroFPRProgressInfo, EigenConfigq);)
284// clang-format on
285
286} // namespace alpaqa
The main polymorphic minimization problem interface.
ZeroFPR solver for ALM.
Definition zerofpr.hpp:137
std::string get_name() const
Definition zerofpr.tpp:20
ZeroFPRSolver(const Params &params, const Direction &direction)
Definition zerofpr.hpp:153
ZeroFPRSolver(const Params &params)
Definition zerofpr.hpp:148
Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec e)
Definition zerofpr.hpp:164
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:181
std::function< void(const ProgressInfo &)> progress_cb
Definition zerofpr.hpp:195
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:146
ZeroFPRStats< config_t > Stats
Definition zerofpr.hpp:144
AtomicStopSignal stop_signal
Definition zerofpr.hpp:194
const Params & get_params() const
Definition zerofpr.hpp:190
ZeroFPRSolver(const Params &params, Direction &&direction)
Definition zerofpr.hpp:151
Stats operator()(const P &problem, const SolveOptions &opts, rvec x)
Definition zerofpr.hpp:170
TypeErasedProblem< config_t > Problem
Definition zerofpr.hpp:141
std::ostream * os
Definition zerofpr.hpp:200
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:56
#define ALPAQA_IF_QUADF(...)
Definition config.hpp:182
#define ALPAQA_IF_LONGD(...)
Definition config.hpp:194
#define ALPAQA_IF_FLOAT(...)
Definition config.hpp:188
#define USING_ALPAQA_CONFIG_TEMPLATE(Conf)
Definition config.hpp:60
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition export.hpp:21
real_t linesearch_tolerance_factor
Tolerance factor used in the line search.
Definition zerofpr.hpp:66
LipschitzEstimateParams< config_t > Lipschitz
Parameters related to the Lipschitz constant estimate and step size.
Definition zerofpr.hpp:28
unsigned max_no_progress
Maximum number of iterations without any progress before giving up.
Definition zerofpr.hpp:48
real_t L_max
Maximum Lipschitz constant estimate.
Definition zerofpr.hpp:44
bool update_direction_from_prox_step
Update the direction between current forward-backward point and the candidate iterate instead of betw...
Definition zerofpr.hpp:80
bool recompute_last_prox_step_after_stepsize_change
If the step size changes, the direction buffer is flushed.
Definition zerofpr.hpp:76
real_t min_linesearch_coefficient
Minimum weight factor between Newton step and projected gradient step.
Definition zerofpr.hpp:34
std::chrono::nanoseconds max_time
Maximum duration.
Definition zerofpr.hpp:32
real_t quadratic_upperbound_tolerance_factor
Tolerance factor used in the quadratic upper bound condition that determines the step size.
Definition zerofpr.hpp:60
bool force_linesearch
Ignore the line search condition and always accept the accelerated step.
Definition zerofpr.hpp:37
real_t linesearch_strictness_factor
Parameter β used in the line search (see Algorithm 2 in ).
Definition zerofpr.hpp:40
unsigned print_interval
When to print progress.
Definition zerofpr.hpp:52
int print_precision
The precision of the floating point values printed by the solver.
Definition zerofpr.hpp:54
real_t L_min
Minimum Lipschitz constant estimate.
Definition zerofpr.hpp:42
bool update_direction_in_candidate
Use the candidate point rather than the accepted point to update the quasi-Newton direction.
Definition zerofpr.hpp:71
unsigned max_iter
Maximum number of inner ZeroFPR iterations.
Definition zerofpr.hpp:30
PANOCStopCrit stop_crit
What stopping criterion to use.
Definition zerofpr.hpp:46
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
unsigned stepsize_backtracks
Definition zerofpr.hpp:94
unsigned lbfgs_rejected
Definition zerofpr.hpp:96
typename Conf::mvec mvec
Definition config.hpp:67
@ ApproxKKT
Find an ε-approximate KKT point in the ∞-norm:
unsigned τ_1_accepted
Definition zerofpr.hpp:97
unsigned lbfgs_failures
Definition zerofpr.hpp:95
const TypeErasedProblem< config_t > * problem
Definition zerofpr.hpp:130
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
@ Busy
In progress.
std::chrono::nanoseconds time_progress_callback
Definition zerofpr.hpp:90
std::chrono::nanoseconds elapsed_time
Definition zerofpr.hpp:89
typename Conf::real_t real_t
Definition config.hpp:65
unsigned linesearch_backtracks
Definition zerofpr.hpp:93
InnerStatsAccumulator< FISTAStats< Conf > > & operator+=(InnerStatsAccumulator< FISTAStats< Conf > > &acc, const FISTAStats< Conf > &s)
Definition fista.hpp:189
constexpr const auto inf
Definition config.hpp:85
typename Conf::rvec rvec
Definition config.hpp:69
typename Conf::crvec crvec
Definition config.hpp:70
unsigned linesearch_failures
Definition zerofpr.hpp:92
const ZeroFPRParams< config_t > * params
Definition zerofpr.hpp:131
SolverStatus status
Definition zerofpr.hpp:87