alpaqa no-casadi-dep
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.
13/// @ingroup grp_Parameters
14template <Config Conf>
17 /// Set this option to a nonzero value to include the Hessian-vector product
18 /// @f$ \nabla^2_{x_\mathcal{J}x_\mathcal{K}}\psi(x) q_\mathcal{K} @f$ from
19 /// equation 12b in @cite pas2022alpaqa, scaled by this parameter.
20 /// Set it to zero to leave out that term (this usually only slightly
21 /// increases the number of iterations, and eliminates one Hessian-vector
22 /// product per iteration, improving the overall runtime).
24 /// If @ref hessian_vec_factor is nonzero, set this option to true to
25 /// approximate that term using finite differences instead of using AD.
27 /// If @ref hessian_vec_factor is nonzero and
28 /// @ref hessian_vec_finite_differences is true, set this option to true to
29 /// compute the exact Hessian of the augmented Lagrangian, false to
30 /// approximate it using the Hessian of the Lagrangian.
33 /// If L-BFGS fails, propagate the failure and tell PANOC that no
34 /// accelerated step is available, causing it to accept the projected
35 /// gradient step instead.
37 /// If L-BFGS fails, return @f$ q_\mathcal{J} =
38 /// -\gamma\nabla_{x_\mathcal{J}}\psi(x^k)
39 /// -\gamma\nabla^2_{x_\mathcal{J}x_\mathcal{K}}\psi(x)
40 /// q_\mathcal{K} @f$ as the accelerated step (effectively approximating
41 /// @f$ \nabla_{x_\mathcal{J}x_\mathcal{J}} \approx \gamma I @f$).
43 }
44 /// What to do when L-BFGS failed (e.g. if there were no pairs (s, y) with
45 /// positive curvature).
47};
48
49/// @ingroup grp_DirectionProviders
50template <Config Conf = DefaultConfig>
57
62
65 : lbfgs(params.accelerator), direction_params(params.direction) {}
75
76 /// @see @ref PANOCDirection::initialize
79
80 /// @see @ref PANOCDirection::has_initial_direction
81 bool has_initial_direction() const { return false; }
82
83 /// @see @ref PANOCDirection::update
92
93 /// @see @ref PANOCDirection::apply
95 rvec qₖ) const;
96
97 /// @see @ref PANOCDirection::changed_γ
99 // Nothing, Hessian approximation is independent of step size
100 }
101
102 /// @see @ref PANOCDirection::reset
103 void reset() { lbfgs.reset(); }
104
105 /// @see @ref PANOCDirection::get_name
106 std::string get_name() const {
107 return "StructuredLBFGSDirection<" + std::string(config_t::get_name()) +
108 '>';
109 }
110
111 auto get_params() const {
112 return std::tie(lbfgs.get_params(), direction_params);
113 }
114
115 private:
117
118 const Problem *problem = nullptr;
119#ifndef _WIN32
120 std::optional<crvec> y = std::nullopt;
121 std::optional<crvec> Σ = std::nullopt;
122#else
123 std::optional<vec> y = std::nullopt;
124 std::optional<vec> Σ = std::nullopt;
125#endif
126
129 mutable vec HqK;
130 mutable vec work_n;
131 mutable vec work_n2;
132 mutable vec work_m;
133
135 crindexvec J) const;
136
137 public:
139};
140
141// clang-format off
146// clang-format on
147
148} // namespace alpaqa
LBFGSParams< config_t > Params
Definition lbfgs.hpp:121
const Params & get_params() const
Get the parameters.
Definition lbfgs.hpp:177
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:77
#define ALPAQA_IF_QUADF(...)
Definition config.hpp:221
#define ALPAQA_IF_LONGD(...)
Definition config.hpp:233
#define ALPAQA_IF_FLOAT(...)
Definition config.hpp:227
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
Definition export.hpp:21
typename Conf::indexvec indexvec
Definition config.hpp:105
typename Conf::real_t real_t
Definition config.hpp:86
constexpr const auto inf
Definition config.hpp:112
typename Conf::rvec rvec
Definition config.hpp:91
typename Conf::crvec crvec
Definition config.hpp:92
typename Conf::vec vec
Definition config.hpp:88
typename Conf::crindexvec crindexvec
Definition config.hpp:107
Double-precision double configuration.
Definition config.hpp:174
Single-precision float configuration.
Definition config.hpp:170
long double configuration.
Definition config.hpp:179
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