Nonconvex constrained optimization
Loading...
Searching...
No Matches
pantr.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <alpaqa/export.hpp>
10#include <guanaqo/atomic-stop-signal.hpp>
11
12#include <chrono>
13#include <iostream>
14#include <limits>
15#include <string>
16#include <type_traits>
17
18namespace alpaqa {
19
20/// Tuning parameters for the PANTR algorithm.
21/// @ingroup grp_Parameters
22template <Config Conf = DefaultConfig>
25
26 /// Parameters related to the Lipschitz constant estimate and step size.
28 /// Maximum number of inner PANTR iterations.
29 unsigned max_iter = 100;
30 /// Maximum duration.
31 std::chrono::nanoseconds max_time = std::chrono::minutes(5);
32 /// Minimum Lipschitz constant estimate.
34 /// Maximum Lipschitz constant estimate.
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 /// The precision of the floating point values printed by the solver.
45 int print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
46
47 /// Tolerance factor used in the quadratic upper bound condition that
48 /// determines the step size. Its goal is to account for numerical errors
49 /// in the function and gradient evaluations. If you notice that the step
50 /// size γ becomes very small, you may want to increase this factor.
52 10 * std::numeric_limits<real_t>::epsilon();
53 real_t TR_tolerance_factor = 10 * std::numeric_limits<real_t>::epsilon();
54
55 /// Minimal TR ratio to be accepted (successful).
57 /// Minimal TR ratio to increase radius (very successful).
59
60 /// TR radius decrease coefficient when unsuccessful.
62 /// TR radius decrease coefficient when successful.
64 /// TR radius increase coefficient when very successful.
66
67 /// Initial trust radius.
69 /// Minimum trust radius.
70 real_t min_radius = 100 * std::numeric_limits<real_t>::epsilon();
71
72 /// Check the quadratic upper bound and update γ before computing the
73 /// reduction of the TR step.
75
78
79 /// Don't compute accelerated steps, fall back to forward-backward splitting.
80 /// For testing purposes.
82 /// Compute the trust-region ratio using an approximation of the quadratic
83 /// model of the FBE, rather than the quadratic model of the subproblem.
84 /// Specifically, when set to false, the quadratic model used is
85 /// @f[ q(d) = \tfrac12 \inprod{\mathcal R_\gamma(\hat x) d}{d} +
86 /// \inprod{R_\gamma(\hat x)}{d}. @f]
87 /// When set to true, the quadratic model used is
88 /// @f[ q_\mathrm{approx}(d) = \inv{(1-\alpha)} q(d), @f]
89 /// where @f$ \alpha = @f$ @ref LipschitzEstimateParams::Lγ_factor.
90 /// This is an approximation of the quadratic model of the FBE,
91 /// @f[ q_{\varphi_\gamma}(d) = \tfrac12 \inprod{\mathcal Q_\gamma(\hat x)
92 /// \mathcal R_\gamma(\hat x) d}{d} + \inprod{\mathcal Q_\gamma(\hat x)
93 /// R_\gamma(\hat x)}{d}, @f]
94 /// with @f$ \mathcal Q_\gamma(x) = \Id - \gamma \nabla^2 \psi(x) @f$.
96};
97
98template <Config Conf = DefaultConfig>
116
117template <Config Conf = DefaultConfig>
149
150/// PANTR solver for ALM.
151/// @ingroup grp_InnerSolvers
152template <class DirectionT>
154 public:
155 USING_ALPAQA_CONFIG_TEMPLATE(DirectionT::config_t);
156
159 using Direction = DirectionT;
163
165 requires std::default_initializable<Direction>
166 : params(params) {}
171
172 Stats operator()(const Problem &problem, // in
173 const SolveOptions &opts, // in
174 rvec x, // inout
175 rvec y, // inout
176 crvec Σ, // in
177 rvec err_z); // out
178
179 template <class P>
180 Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y,
181 crvec Σ, rvec e) {
182 return operator()(Problem{&problem}, opts, x, y, Σ, e);
183 }
184
185 template <class P>
186 Stats operator()(const P &problem, const SolveOptions &opts, rvec x) {
187 if (problem.get_num_constraints() != 0)
188 throw std::invalid_argument("Missing arguments y, Σ, e");
189 mvec y{nullptr, 0}, Σ{nullptr, 0}, e{nullptr, 0};
190 return operator()(problem, opts, x, y, Σ, e);
191 }
192
193 /// Specify a callable that is invoked with some intermediate results on
194 /// each iteration of the algorithm.
195 /// @see @ref ProgressInfo
197 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
198 this->progress_cb = cb;
199 return *this;
200 }
201
202 std::string get_name() const;
203
204 void stop() { stop_signal.stop(); }
205
206 const Params &get_params() const { return params; }
207
208 private:
210 guanaqo::AtomicStopSignal stop_signal;
211 std::function<void(const ProgressInfo &)> progress_cb;
213
214 public:
216 std::ostream *os = &std::cout;
217};
218
219template <class InnerSolverStats>
221
222template <Config Conf>
225
226 /// Total elapsed time in the inner solver.
227 std::chrono::nanoseconds elapsed_time{};
228 /// Total time spent in the user-provided progress callback.
229 std::chrono::nanoseconds time_progress_callback{};
230 /// Total number of inner PANTR iterations.
231 unsigned iterations = 0;
232 /// Total number of PANTR rejected accelerated steps.
234 /// Total number of FB step size reductions.
236 /// Total number of times that the accelerated direction was not finite.
237 unsigned direction_failures = 0;
238 /// Total number of times that the direction update was rejected (e.g. it
239 /// could have resulted in a non-positive definite Hessian estimate).
241 /// The final FB 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 PANTRStats<Conf> &s) {
256 acc.elapsed_time += s.elapsed_time;
257 acc.time_progress_callback += s.time_progress_callback;
258 acc.iterations += s.iterations;
259 acc.accelerated_step_rejected += s.accelerated_step_rejected;
260 acc.stepsize_backtracks += s.stepsize_backtracks;
261 acc.direction_failures += s.direction_failures;
262 acc.direction_update_rejected += s.direction_update_rejected;
263 acc.final_γ = s.final_γ;
264 acc.final_ψ = s.final_ψ;
265 acc.final_h = s.final_h;
266 acc.final_φγ = s.final_φγ;
267 return acc;
268}
269
270// clang-format off
271ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigd);
272ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigf);)
273ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigl);)
274ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigq);)
275
276ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigd);
277ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigf);)
278ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigl);)
279ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigq);)
280
281ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigd);
282ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigf);)
283ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigl);)
284ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigq);)
285// clang-format on
286
287} // namespace alpaqa
PANTR solver for ALM.
Definition pantr.hpp:153
std::string get_name() const
Definition pantr.tpp:20
Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec e)
Definition pantr.hpp:180
std::function< void(const ProgressInfo &)> progress_cb
Definition pantr.hpp:211
Stats operator()(const Problem &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec err_z)
Definition pantr.tpp:25
PANTRSolver(const Params &params, Direction &&direction)
Definition pantr.hpp:167
PANTRParams< config_t > Params
Definition pantr.hpp:158
Direction direction
Definition pantr.hpp:215
InnerSolveOptions< config_t > SolveOptions
Definition pantr.hpp:162
PANTRProgressInfo< config_t > ProgressInfo
Definition pantr.hpp:161
PANTRSolver(const Params &params, const Direction &direction)
Definition pantr.hpp:169
PANTRSolver & 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 pantr.hpp:197
DirectionT Direction
Definition pantr.hpp:159
const Params & get_params() const
Definition pantr.hpp:206
PANTRStats< config_t > Stats
Definition pantr.hpp:160
guanaqo::AtomicStopSignal stop_signal
Definition pantr.hpp:210
PANTRSolver(const Params &params)
Definition pantr.hpp:164
detail::PANOCHelpers< config_t > Helpers
Definition pantr.hpp:212
Stats operator()(const P &problem, const SolveOptions &opts, rvec x)
Definition pantr.hpp:186
TypeErasedProblem< config_t > Problem
Definition pantr.hpp:157
std::ostream * os
Definition pantr.hpp:216
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 pantr.hpp:27
bool recompute_last_prox_step_after_direction_reset
Definition pantr.hpp:77
std::chrono::nanoseconds max_time
Definition pantr.hpp:31
real_t quadratic_upperbound_tolerance_factor
Definition pantr.hpp:51
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 PANTR algorithm.
Definition pantr.hpp:23
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 pantr.hpp:105
std::chrono::nanoseconds elapsed_time
Definition pantr.hpp:104
typename Conf::real_t real_t
Definition config.hpp:86
constexpr const auto NaN
Definition config.hpp:114
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 pantr.hpp:144
const PANTRParams< config_t > * params
Definition pantr.hpp:145
PANTRProgressInfo & operator=(const PANTRProgressInfo &)=delete