alpaqa 1.0.0a10
Nonconvex constrained optimization
Loading...
Searching...
No Matches
anderson.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace alpaqa {
8
9/// Parameters for the @ref AndersonDirection class.
10template <Config Conf>
13};
14
15/// @ingroup grp_DirectionProviders
16template <Config Conf>
19
24
26
27 struct Params {
30 };
31
32 AndersonDirection() = default;
34 : anderson(params.accelerator), direction_params(params.direction) {}
36 const DirectionParams &directionparams = {})
37 : anderson(params), direction_params(directionparams) {}
39 const DirectionParams &directionparams = {})
40 : anderson(anderson), direction_params(directionparams) {}
42 const DirectionParams &directionparams = {})
43 : anderson(std::move(anderson)), direction_params(directionparams) {}
44
45 /// @see @ref PANOCDirection::initialize
46 void initialize(const Problem &problem, [[maybe_unused]] crvec y,
47 [[maybe_unused]] crvec Σ, [[maybe_unused]] real_t γ_0,
48 [[maybe_unused]] crvec x_0, [[maybe_unused]] crvec x̂_0,
49 [[maybe_unused]] crvec p_0,
50 [[maybe_unused]] crvec grad_ψx_0) {
51 anderson.resize(problem.get_n());
52 anderson.initialize(x̂_0, p_0);
53 }
54
55 /// @see @ref PANOCDirection::has_initial_direction
56 bool has_initial_direction() const { return false; }
57
58 /// @see @ref PANOCDirection::update
59 bool update([[maybe_unused]] real_t γₖ, [[maybe_unused]] real_t γₙₑₓₜ,
60 [[maybe_unused]] crvec xₖ, [[maybe_unused]] crvec xₙₑₓₜ,
61 [[maybe_unused]] crvec pₖ, [[maybe_unused]] crvec pₙₑₓₜ,
62 [[maybe_unused]] crvec grad_ψxₖ,
63 [[maybe_unused]] crvec grad_ψxₙₑₓₜ) {
64 return true;
65 }
66
67 /// @see @ref PANOCDirection::apply
68 bool apply([[maybe_unused]] real_t γₖ, [[maybe_unused]] crvec xₖ,
69 [[maybe_unused]] crvec x̂ₖ, crvec pₖ,
70 [[maybe_unused]] crvec grad_ψxₖ, rvec qₖ) const {
71 anderson.compute(x̂ₖ, pₖ, qₖ);
72 qₖ -= xₖ;
73 return true;
74 }
75
76 /// @see @ref PANOCDirection::changed_γ
77 void changed_γ(real_t γₖ, real_t old_γₖ) {
79 anderson.scale_R(γₖ / old_γₖ);
80 else
82 }
83
84 /// @see @ref PANOCDirection::reset
85 void reset() { anderson.reset(); }
86
87 /// @see @ref PANOCDirection::get_name
88 std::string get_name() const {
89 return "AndersonDirection<" + std::string(config_t::get_name()) + '>';
90 }
91 auto get_params() const {
92 return std::tie(anderson.get_params(), direction_params);
93 }
94
96};
97
98} // namespace alpaqa
void compute(crvec gₖ, crvec rₖ, rvec xₖ_aa)
Compute the accelerated iterate , given the function value at the current iterate and the correspond...
Definition: anderson.hpp:78
const Params & get_params() const
Get the parameters.
Definition: anderson.hpp:115
void initialize(crvec g_0, crvec r_0)
Call this function on the first iteration to initialize the accelerator.
Definition: anderson.hpp:66
void resize(length_t n)
Change the problem dimension.
Definition: anderson.hpp:56
void reset()
Reset the accelerator (but keep the last function value and residual, so calling initialize is not ne...
Definition: anderson.hpp:100
AndersonAccelParams< config_t > Params
Definition: anderson.hpp:41
void scale_R(real_t scal)
Scale the factorization.
Definition: anderson.hpp:122
length_t get_n() const
[Required] Number of decision variables.
#define USING_ALPAQA_CONFIG(Conf)
Definition: config.hpp:54
typename Conf::real_t real_t
Definition: config.hpp:63
typename Conf::rvec rvec
Definition: config.hpp:67
typename Conf::crvec crvec
Definition: config.hpp:68
Parameters for the AndersonDirection class.
Definition: anderson.hpp:11
AndersonDirection(AndersonAccel &&anderson, const DirectionParams &directionparams={})
Definition: anderson.hpp:41
std::string get_name() const
Definition: anderson.hpp:88
void changed_γ(real_t γₖ, real_t old_γₖ)
Definition: anderson.hpp:77
AndersonDirection(const typename AndersonAccel::Params &params, const DirectionParams &directionparams={})
Definition: anderson.hpp:35
DirectionParams direction_params
Definition: anderson.hpp:95
bool update(real_t γₖ, real_t γₙₑₓₜ, crvec xₖ, crvec xₙₑₓₜ, crvec pₖ, crvec pₙₑₓₜ, crvec grad_ψxₖ, crvec grad_ψxₙₑₓₜ)
Definition: anderson.hpp:59
auto get_params() const
Definition: anderson.hpp:91
typename AndersonAccel::Params AcceleratorParams
Definition: anderson.hpp:22
AndersonDirection(const Params &params)
Definition: anderson.hpp:33
AndersonDirection(const AndersonAccel &anderson, const DirectionParams &directionparams={})
Definition: anderson.hpp:38
AndersonAccel anderson
Definition: anderson.hpp:25
void initialize(const Problem &problem, crvec y, crvec Σ, real_t γ_0, crvec x_0, crvec x̂_0, crvec p_0, crvec grad_ψx_0)
Definition: anderson.hpp:46
bool apply(real_t γₖ, crvec xₖ, crvec x̂ₖ, crvec pₖ, crvec grad_ψxₖ, rvec qₖ) const
Definition: anderson.hpp:68
bool has_initial_direction() const
Definition: anderson.hpp:56
AcceleratorParams accelerator
Definition: anderson.hpp:28