alpaqa guanaqo
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.
10/// @ingroup grp_Parameters
11template <Config Conf>
13 /// Instead of flushing the buffer when the step size changes, rescale the
14 /// buffer by a factor @f$ \gamma_k / \gamma_{k-1} @f$.
16};
17
18/// @ingroup grp_DirectionProviders
19template <Config Conf>
22
27
29
34
35 AndersonDirection() = default;
37 : anderson(params.accelerator), direction_params(params.direction) {}
39 const DirectionParams &directionparams = {})
40 : anderson(params), direction_params(directionparams) {}
42 const DirectionParams &directionparams = {})
43 : anderson(anderson), direction_params(directionparams) {}
45 const DirectionParams &directionparams = {})
46 : anderson(std::move(anderson)), direction_params(directionparams) {}
47
48 /// @see @ref PANOCDirection::initialize
49 void initialize(const Problem &problem, [[maybe_unused]] crvec y,
50 [[maybe_unused]] crvec Σ, [[maybe_unused]] real_t γ_0,
51 [[maybe_unused]] crvec x_0, [[maybe_unused]] crvec x̂_0,
52 [[maybe_unused]] crvec p_0,
53 [[maybe_unused]] crvec grad_ψx_0) {
54 anderson.resize(problem.get_num_variables());
55 anderson.initialize(x̂_0, p_0);
56 }
57
58 /// @see @ref PANOCDirection::has_initial_direction
59 bool has_initial_direction() const { return false; }
60
61 /// @see @ref PANOCDirection::update
62 bool update([[maybe_unused]] real_t γₖ, [[maybe_unused]] real_t γₙₑₓₜ,
63 [[maybe_unused]] crvec xₖ, [[maybe_unused]] crvec xₙₑₓₜ,
64 [[maybe_unused]] crvec pₖ, [[maybe_unused]] crvec pₙₑₓₜ,
65 [[maybe_unused]] crvec grad_ψxₖ,
66 [[maybe_unused]] crvec grad_ψxₙₑₓₜ) {
67 return true;
68 }
69
70 /// @see @ref PANOCDirection::apply
71 bool apply([[maybe_unused]] real_t γₖ, [[maybe_unused]] crvec xₖ,
72 [[maybe_unused]] crvec x̂ₖ, crvec pₖ,
73 [[maybe_unused]] crvec grad_ψxₖ, rvec qₖ) const {
74 anderson.compute(x̂ₖ, pₖ, qₖ);
75 qₖ -= xₖ;
76 return true;
77 }
78
79 /// @see @ref PANOCDirection::changed_γ
80 void changed_γ(real_t γₖ, real_t old_γₖ) {
81 if (direction_params.rescale_on_step_size_changes)
82 anderson.scale_R(γₖ / old_γₖ);
83 else
84 anderson.reset();
85 }
86
87 /// @see @ref PANOCDirection::reset
88 void reset() { anderson.reset(); }
89
90 /// @see @ref PANOCDirection::get_name
91 std::string get_name() const {
92 return "AndersonDirection<" + std::string(config_t::get_name()) + '>';
93 }
94 auto get_params() const {
95 return std::tie(anderson.get_params(), direction_params);
96 }
97
99};
100
101} // namespace alpaqa
Anderson Acceleration.
Definition anderson.hpp:39
AndersonAccelParams< config_t > Params
Definition anderson.hpp:42
The main polymorphic minimization problem interface.
length_t get_num_variables() const
[Required] Number of decision variables.
#define USING_ALPAQA_CONFIG(Conf)
Definition config.hpp:77
Parameters for the AndersonDirection class.
Definition anderson.hpp:12
typename Conf::real_t real_t
Definition config.hpp:86
typename Conf::rvec rvec
Definition config.hpp:91
typename Conf::crvec crvec
Definition config.hpp:92
AndersonDirection(AndersonAccel &&anderson, const DirectionParams &directionparams={})
Definition anderson.hpp:44
std::string get_name() const
Definition anderson.hpp:91
void changed_γ(real_t γₖ, real_t old_γₖ)
Definition anderson.hpp:80
AndersonDirectionParams< config_t > DirectionParams
Definition anderson.hpp:26
AndersonDirection(const typename AndersonAccel::Params &params, const DirectionParams &directionparams={})
Definition anderson.hpp:38
alpaqa::AndersonAccel< config_t > AndersonAccel
Definition anderson.hpp:24
DirectionParams direction_params
Definition anderson.hpp:98
bool update(real_t γₖ, real_t γₙₑₓₜ, crvec xₖ, crvec xₙₑₓₜ, crvec pₖ, crvec pₙₑₓₜ, crvec grad_ψxₖ, crvec grad_ψxₙₑₓₜ)
Definition anderson.hpp:62
typename AndersonAccel::Params AcceleratorParams
Definition anderson.hpp:25
AndersonDirection(const Params &params)
Definition anderson.hpp:36
AndersonDirection(const AndersonAccel &anderson, const DirectionParams &directionparams={})
Definition anderson.hpp:41
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:49
bool apply(real_t γₖ, crvec xₖ, crvec x̂ₖ, crvec pₖ, crvec grad_ψxₖ, rvec qₖ) const
Definition anderson.hpp:71
bool has_initial_direction() const
Definition anderson.hpp:59
TypeErasedProblem< config_t > Problem
Definition anderson.hpp:23