alpaqa 1.0.0a12
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.
21template <Config Conf = DefaultConfig>
24
25 /// Parameters related to the Lipschitz constant estimate and step size.
27 /// Maximum number of inner PANTR iterations.
28 unsigned max_iter = 100;
29 /// Maximum duration.
30 std::chrono::nanoseconds max_time = std::chrono::minutes(5);
31 /// Minimum Lipschitz constant estimate.
33 /// Maximum Lipschitz constant estimate.
35 /// What stopping criterion to use.
37 /// Maximum number of iterations without any progress before giving up.
38 unsigned max_no_progress = 10;
39
40 /// When to print progress. If set to zero, nothing will be printed.
41 /// If set to N != 0, progress is printed every N iterations.
42 unsigned print_interval = 0;
43 /// The precision of the floating point values printed by the solver.
44 int print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
45
47 10 * std::numeric_limits<real_t>::epsilon();
48 real_t TR_tolerance_factor = 10 * std::numeric_limits<real_t>::epsilon();
49
50 /// Minimal TR ratio to be accepted (successful).
52 /// Minimal TR ratio to increase radius (very successful).
54
55 /// TR radius decrease coefficient when unsuccessful.
57 /// TR radius decrease coefficient when successful.
59 /// TR radius increase coefficient when very successful.
61
62 /// Initial trust radius.
64 /// Minimum trust radius.
65 real_t min_radius = 100 * std::numeric_limits<real_t>::epsilon();
66
67 /// Check the quadratic upperbound and update γ before computing the
68 /// reduction of the TR step.
70
73
74 /// Don't compute accelerated steps, fall back to forward-backward splitting.
75 /// For testing purposes.
77 /// Compute the trust-region ratio using an approximation of the quadratic
78 /// model of the FBE, rather than the quadratic model of the subproblem.
79 /// Specifically, when set to false, the quadratic model used is
80 /// @f[ q(d) = \tfrac12 \inprod{\mathcal R_\gamma(\hat x) d}{d} +
81 /// \inprod{R_\gamma(\hat x)}{d}. @f]
82 /// When set to true, the quadratic model used is
83 /// @f[ q_\mathrm{approx}(d) = \inv{(1-\alpha)} q(d), @f]
84 /// where @f$ \alpha = @f$ @ref LipschitzEstimateParams::Lγ_factor.
85 /// This is an approximation of the quadratic model of the FBE,
86 /// @f[ q_{\varphi_\gamma}(d) = \tfrac12 \inprod{\mathcal Q_\gamma(\hat x)
87 /// \mathcal R_\gamma(\hat x) d}{d} + \inprod{\mathcal Q_\gamma(\hat x)
88 /// R_\gamma(\hat x)}{d}, @f]
89 /// with @f$ \mathcal Q_\gamma(x) = \Id - \gamma \nabla^2 \psi(x) @f$.
91};
92
93template <Config Conf = DefaultConfig>
111
112template <Config Conf = DefaultConfig>
139
140/// PANTR solver for ALM.
141/// @ingroup grp_InnerSolvers
142template <class DirectionT>
144 public:
145 USING_ALPAQA_CONFIG_TEMPLATE(DirectionT::config_t);
146
153
155 requires std::default_initializable<Direction>
156 : params(params) {}
161
162 Stats operator()(const Problem &problem, // in
163 const SolveOptions &opts, // in
164 rvec x, // inout
165 rvec y, // inout
166 crvec Σ, // in
167 rvec err_z); // out
168
169 template <class P>
170 Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y,
171 crvec Σ, rvec e) {
172 return operator()(Problem::template make<P>(problem), opts, x, y, Σ, e);
173 }
174
175 template <class P>
176 Stats operator()(const P &problem, const SolveOptions &opts, rvec x) {
177 if (problem.get_m() != 0)
178 throw std::invalid_argument("Missing arguments y, Σ, e");
179 mvec y{nullptr, 0}, Σ{nullptr, 0}, e{nullptr, 0};
180 return operator()(problem, opts, x, y, Σ, e);
181 }
182
183 /// Specify a callable that is invoked with some intermediate results on
184 /// each iteration of the algorithm.
185 /// @see @ref ProgressInfo
187 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
188 this->progress_cb = cb;
189 return *this;
190 }
191
192 std::string get_name() const;
193
194 void stop() { stop_signal.stop(); }
195
196 const Params &get_params() const { return params; }
197
198 private:
201 std::function<void(const ProgressInfo &)> progress_cb;
203
204 public:
206 std::ostream *os = &std::cout;
207};
208
209template <class InnerSolverStats>
211
212template <Config Conf>
215
216 /// Total elapsed time in the inner solver.
217 std::chrono::nanoseconds elapsed_time{};
218 /// Total time spent in the user-provided progress callback.
219 std::chrono::nanoseconds time_progress_callback{};
220 /// Total number of inner PANTR iterations.
221 unsigned iterations = 0;
222 /// Total number of PANTR rejected accelerated steps.
223 unsigned accelerated_step_rejected = 0;
224 /// Total number of FB step size reductions.
225 unsigned stepsize_backtracks = 0;
226 /// Total number of times that the accelerated direction was not finite.
227 unsigned direction_failures = 0;
228 /// Total number of times that the direction update was rejected (e.g. it
229 /// could have resulted in a non-positive definite Hessian estimate).
230 unsigned direction_update_rejected = 0;
231 /// The final FB step size γ.
232 real_t final_γ = 0;
233 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
234 real_t final_ψ = 0;
235 /// Final value of the nonsmooth cost @f$ h(\hat x) @f$.
236 real_t final_h = 0;
237 /// Final value of the forward-backward envelope, @f$ \varphi_\gamma(x) @f$
238 /// (note that this is in the point @f$ x @f$, not @f$ \hat x @f$).
239 real_t final_φγ = 0;
240};
241
242template <Config Conf>
245 const PANTRStats<Conf> &s) {
247 acc.time_progress_callback += s.time_progress_callback;
248 acc.iterations += s.iterations;
249 acc.accelerated_step_rejected += s.accelerated_step_rejected;
250 acc.stepsize_backtracks += s.stepsize_backtracks;
251 acc.direction_failures += s.direction_failures;
252 acc.direction_update_rejected += s.direction_update_rejected;
253 acc.final_γ = s.final_γ;
254 acc.final_ψ = s.final_ψ;
255 acc.final_h = s.final_h;
256 acc.final_φγ = s.final_φγ;
257 return acc;
258}
259
260// clang-format off
261ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigd);
262ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigf);)
263ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRParams, EigenConfigl);)
265
266ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigd);
267ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigf);)
268ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRStats, EigenConfigl);)
270
271ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigd);
272ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigf);)
273ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, PANTRProgressInfo, EigenConfigl);)
275// clang-format on
276
277} // namespace alpaqa
PANTR solver for ALM.
Definition pantr.hpp:143
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:170
std::function< void(const ProgressInfo &)> progress_cb
Definition pantr.hpp:201
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:157
Direction direction
Definition pantr.hpp:205
InnerSolveOptions< config_t > SolveOptions
Definition pantr.hpp:152
PANTRSolver(const Params &params, const Direction &direction)
Definition pantr.hpp:159
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:187
AtomicStopSignal stop_signal
Definition pantr.hpp:200
DirectionT Direction
Definition pantr.hpp:149
const Params & get_params() const
Definition pantr.hpp:196
PANTRStats< config_t > Stats
Definition pantr.hpp:150
PANTRSolver(const Params &params)
Definition pantr.hpp:154
Stats operator()(const P &problem, const SolveOptions &opts, rvec x)
Definition pantr.hpp:176
TypeErasedProblem< config_t > Problem
Definition pantr.hpp:147
std::ostream * os
Definition pantr.hpp:206
The main polymorphic minimization problem interface.
#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
unsigned stepsize_backtracks
Definition pantr.hpp:103
unsigned direction_update_rejected
Definition pantr.hpp:105
typename Conf::mvec mvec
Definition config.hpp:67
@ ApproxKKT
Find an ε-approximate KKT point in the ∞-norm:
LipschitzEstimateParams< config_t > Lipschitz
Parameters related to the Lipschitz constant estimate and step size.
Definition pantr.hpp:26
real_t TR_tolerance_factor
Definition pantr.hpp:48
unsigned accelerated_step_rejected
Definition pantr.hpp:102
const TypeErasedProblem< config_t > * problem
Definition pantr.hpp:136
real_t ratio_threshold_good
Minimal TR ratio to increase radius (very successful).
Definition pantr.hpp:53
bool disable_acceleration
Don't compute accelerated steps, fall back to forward-backward splitting.
Definition pantr.hpp:76
InnerStatsAccumulator< PANOCOCPStats< Conf > > & operator+=(InnerStatsAccumulator< PANOCOCPStats< Conf > > &acc, const PANOCOCPStats< Conf > &s)
unsigned max_no_progress
Maximum number of iterations without any progress before giving up.
Definition pantr.hpp:38
real_t L_max
Maximum Lipschitz constant estimate.
Definition pantr.hpp:34
bool recompute_last_prox_step_after_direction_reset
Definition pantr.hpp:72
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
@ Busy
In progress.
bool update_direction_on_prox_step
Definition pantr.hpp:71
std::chrono::nanoseconds time_progress_callback
Definition pantr.hpp:100
real_t initial_radius
Initial trust radius.
Definition pantr.hpp:63
std::chrono::nanoseconds elapsed_time
Definition pantr.hpp:99
typename Conf::real_t real_t
Definition config.hpp:65
unsigned direction_failures
Definition pantr.hpp:104
std::chrono::nanoseconds max_time
Maximum duration.
Definition pantr.hpp:30
bool ratio_approx_fbe_quadratic_model
Compute the trust-region ratio using an approximation of the quadratic model of the FBE,...
Definition pantr.hpp:90
real_t quadratic_upperbound_tolerance_factor
Definition pantr.hpp:46
constexpr const auto inf
Definition config.hpp:85
real_t radius_factor_rejected
TR radius decrease coefficient when unsuccessful.
Definition pantr.hpp:56
typename Conf::rvec rvec
Definition config.hpp:69
const PANTRParams< config_t > * params
Definition pantr.hpp:137
typename Conf::crvec crvec
Definition config.hpp:70
unsigned print_interval
When to print progress.
Definition pantr.hpp:42
real_t ratio_threshold_acceptable
Minimal TR ratio to be accepted (successful).
Definition pantr.hpp:51
int print_precision
The precision of the floating point values printed by the solver.
Definition pantr.hpp:44
real_t min_radius
Minimum trust radius.
Definition pantr.hpp:65
real_t L_min
Minimum Lipschitz constant estimate.
Definition pantr.hpp:32
real_t radius_factor_good
TR radius increase coefficient when very successful.
Definition pantr.hpp:60
bool compute_ratio_using_new_stepsize
Check the quadratic upperbound and update γ before computing the reduction of the TR step.
Definition pantr.hpp:69
unsigned iterations
Definition pantr.hpp:101
real_t radius_factor_acceptable
TR radius decrease coefficient when successful.
Definition pantr.hpp:58
SolverStatus status
Definition pantr.hpp:97
unsigned max_iter
Maximum number of inner PANTR iterations.
Definition pantr.hpp:28
PANOCStopCrit stop_crit
What stopping criterion to use.
Definition pantr.hpp:36
Tuning parameters for the PANTR algorithm.
Definition pantr.hpp:22