alpaqa 1.0.0a9
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.
10template <Config Conf>
13};
14
15/// @ingroup grp_DirectionProviders
16template <Config Conf>
19
24
26
27 struct Params {
30 };
31
32 LBFGSDirection() = default;
33 LBFGSDirection(const Params &params)
34 : lbfgs(params.accelerator), direction_params(params.direction) {}
35 LBFGSDirection(const typename LBFGS::Params &params,
36 const DirectionParams &directionparams = {})
37 : lbfgs(params), direction_params(directionparams) {}
39 const DirectionParams &directionparams = {})
40 : lbfgs(lbfgs), direction_params(directionparams) {}
41 LBFGSDirection(LBFGS &&lbfgs, const DirectionParams &directionparams = {})
42 : lbfgs(std::move(lbfgs)), direction_params(directionparams) {}
43
44 /// @see @ref PANOCDirection::initialize
45 void initialize(const Problem &problem, [[maybe_unused]] crvec y,
46 [[maybe_unused]] crvec Σ, [[maybe_unused]] real_t γ_0,
47 [[maybe_unused]] crvec x_0, [[maybe_unused]] crvec x̂_0,
48 [[maybe_unused]] crvec p_0,
49 [[maybe_unused]] crvec grad_ψx_0) {
50 lbfgs.resize(problem.get_n());
51 }
52
53 /// @see @ref PANOCDirection::has_initial_direction
54 bool has_initial_direction() const { return false; }
55
56 /// @see @ref PANOCDirection::update
57 bool update([[maybe_unused]] real_t γₖ, [[maybe_unused]] real_t γₙₑₓₜ,
58 crvec xₖ, crvec xₙₑₓₜ, crvec pₖ, crvec pₙₑₓₜ,
59 [[maybe_unused]] crvec grad_ψxₖ,
60 [[maybe_unused]] crvec grad_ψxₙₑₓₜ) {
61 return lbfgs.update(xₖ, xₙₑₓₜ, pₖ, pₙₑₓₜ, LBFGS::Sign::Negative);
62 }
63
64 /// @see @ref PANOCDirection::apply
65 bool apply([[maybe_unused]] real_t γₖ, [[maybe_unused]] crvec xₖ,
66 [[maybe_unused]] crvec x̂ₖ, crvec pₖ,
67 [[maybe_unused]] crvec grad_ψxₖ, rvec qₖ) const {
68 qₖ = pₖ;
69 return lbfgs.apply(qₖ, γₖ);
70 }
71
72 /// @see @ref PANOCDirection::changed_γ
73 void changed_γ(real_t γₖ, real_t old_γₖ) {
75 lbfgs.scale_y(γₖ / old_γₖ);
76 else
77 lbfgs.reset();
78 }
79
80 /// @see @ref PANOCDirection::reset
81 void reset() { lbfgs.reset(); }
82
83 /// @see @ref PANOCDirection::get_name
84 std::string get_name() const {
85 return "LBFGSDirection<" + std::string(config_t::get_name()) + '>';
86 }
87 auto get_params() const {
88 return std::tie(lbfgs.get_params(), direction_params);
89 }
90
92};
93
94} // namespace alpaqa
LBFGSParams< config_t > Params
Definition: lbfgs.hpp:112
const Params & get_params() const
Get the parameters.
Definition: lbfgs.hpp:168
void resize(length_t n)
Re-allocate storage for a problem with a different size.
Definition: lbfgs.tpp:213
void reset()
Throw away the approximation and all previous vectors s and y.
Definition: lbfgs.tpp:207
bool apply(rvec q, real_t γ=-1) const
Apply the inverse Hessian approximation to the given vector q.
Definition: lbfgs.tpp:74
void scale_y(real_t factor)
Scale the stored y vectors by the given factor.
Definition: lbfgs.tpp:226
bool update(crvec xₖ, crvec xₙₑₓₜ, crvec pₖ, crvec pₙₑₓₜ, Sign sign=Sign::Positive, bool forced=false)
Update the inverse Hessian approximation using the new vectors xₙₑₓₜ and pₙₑₓₜ.
Definition: lbfgs.tpp:65
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 LBFGSDirection class.
Definition: lbfgs.hpp:11
std::string get_name() const
Definition: lbfgs.hpp:84
void changed_γ(real_t γₖ, real_t old_γₖ)
Definition: lbfgs.hpp:73
DirectionParams direction_params
Definition: lbfgs.hpp:91
DirectionParams direction
Definition: lbfgs.hpp:29
bool update(real_t γₖ, real_t γₙₑₓₜ, crvec xₖ, crvec xₙₑₓₜ, crvec pₖ, crvec pₙₑₓₜ, crvec grad_ψxₖ, crvec grad_ψxₙₑₓₜ)
Definition: lbfgs.hpp:57
auto get_params() const
Definition: lbfgs.hpp:87
LBFGSDirection(const LBFGS &lbfgs, const DirectionParams &directionparams={})
Definition: lbfgs.hpp:38
typename LBFGS::Params AcceleratorParams
Definition: lbfgs.hpp:22
LBFGSDirection(LBFGS &&lbfgs, const DirectionParams &directionparams={})
Definition: lbfgs.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: lbfgs.hpp:45
bool apply(real_t γₖ, crvec xₖ, crvec x̂ₖ, crvec pₖ, crvec grad_ψxₖ, rvec qₖ) const
Definition: lbfgs.hpp:65
bool has_initial_direction() const
Definition: lbfgs.hpp:54
AcceleratorParams accelerator
Definition: lbfgs.hpp:28
LBFGSDirection(const Params &params)
Definition: lbfgs.hpp:33
LBFGSDirection(const typename LBFGS::Params &params, const DirectionParams &directionparams={})
Definition: lbfgs.hpp:35