alpaqa pantr
Nonconvex constrained optimization
Loading...
Searching...
No Matches
inner/directions/panoc/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...
const Params & get_params() const
Get the parameters.
void initialize(crvec g_0, crvec r_0)
Call this function on the first iteration to initialize the accelerator.
void resize(length_t n)
Change the problem dimension.
void reset()
Reset the accelerator (but keep the last function value and residual, so calling initialize is not ne...
AndersonAccelParams< config_t > Params
void scale_R(real_t scal)
Scale the factorization.
length_t get_n() const
[Required] Number of decision variables.
#define USING_ALPAQA_CONFIG(Conf)
Definition: config.hpp:42
typename Conf::real_t real_t
Definition: config.hpp:51
typename Conf::rvec rvec
Definition: config.hpp:55
typename Conf::crvec crvec
Definition: config.hpp:56
Parameters for the AndersonDirection class.
AndersonDirection(AndersonAccel &&anderson, const DirectionParams &directionparams={})
void changed_γ(real_t γₖ, real_t old_γₖ)
AndersonDirection(const typename AndersonAccel::Params &params, const DirectionParams &directionparams={})
bool update(real_t γₖ, real_t γₙₑₓₜ, crvec xₖ, crvec xₙₑₓₜ, crvec pₖ, crvec pₙₑₓₜ, crvec grad_ψxₖ, crvec grad_ψxₙₑₓₜ)
typename AndersonAccel::Params AcceleratorParams
AndersonDirection(const AndersonAccel &anderson, const DirectionParams &directionparams={})
void initialize(const Problem &problem, crvec y, crvec Σ, real_t γ_0, crvec x_0, crvec x̂_0, crvec p_0, crvec grad_ψx_0)
bool apply(real_t γₖ, crvec xₖ, crvec x̂ₖ, crvec pₖ, crvec grad_ψxₖ, rvec qₖ) const