alpaqa 1.0.0a17
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>
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 upperbound 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>
147
148/// PANTR solver for ALM.
149/// @ingroup grp_InnerSolvers
150template <class DirectionT>
152 public:
153 USING_ALPAQA_CONFIG_TEMPLATE(DirectionT::config_t);
154
161
163 requires std::default_initializable<Direction>
164 : params(params) {}
169
170 Stats operator()(const Problem &problem, // in
171 const SolveOptions &opts, // in
172 rvec x, // inout
173 rvec y, // inout
174 crvec Σ, // in
175 rvec err_z); // out
176
177 template <class P>
178 Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y,
179 crvec Σ, rvec e) {
180 return operator()(Problem{&problem}, opts, x, y, Σ, e);
181 }
182
183 template <class P>
184 Stats operator()(const P &problem, const SolveOptions &opts, rvec x) {
185 if (problem.get_m() != 0)
186 throw std::invalid_argument("Missing arguments y, Σ, e");
187 mvec y{nullptr, 0}, Σ{nullptr, 0}, e{nullptr, 0};
188 return operator()(problem, opts, x, y, Σ, e);
189 }
190
191 /// Specify a callable that is invoked with some intermediate results on
192 /// each iteration of the algorithm.
193 /// @see @ref ProgressInfo
195 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
196 this->progress_cb = cb;
197 return *this;
198 }
199
200 std::string get_name() const;
201
202 void stop() { stop_signal.stop(); }
203
204 const Params &get_params() const { return params; }
205
206 private:
209 std::function<void(const ProgressInfo &)> progress_cb;
211
212 public:
214 std::ostream *os = &std::cout;
215};
216
217template <class InnerSolverStats>
219
220template <Config Conf>
223
224 /// Total elapsed time in the inner solver.
225 std::chrono::nanoseconds elapsed_time{};
226 /// Total time spent in the user-provided progress callback.
227 std::chrono::nanoseconds time_progress_callback{};
228 /// Total number of inner PANTR iterations.
229 unsigned iterations = 0;
230 /// Total number of PANTR rejected accelerated steps.
231 unsigned accelerated_step_rejected = 0;
232 /// Total number of FB step size reductions.
233 unsigned stepsize_backtracks = 0;
234 /// Total number of times that the accelerated direction was not finite.
235 unsigned direction_failures = 0;
236 /// Total number of times that the direction update was rejected (e.g. it
237 /// could have resulted in a non-positive definite Hessian estimate).
238 unsigned direction_update_rejected = 0;
239 /// The final FB step size γ.
240 real_t final_γ = 0;
241 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
242 real_t final_ψ = 0;
243 /// Final value of the nonsmooth cost @f$ h(\hat x) @f$.
244 real_t final_h = 0;
245 /// Final value of the forward-backward envelope, @f$ \varphi_\gamma(x) @f$
246 /// (note that this is in the point @f$ x @f$, not @f$ \hat x @f$).
247 real_t final_φγ = 0;
248};
249
250template <Config Conf>
253 const PANTRStats<Conf> &s) {
255 acc.time_progress_callback += s.time_progress_callback;
256 acc.iterations += s.iterations;
257 acc.accelerated_step_rejected += s.accelerated_step_rejected;
258 acc.stepsize_backtracks += s.stepsize_backtracks;
259 acc.direction_failures += s.direction_failures;
260 acc.direction_update_rejected += s.direction_update_rejected;
261 acc.final_γ = s.final_γ;
262 acc.final_ψ = s.final_ψ;
263 acc.final_h = s.final_h;
264 acc.final_φγ = s.final_φγ;
265 return acc;
266}
267
268// clang-format off
269ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigd);
270ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigf);)
271ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigl);)
273
274ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigd);
275ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigf);)
276ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigl);)
278
279ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigd);
280ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigf);)
281ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigl);)
283// clang-format on
284
285} // namespace alpaqa
PANTR solver for ALM.
Definition pantr.hpp:151
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:178
std::function< void(const ProgressInfo &)> progress_cb
Definition pantr.hpp:209
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:165
Direction direction
Definition pantr.hpp:213
InnerSolveOptions< config_t > SolveOptions
Definition pantr.hpp:160
PANTRSolver(const Params &params, const Direction &direction)
Definition pantr.hpp:167
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:195
AtomicStopSignal stop_signal
Definition pantr.hpp:208
DirectionT Direction
Definition pantr.hpp:157
const Params & get_params() const
Definition pantr.hpp:204
PANTRStats< config_t > Stats
Definition pantr.hpp:158
PANTRSolver(const Params &params)
Definition pantr.hpp:162
Stats operator()(const P &problem, const SolveOptions &opts, rvec x)
Definition pantr.hpp:184
TypeErasedProblem< config_t > Problem
Definition pantr.hpp:155
std::ostream * os
Definition pantr.hpp:214
The main polymorphic minimization problem interface.
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:77
#define ALPAQA_IF_QUADF(...)
Definition config.hpp:221
#define ALPAQA_IF_LONGD(...)
Definition config.hpp:233
#define ALPAQA_IF_FLOAT(...)
Definition config.hpp:227
#define USING_ALPAQA_CONFIG_TEMPLATE(Conf)
Definition config.hpp:81
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition export.hpp:21
LipschitzEstimateParams< config_t > Lipschitz
Parameters related to the Lipschitz constant estimate and step size.
Definition pantr.hpp:27
real_t TR_tolerance_factor
Definition pantr.hpp:53
real_t ratio_threshold_good
Minimal TR ratio to increase radius (very successful).
Definition pantr.hpp:58
bool disable_acceleration
Don't compute accelerated steps, fall back to forward-backward splitting.
Definition pantr.hpp:81
unsigned max_no_progress
Maximum number of iterations without any progress before giving up.
Definition pantr.hpp:39
real_t L_max
Maximum Lipschitz constant estimate.
Definition pantr.hpp:35
bool recompute_last_prox_step_after_direction_reset
Definition pantr.hpp:77
bool update_direction_on_prox_step
Definition pantr.hpp:76
real_t initial_radius
Initial trust radius.
Definition pantr.hpp:68
std::chrono::nanoseconds max_time
Maximum duration.
Definition pantr.hpp:31
bool ratio_approx_fbe_quadratic_model
Compute the trust-region ratio using an approximation of the quadratic model of the FBE,...
Definition pantr.hpp:95
real_t quadratic_upperbound_tolerance_factor
Tolerance factor used in the quadratic upper bound condition that determines the step size.
Definition pantr.hpp:51
real_t radius_factor_rejected
TR radius decrease coefficient when unsuccessful.
Definition pantr.hpp:61
unsigned print_interval
When to print progress.
Definition pantr.hpp:43
real_t ratio_threshold_acceptable
Minimal TR ratio to be accepted (successful).
Definition pantr.hpp:56
int print_precision
The precision of the floating point values printed by the solver.
Definition pantr.hpp:45
real_t min_radius
Minimum trust radius.
Definition pantr.hpp:70
real_t L_min
Minimum Lipschitz constant estimate.
Definition pantr.hpp:33
real_t radius_factor_good
TR radius increase coefficient when very successful.
Definition pantr.hpp:65
bool compute_ratio_using_new_stepsize
Check the quadratic upperbound and update γ before computing the reduction of the TR step.
Definition pantr.hpp:74
real_t radius_factor_acceptable
TR radius decrease coefficient when successful.
Definition pantr.hpp:63
unsigned max_iter
Maximum number of inner PANTR iterations.
Definition pantr.hpp:29
PANOCStopCrit stop_crit
What stopping criterion to use.
Definition pantr.hpp:37
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
unsigned stepsize_backtracks
Definition pantr.hpp:108
unsigned direction_update_rejected
Definition pantr.hpp:110
typename Conf::mvec mvec
Definition config.hpp:89
@ ApproxKKT
Find an ε-approximate KKT point in the ∞-norm:
unsigned accelerated_step_rejected
Definition pantr.hpp:107
const TypeErasedProblem< config_t > * problem
Definition pantr.hpp:144
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
@ Busy
In progress.
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
unsigned direction_failures
Definition pantr.hpp:109
InnerStatsAccumulator< FISTAStats< Conf > > & operator+=(InnerStatsAccumulator< FISTAStats< Conf > > &acc, const FISTAStats< Conf > &s)
Definition fista.hpp:189
constexpr const auto inf
Definition config.hpp:112
typename Conf::rvec rvec
Definition config.hpp:91
const PANTRParams< config_t > * params
Definition pantr.hpp:145
typename Conf::crvec crvec
Definition config.hpp:92
real_t τ
1 if previous step accepted, 0 otherwise (PANOC compatibility)
Definition pantr.hpp:139
unsigned iterations
Definition pantr.hpp:106
SolverStatus status
Definition pantr.hpp:102