Nonconvex constrained optimization
Loading...
Searching...
No Matches
fista.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <alpaqa/export.hpp>
11#include <guanaqo/atomic-stop-signal.hpp>
12
13#include <chrono>
14#include <iostream>
15#include <limits>
16#include <stdexcept>
17#include <string>
18#include <type_traits>
19
20namespace alpaqa {
21
22/// Tuning parameters for the FISTA algorithm.
23/// @ingroup grp_Parameters
24template <Config Conf = DefaultConfig>
27
28 /// Parameters related to the Lipschitz constant estimate and step size.
30 /// Maximum number of inner FISTA iterations.
31 unsigned max_iter = 1000;
32 /// Maximum duration.
33 std::chrono::nanoseconds max_time = std::chrono::minutes(5);
34 /// Minimum Lipschitz constant estimate.
36 /// Maximum Lipschitz constant estimate.
38 /// What stopping criterion to use.
40 /// Maximum number of iterations without any progress before giving up.
41 unsigned max_no_progress = 10;
42
43 /// When to print progress. If set to zero, nothing will be printed.
44 /// If set to N != 0, progress is printed every N iterations.
45 unsigned print_interval = 0;
46 /// The precision of the floating point values printed by the solver.
47 int print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
48
49 /// Tolerance factor used in the quadratic upper bound condition that
50 /// determines the step size. Its goal is to account for numerical errors
51 /// in the function and gradient evaluations. If you notice that the step
52 /// size γ becomes very small, you may want to increase this factor.
54 10 * std::numeric_limits<real_t>::epsilon();
55
56 /// Don't compute accelerated steps, fall back to forward-backward splitting.
57 /// For testing purposes.
59};
60
61template <Config Conf = DefaultConfig>
62struct FISTAStats {
64
67 std::chrono::nanoseconds elapsed_time{};
68 std::chrono::nanoseconds time_progress_callback{};
69 unsigned iterations = 0;
70 unsigned stepsize_backtracks = 0;
74};
75
76template <Config Conf = DefaultConfig>
104
105/// FISTA solver for ALM.
106/// @ingroup grp_InnerSolvers
107template <Config Conf>
109 public:
111
117
119
120 Stats operator()(const Problem &problem, // in
121 const SolveOptions &opts, // in
122 rvec x, // inout
123 rvec y, // inout
124 crvec Σ, // in
125 rvec err_z); // out
126
127 template <class P>
128 Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y,
129 crvec Σ, rvec e) {
130 return operator()(Problem{&problem}, opts, x, y, Σ, e);
131 }
132
133 template <class P>
134 Stats operator()(const P &problem, const SolveOptions &opts, rvec x) {
135 if (problem.get_num_constraints() != 0)
136 throw std::invalid_argument("Missing arguments y, Σ, e");
137 mvec y{nullptr, 0}, Σ{nullptr, 0}, e{nullptr, 0};
138 return operator()(problem, opts, x, y, Σ, e);
139 }
140
141 /// Specify a callable that is invoked with some intermediate results on
142 /// each iteration of the algorithm.
143 /// @see @ref ProgressInfo
145 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
146 this->progress_cb = cb;
147 return *this;
148 }
149
150 std::string get_name() const;
151
152 void stop() { stop_signal.stop(); }
153
154 const Params &get_params() const { return params; }
155
156 private:
158 guanaqo::AtomicStopSignal stop_signal;
159 std::function<void(const ProgressInfo &)> progress_cb;
161
162 public:
163 std::ostream *os = &std::cout;
164};
165
166template <class InnerSolverStats>
168
169template <Config Conf>
172
173 /// Total elapsed time in the inner solver.
174 std::chrono::nanoseconds elapsed_time{};
175 /// Total time spent in the user-provided progress callback.
176 std::chrono::nanoseconds time_progress_callback{};
177 /// Total number of inner FISTA iterations.
178 unsigned iterations = 0;
179 /// Total number of FISTA step size reductions.
181 /// The final FISTA step size γ.
183 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
185 /// Final value of the nonsmooth cost @f$ h(\hat x) @f$.
187};
188
189template <Config Conf>
192 const FISTAStats<Conf> &s) {
193 acc.iterations += s.iterations;
194 acc.elapsed_time += s.elapsed_time;
195 acc.time_progress_callback += s.time_progress_callback;
196 acc.stepsize_backtracks += s.stepsize_backtracks;
197 acc.final_γ = s.final_γ;
198 acc.final_ψ = s.final_ψ;
199 acc.final_h = s.final_h;
200 return acc;
201}
202
203// clang-format off
204ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAParams, EigenConfigd);
205ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAParams, EigenConfigf);)
206ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAParams, EigenConfigl);)
207ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAParams, EigenConfigq);)
208
209ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAStats, EigenConfigd);
210ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAStats, EigenConfigf);)
211ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAStats, EigenConfigl);)
212ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAStats, EigenConfigq);)
213
214ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAProgressInfo, EigenConfigd);
215ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAProgressInfo, EigenConfigf);)
216ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAProgressInfo, EigenConfigl);)
217ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAProgressInfo, EigenConfigq);)
218
219ALPAQA_EXPORT_EXTERN_TEMPLATE(class, FISTASolver, EigenConfigd);
220ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(class, FISTASolver, EigenConfigf);)
221ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(class, FISTASolver, EigenConfigl);)
222ALPAQA_IF_QUADF(ALPAQA_EXPORT_EXTERN_TEMPLATE(class, FISTASolver, EigenConfigq);)
223// clang-format on
224
225} // namespace alpaqa
FISTA solver for ALM.
Definition fista.hpp:108
std::string get_name() const
Definition fista.tpp:21
FISTAParams< config_t > Params
Definition fista.hpp:113
FISTASolver & 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 fista.hpp:145
Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec e)
Definition fista.hpp:128
std::function< void(const ProgressInfo &)> progress_cb
Definition fista.hpp:159
Stats operator()(const Problem &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec err_z)
Definition fista.tpp:69
InnerSolveOptions< config_t > SolveOptions
Definition fista.hpp:116
const Params & get_params() const
Definition fista.hpp:154
FISTAProgressInfo< config_t > ProgressInfo
Definition fista.hpp:115
guanaqo::AtomicStopSignal stop_signal
Definition fista.hpp:158
FISTAStats< config_t > Stats
Definition fista.hpp:114
detail::PANOCHelpers< config_t > Helpers
Definition fista.hpp:160
Stats operator()(const P &problem, const SolveOptions &opts, rvec x)
Definition fista.hpp:134
FISTASolver(const Params &params)
Definition fista.hpp:118
TypeErasedProblem< config_t > Problem
Definition fista.hpp:112
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 ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition export.hpp:23
LipschitzEstimateParams< config_t > Lipschitz
Definition fista.hpp:29
std::chrono::nanoseconds max_time
Definition fista.hpp:33
real_t quadratic_upperbound_tolerance_factor
Definition fista.hpp:53
Tuning parameters for the FISTA algorithm.
Definition fista.hpp:25
Parameters for the estimation of the Lipschitz constant of the gradient of the smooth term of the cos...
Definition lipschitz.hpp:12
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 fista.hpp:68
std::chrono::nanoseconds elapsed_time
Definition fista.hpp:67
typename Conf::real_t real_t
Definition config.hpp:86
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 FISTAParams< config_t > * params
Definition fista.hpp:100
const TypeErasedProblem< config_t > * problem
Definition fista.hpp:99
FISTAProgressInfo & operator=(const FISTAProgressInfo &)=delete