alpaqa 1.0.0a11
Nonconvex constrained optimization
Loading...
Searching...
No Matches
structured-lbfgs.hpp
Go to the documentation of this file.
1#pragma once
2
8#include <optional>
9
10namespace alpaqa {
11
12/// Parameters for the @ref StructuredLBFGSDirection class.
13template <Config Conf>
16 /// Set this option to a nonzero value to include the Hessian-vector product
17 /// @f$ \nabla^2_{x_\mathcal{J}x_\mathcal{K}}\psi(x) q_\mathcal{K} @f$ from
18 /// equation 12b in @cite pas2022alpaqa, scaled by this parameter.
19 /// Set it to zero to leave out that term.
21 /// If @ref hessian_vec_factor is nonzero, set this option to true to
22 /// approximate that term using finite differences instead of using AD.
24 /// If @ref hessian_vec_factor is nonzero and
25 /// @ref hessian_vec_finite_differences is true, set this option to true to
26 /// compute the exact Hessian of the augmented Lagrangian, false to
27 /// approximate it using the Hessian of the Lagrangian.
30 /// If L-BFGS fails, propagate the failure and tell PANOC that no
31 /// accelerated step is available, causing it to accept the projected
32 /// gradient step instead.
34 /// If L-BFGS fails, return @f$ q_\mathcal{J} =
35 /// -\gamma\nabla_{x_\mathcal{J}}\psi(x^k)
36 /// -\gamma\nabla^2_{x_\mathcal{J}x_\mathcal{K}}\psi(x)
37 /// q_\mathcal{K} @f$ as the accelerated step (effectively approximating
38 /// @f$ \nabla_{x_\mathcal{J}x_\mathcal{J}} \approx \gamma I @f$).
40 }
41 /// What to do when L-BFGS failed (e.g. if there were no pairs (s, y) with
42 /// positive curvature).
44};
45
46/// @ingroup grp_DirectionProviders
47template <Config Conf = DefaultConfig>
54
55 struct Params {
58 };
59
62 : lbfgs(params.accelerator), direction_params(params.direction) {}
64 const DirectionParams &directionparams = {})
65 : lbfgs(params), direction_params(directionparams) {}
67 const DirectionParams &directionparams = {})
68 : lbfgs(lbfgs), direction_params(directionparams) {}
70 const DirectionParams &directionparams = {})
71 : lbfgs(std::move(lbfgs)), direction_params(directionparams) {}
72
73 /// @see @ref PANOCDirection::initialize
74 void initialize(const Problem &problem, crvec y, crvec Σ, real_t γ_0,
75 crvec x_0, crvec x̂_0, crvec p_0, crvec grad_ψx_0);
76
77 /// @see @ref PANOCDirection::has_initial_direction
78 bool has_initial_direction() const { return false; }
79
80 /// @see @ref PANOCDirection::update
81 bool update([[maybe_unused]] real_t γₖ, [[maybe_unused]] real_t γₙₑₓₜ,
82 crvec xₖ, crvec xₙₑₓₜ, [[maybe_unused]] crvec pₖ,
83 [[maybe_unused]] crvec pₙₑₓₜ, crvec grad_ψxₖ,
84 crvec grad_ψxₙₑₓₜ) {
85 const bool force = true;
86 return lbfgs.update(xₖ, xₙₑₓₜ, grad_ψxₖ, grad_ψxₙₑₓₜ,
88 }
89
90 /// @see @ref PANOCDirection::apply
91 bool apply(real_t γₖ, crvec xₖ, crvec x̂ₖ, crvec pₖ, crvec grad_ψxₖ,
92 rvec qₖ) const;
93
94 /// @see @ref PANOCDirection::changed_γ
95 void changed_γ([[maybe_unused]] real_t γₖ, [[maybe_unused]] real_t old_γₖ) {
96 // Nothing, Hessian approximation is independent of step size
97 }
98
99 /// @see @ref PANOCDirection::reset
100 void reset() { lbfgs.reset(); }
101
102 /// @see @ref PANOCDirection::get_name
103 std::string get_name() const {
104 return "StructuredLBFGSDirection<" + std::string(config_t::get_name()) +
105 '>';
106 }
107
108 auto get_params() const {
109 return std::tie(lbfgs.get_params(), direction_params);
110 }
111
112 private:
114
115 const Problem *problem = nullptr;
116#ifndef _WIN32
117 std::optional<crvec> y = std::nullopt;
118 std::optional<crvec> Σ = std::nullopt;
119#else
120 std::optional<vec> y = std::nullopt;
121 std::optional<vec> Σ = std::nullopt;
122#endif
123
126 mutable vec HqK;
127 mutable vec work_n;
128 mutable vec work_n2;
129 mutable vec work_m;
130
131 void approximate_hessian_vec_term(crvec xₖ, crvec grad_ψxₖ, rvec qₖ,
132 crindexvec J) const;
133
134 public:
136};
137
138// clang-format off
143// clang-format on
144
145} // namespace alpaqa
LBFGSParams< config_t > Params
Definition: lbfgs.hpp:112
const Params & get_params() const
Get the parameters.
Definition: lbfgs.hpp:168
void reset()
Throw away the approximation and all previous vectors s and y.
Definition: lbfgs.tpp:207
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
#define USING_ALPAQA_CONFIG(Conf)
Definition: config.hpp:54
#define ALPAQA_IF_QUADF(...)
Definition: config.hpp:171
#define ALPAQA_IF_LONGD(...)
Definition: config.hpp:183
#define ALPAQA_IF_FLOAT(...)
Definition: config.hpp:177
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition: export.hpp:21
typename Conf::indexvec indexvec
Definition: config.hpp:76
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
typename Conf::vec vec
Definition: config.hpp:64
typename Conf::crindexvec crindexvec
Definition: config.hpp:78
Double-precision double configuration.
Definition: config.hpp:127
Single-precision float configuration.
Definition: config.hpp:123
long double configuration.
Definition: config.hpp:132
Parameters for the StructuredLBFGSDirection class.
real_t hessian_vec_factor
Set this option to a nonzero value to include the Hessian-vector product from equation 12b in ,...
bool full_augmented_hessian
If hessian_vec_factor is nonzero and hessian_vec_finite_differences is true, set this option to true ...
bool hessian_vec_finite_differences
If hessian_vec_factor is nonzero, set this option to true to approximate that term using finite diffe...
@ FallbackToProjectedGradient
If L-BFGS fails, propagate the failure and tell PANOC that no accelerated step is available,...
@ UseScaledLBFGSInput
If L-BFGS fails, return as the accelerated step (effectively approximating ).
enum alpaqa::StructuredLBFGSDirectionParams::FailurePolicy failure_policy
What to do when L-BFGS failed (e.g.
void changed_γ(real_t γₖ, real_t old_γₖ)
bool update(real_t γₖ, real_t γₙₑₓₜ, crvec xₖ, crvec xₙₑₓₜ, crvec pₖ, crvec pₙₑₓₜ, crvec grad_ψxₖ, crvec grad_ψxₙₑₓₜ)
StructuredLBFGSDirection(LBFGS &&lbfgs, const DirectionParams &directionparams={})
typename LBFGS::Params AcceleratorParams
StructuredLBFGSDirection(const LBFGS &lbfgs, const DirectionParams &directionparams={})
StructuredLBFGSDirection(const Params &params)
StructuredLBFGSDirection(const typename LBFGS::Params &params, 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)
void approximate_hessian_vec_term(crvec xₖ, crvec grad_ψxₖ, rvec qₖ, crindexvec J) const
bool apply(real_t γₖ, crvec xₖ, crvec x̂ₖ, crvec pₖ, crvec grad_ψxₖ, rvec qₖ) const
TypeErasedProblem< config_t > Problem