alpaqa cmake-targets
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>
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>
75
76template <Config Conf = DefaultConfig>
102
103/// FISTA solver for ALM.
104/// @ingroup grp_InnerSolvers
105template <Config Conf>
107 public:
109
115
117
118 Stats operator()(const Problem &problem, // in
119 const SolveOptions &opts, // in
120 rvec x, // inout
121 rvec y, // inout
122 crvec Σ, // in
123 rvec err_z); // out
124
125 template <class P>
126 Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y,
127 crvec Σ, rvec e) {
128 return operator()(Problem{&problem}, opts, x, y, Σ, e);
129 }
130
131 template <class P>
132 Stats operator()(const P &problem, const SolveOptions &opts, rvec x) {
133 if (problem.get_m() != 0)
134 throw std::invalid_argument("Missing arguments y, Σ, e");
135 mvec y{nullptr, 0}, Σ{nullptr, 0}, e{nullptr, 0};
136 return operator()(problem, opts, x, y, Σ, e);
137 }
138
139 /// Specify a callable that is invoked with some intermediate results on
140 /// each iteration of the algorithm.
141 /// @see @ref ProgressInfo
143 set_progress_callback(std::function<void(const ProgressInfo &)> cb) {
144 this->progress_cb = cb;
145 return *this;
146 }
147
148 std::string get_name() const;
149
150 void stop() { stop_signal.stop(); }
151
152 const Params &get_params() const { return params; }
153
154 private:
157 std::function<void(const ProgressInfo &)> progress_cb;
159
160 public:
161 std::ostream *os = &std::cout;
162};
163
164template <class InnerSolverStats>
166
167template <Config Conf>
170
171 /// Total elapsed time in the inner solver.
172 std::chrono::nanoseconds elapsed_time{};
173 /// Total time spent in the user-provided progress callback.
174 std::chrono::nanoseconds time_progress_callback{};
175 /// Total number of inner FISTA iterations.
176 unsigned iterations = 0;
177 /// Total number of FISTA step size reductions.
178 unsigned stepsize_backtracks = 0;
179 /// The final FISTA step size γ.
180 real_t final_γ = 0;
181 /// Final value of the smooth cost @f$ \psi(\hat x) @f$.
182 real_t final_ψ = 0;
183 /// Final value of the nonsmooth cost @f$ h(\hat x) @f$.
184 real_t final_h = 0;
185};
186
187template <Config Conf>
190 const FISTAStats<Conf> &s) {
192 acc.elapsed_time += s.elapsed_time;
193 acc.time_progress_callback += s.time_progress_callback;
194 acc.stepsize_backtracks += s.stepsize_backtracks;
195 acc.final_γ = s.final_γ;
196 acc.final_ψ = s.final_ψ;
197 acc.final_h = s.final_h;
198 return acc;
199}
200
201// clang-format off
202ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAParams, EigenConfigd);
203ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAParams, EigenConfigf);)
204ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAParams, EigenConfigl);)
206
207ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAStats, EigenConfigd);
208ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAStats, EigenConfigf);)
209ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAStats, EigenConfigl);)
211
212ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAProgressInfo, EigenConfigd);
213ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAProgressInfo, EigenConfigf);)
214ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(struct, FISTAProgressInfo, EigenConfigl);)
216
217ALPAQA_EXPORT_EXTERN_TEMPLATE(class, FISTASolver, EigenConfigd);
218ALPAQA_IF_FLOAT(ALPAQA_EXPORT_EXTERN_TEMPLATE(class, FISTASolver, EigenConfigf);)
219ALPAQA_IF_LONGD(ALPAQA_EXPORT_EXTERN_TEMPLATE(class, FISTASolver, EigenConfigl);)
221// clang-format on
222
223} // namespace alpaqa
FISTA solver for ALM.
Definition fista.hpp:106
std::string get_name() const
Definition fista.tpp:21
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:143
Stats operator()(const P &problem, const SolveOptions &opts, rvec x, rvec y, crvec Σ, rvec e)
Definition fista.hpp:126
std::function< void(const ProgressInfo &)> progress_cb
Definition fista.hpp:157
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:114
AtomicStopSignal stop_signal
Definition fista.hpp:156
const Params & get_params() const
Definition fista.hpp:152
FISTAStats< config_t > Stats
Definition fista.hpp:112
Stats operator()(const P &problem, const SolveOptions &opts, rvec x)
Definition fista.hpp:132
FISTASolver(const Params &params)
Definition fista.hpp:116
TypeErasedProblem< config_t > Problem
Definition fista.hpp:110
std::ostream * os
Definition fista.hpp:161
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 ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition export.hpp:21
LipschitzEstimateParams< config_t > Lipschitz
Parameters related to the Lipschitz constant estimate and step size.
Definition fista.hpp:29
bool disable_acceleration
Don't compute accelerated steps, fall back to forward-backward splitting.
Definition fista.hpp:58
unsigned max_no_progress
Maximum number of iterations without any progress before giving up.
Definition fista.hpp:41
real_t L_max
Maximum Lipschitz constant estimate.
Definition fista.hpp:37
std::chrono::nanoseconds max_time
Maximum duration.
Definition fista.hpp:33
real_t quadratic_upperbound_tolerance_factor
Tolerance factor used in the quadratic upper bound condition that determines the step size.
Definition fista.hpp:53
unsigned print_interval
When to print progress.
Definition fista.hpp:45
int print_precision
The precision of the floating point values printed by the solver.
Definition fista.hpp:47
real_t L_min
Minimum Lipschitz constant estimate.
Definition fista.hpp:35
unsigned max_iter
Maximum number of inner FISTA iterations.
Definition fista.hpp:31
PANOCStopCrit stop_crit
What stopping criterion to use.
Definition fista.hpp:39
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
unsigned stepsize_backtracks
Definition fista.hpp:70
typename Conf::mvec mvec
Definition config.hpp:67
@ ApproxKKT
Find an ε-approximate KKT point in the ∞-norm:
const FISTAParams< config_t > * params
Definition fista.hpp:100
const TypeErasedProblem< config_t > * problem
Definition fista.hpp:99
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
@ Busy
In progress.
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:65
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 iterations
Definition fista.hpp:69
SolverStatus status
Definition fista.hpp:65