alpaqa guanaqo
Nonconvex constrained optimization
Loading...
Searching...
No Matches
lbfgs.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace alpaqa {
8
9/// Parameters for the @ref LBFGSDirection 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 LBFGSDirection() = default;
37 : lbfgs(params.accelerator), direction_params(params.direction) {}
39 const DirectionParams &directionparams = {})
40 : lbfgs(params), direction_params(directionparams) {}
42 const DirectionParams &directionparams = {})
43 : lbfgs(lbfgs), direction_params(directionparams) {}
44 LBFGSDirection(LBFGS &&lbfgs, const DirectionParams &directionparams = {})
45 : lbfgs(std::move(lbfgs)), direction_params(directionparams) {}
46
47 /// @see @ref PANOCDirection::initialize
48 void initialize(const Problem &problem, [[maybe_unused]] crvec y,
49 [[maybe_unused]] crvec Σ, [[maybe_unused]] real_t γ_0,
50 [[maybe_unused]] crvec x_0, [[maybe_unused]] crvec x̂_0,
51 [[maybe_unused]] crvec p_0,
52 [[maybe_unused]] crvec grad_ψx_0) {
53 lbfgs.resize(problem.get_num_variables());
54 }
55
56 /// @see @ref PANOCDirection::has_initial_direction
57 bool has_initial_direction() const { return false; }
58
59 /// @see @ref PANOCDirection::update
60 bool update([[maybe_unused]] real_t γₖ, [[maybe_unused]] real_t γₙₑₓₜ,
61 crvec xₖ, crvec xₙₑₓₜ, crvec pₖ, crvec pₙₑₓₜ,
62 [[maybe_unused]] crvec grad_ψxₖ,
63 [[maybe_unused]] crvec grad_ψxₙₑₓₜ) {
64 return lbfgs.update(xₖ, xₙₑₓₜ, pₖ, pₙₑₓₜ, LBFGS::Sign::Negative);
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 qₖ = pₖ;
72 return lbfgs.apply(qₖ, γₖ);
73 }
74
75 /// @see @ref PANOCDirection::changed_γ
76 void changed_γ(real_t γₖ, real_t old_γₖ) {
77 if (direction_params.rescale_on_step_size_changes)
78 lbfgs.scale_y(γₖ / old_γₖ);
79 else
80 lbfgs.reset();
81 }
82
83 /// @see @ref PANOCDirection::reset
84 void reset() { lbfgs.reset(); }
85
86 /// @see @ref PANOCDirection::get_name
87 std::string get_name() const {
88 return "LBFGSDirection<" + std::string(config_t::get_name()) + '>';
89 }
90 auto get_params() const {
91 return std::tie(lbfgs.get_params(), direction_params);
92 }
93
95};
96
97} // namespace alpaqa
Limited memory Broyden–Fletcher–Goldfarb–Shanno (L-BFGS) algorithm.
Definition lbfgs.hpp:117
LBFGSParams< config_t > Params
Definition lbfgs.hpp:121
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 LBFGSDirection class.
Definition lbfgs.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
std::string get_name() const
Definition lbfgs.hpp:87
LBFGSDirectionParams< config_t > DirectionParams
Definition lbfgs.hpp:26
void changed_γ(real_t γₖ, real_t old_γₖ)
Definition lbfgs.hpp:76
DirectionParams direction_params
Definition lbfgs.hpp:94
DirectionParams direction
Definition lbfgs.hpp:32
bool update(real_t γₖ, real_t γₙₑₓₜ, crvec xₖ, crvec xₙₑₓₜ, crvec pₖ, crvec pₙₑₓₜ, crvec grad_ψxₖ, crvec grad_ψxₙₑₓₜ)
Definition lbfgs.hpp:60
auto get_params() const
Definition lbfgs.hpp:90
LBFGSDirection(const LBFGS &lbfgs, const DirectionParams &directionparams={})
Definition lbfgs.hpp:41
typename LBFGS::Params AcceleratorParams
Definition lbfgs.hpp:25
LBFGSDirection(LBFGS &&lbfgs, const DirectionParams &directionparams={})
Definition lbfgs.hpp:44
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 lbfgs.hpp:48
bool apply(real_t γₖ, crvec xₖ, crvec x̂ₖ, crvec pₖ, crvec grad_ψxₖ, rvec qₖ) const
Definition lbfgs.hpp:68
alpaqa::LBFGS< config_t > LBFGS
Definition lbfgs.hpp:24
bool has_initial_direction() const
Definition lbfgs.hpp:57
AcceleratorParams accelerator
Definition lbfgs.hpp:31
LBFGSDirection(const Params &params)
Definition lbfgs.hpp:36
LBFGSDirection(const typename LBFGS::Params &params, const DirectionParams &directionparams={})
Definition lbfgs.hpp:38
TypeErasedProblem< config_t > Problem
Definition lbfgs.hpp:23