alpaqa pantr
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>
15 /// Set this option to true to include the Hessian-vector product
16 /// @f$ \nabla^2_{x_\mathcal{J}x_\mathcal{K}}\psi(x) q_\mathcal{K} @f$ from
17 /// equation 12b in @cite pas2022alpaqa, false to leave out that term.
18 bool hessian_vec = true;
19 /// If @ref hessian_vec is true, set this option to true to approximate that
20 /// term using finite differences instead of using AD.
22 /// If both @ref hessian_vec and @ref hessian_vec_finite_differences are
23 /// true, set this option to true to compute the exact Hessian of the
24 /// augmented Lagrangian, false to approximate it using the Hessian of the
25 /// Lagrangian.
28 /// If L-BFGS fails, propagate the failure and tell PANOC that no
29 /// accelerated step is available, causing it to accept the projected
30 /// gradient step instead.
32 /// If L-BFGS fails, return @f$ q_\mathcal{J} =
33 /// -\gamma\nabla_{x_\mathcal{J}}\psi(x^k)
34 /// -\gamma\nabla^2_{x_\mathcal{J}x_\mathcal{K}}\psi(x)
35 /// q_\mathcal{K} @f$ as the accelerated step (effectively approximating
36 /// @f$ \nabla_{x_\mathcal{J}x_\mathcal{J}} \approx \gamma I @f$).
38 }
39 /// What to do when L-BFGS failed (e.g. if there were no pairs (s, y) with
40 /// positive curvature).
42};
43
44/// @ingroup grp_DirectionProviders
45template <Config Conf = DefaultConfig>
52
53 struct Params {
56 };
57
60 : lbfgs(params.accelerator), direction_params(params.direction) {}
62 const DirectionParams &directionparams = {})
63 : lbfgs(params), direction_params(directionparams) {}
65 const DirectionParams &directionparams = {})
66 : lbfgs(lbfgs), direction_params(directionparams) {}
68 const DirectionParams &directionparams = {})
69 : lbfgs(std::move(lbfgs)), direction_params(directionparams) {}
70
71 /// @see @ref PANOCDirection::initialize
72 void initialize(const Problem &problem, crvec y, crvec Σ, real_t γ_0,
73 crvec x_0, crvec x̂_0, crvec p_0, crvec grad_ψx_0);
74
75 /// @see @ref PANOCDirection::has_initial_direction
76 bool has_initial_direction() const { return false; }
77
78 /// @see @ref PANOCDirection::update
79 bool update([[maybe_unused]] real_t γₖ, [[maybe_unused]] real_t γₙₑₓₜ,
80 crvec xₖ, crvec xₙₑₓₜ, [[maybe_unused]] crvec pₖ,
81 [[maybe_unused]] crvec pₙₑₓₜ, crvec grad_ψxₖ,
82 crvec grad_ψxₙₑₓₜ) {
83 const bool force = true;
84 return lbfgs.update(xₖ, xₙₑₓₜ, grad_ψxₖ, grad_ψxₙₑₓₜ,
86 }
87
88 /// @see @ref PANOCDirection::apply
89 bool apply(real_t γₖ, crvec xₖ, crvec x̂ₖ, crvec pₖ, crvec grad_ψxₖ,
90 rvec qₖ) const;
91
92 /// @see @ref PANOCDirection::changed_γ
93 void changed_γ([[maybe_unused]] real_t γₖ, [[maybe_unused]] real_t old_γₖ) {
94 // Nothing, Hessian approximation is independent of step size
95 }
96
97 /// @see @ref PANOCDirection::reset
98 void reset() { lbfgs.reset(); }
99
100 /// @see @ref PANOCDirection::get_name
101 std::string get_name() const {
102 return "StructuredLBFGSDirection<" + std::string(config_t::get_name()) +
103 '>';
104 }
105
106 auto get_params() const {
107 return std::tie(lbfgs.get_params(), direction_params);
108 }
109
110 private:
112
113 const Problem *problem = nullptr;
114#ifndef _WIN32
115 std::optional<crvec> y = std::nullopt;
116 std::optional<crvec> Σ = std::nullopt;
117#else
118 std::optional<vec> y = std::nullopt;
119 std::optional<vec> Σ = std::nullopt;
120#endif
121
124 mutable vec HqK;
125 mutable vec work_n;
126 mutable vec work_n2;
127 mutable vec work_m;
128
129 void approximate_hessian_vec_term(crvec xₖ, crvec grad_ψxₖ, rvec qₖ,
130 crindexvec J) const;
131
132 public:
134};
135
140#ifdef ALPAQA_WITH_QUAD_PRECISION
142#endif
143
144} // namespace alpaqa
LBFGSParams< config_t > Params
const Params & get_params() const
Get the parameters.
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:42
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition: export.hpp:21
typename Conf::indexvec indexvec
Definition: config.hpp:64
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
typename Conf::vec vec
Definition: config.hpp:52
typename Conf::crindexvec crindexvec
Definition: config.hpp:66
Double-precision double configuration.
Definition: config.hpp:115
Single-precision float configuration.
Definition: config.hpp:111
long double configuration.
Definition: config.hpp:120
Parameters for the StructuredLBFGSDirection class.
bool hessian_vec
Set this option to true to include the Hessian-vector product from equation 12b in ,...
bool full_augmented_hessian
If both hessian_vec and hessian_vec_finite_differences are true, set this option to true to compute t...
bool hessian_vec_finite_differences
If hessian_vec is true, set this option to true to approximate that term using finite differences ins...
@ 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