PANOC-ALM  quadratic-penalty
Nonconvex constrained optimization
decl/specialized-lbfgs.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 namespace pa {
6 
11  public:
13 
16  resize(n, history);
17  }
18 
20  bool standard_update(crvec xₖ, crvec xₖ₊₁, crvec pₖ,
21  crvec pₖ₊₁, crvec gradₖ₊₁);
23  bool full_update(crvec xₖ, crvec xₖ₊₁, crvec pₖ_old_γ,
24  crvec pₖ₊₁, crvec gradₖ₊₁, const Box &C,
25  real_t γ);
28  bool update(crvec xₖ, crvec xₖ₊₁, crvec pₖ, crvec pₖ₊₁,
29  crvec gradₖ₊₁, const Box &C, real_t γ);
30 
32  template <class Vec>
33  void apply(Vec &&q);
34 
36  void initialize(crvec x₀, crvec grad₀);
37 
39  void reset();
41  void resize(size_t n, size_t history);
42 
43  std::string get_name() const { return "SpecializedLBFGS"; }
44 
46  size_t n() const { return sto.rows() - 1; }
48  size_t history() const { return (sto.cols() - 2) / 4; }
51  size_t succ(size_t i) const { return i + 1 < history() ? i + 1 : 0; }
54  size_t pred(size_t i) const { return i == 0 ? history() - 1 : i - 1; }
55 
56  auto s(size_t i) { return sto.col(2 * i).topRows(n()); }
57  auto s(size_t i) const { return sto.col(2 * i).topRows(n()); }
58  auto y(size_t i) { return sto.col(2 * i + 1).topRows(n()); }
59  auto y(size_t i) const { return sto.col(2 * i + 1).topRows(n()); }
60  auto x(size_t i) { return sto.col(2 * history() + 2 * i).topRows(n()); }
61  auto x(size_t i) const {
62  return sto.col(2 * history() + 2 * i).topRows(n());
63  }
64  auto g(size_t i) { return sto.col(2 * history() + 2 * i + 1).topRows(n()); }
65  auto g(size_t i) const {
66  return sto.col(2 * history() + 2 * i + 1).topRows(n());
67  }
68  auto p() { return sto.col(4 * history()).topRows(n()); }
69  auto p() const { return sto.col(4 * history()).topRows(n()); }
70  auto w() { return sto.col(4 * history() + 1).topRows(n()); }
71  auto w() const { return sto.col(4 * history() + 1).topRows(n()); }
72  real_t &ρ(size_t i) { return sto.coeffRef(n(), 2 * i); }
73  const real_t &ρ(size_t i) const { return sto.coeff(n(), 2 * i); }
74  real_t &α(size_t i) { return sto.coeffRef(n(), 2 * i + 1); }
75  const real_t &α(size_t i) const { return sto.coeff(n(), 2 * i + 1); }
76 
77  private:
78  using storage_t = Eigen::Matrix<real_t, Eigen::Dynamic, Eigen::Dynamic>;
79 
81  size_t idx = 0;
82  bool full = false;
85 };
86 
87 } // namespace pa
pa::SpecializedLBFGS::idx
size_t idx
Definition: decl/specialized-lbfgs.hpp:81
pa::SpecializedLBFGS::get_name
std::string get_name() const
Definition: decl/specialized-lbfgs.hpp:43
lbfgs.hpp
pa::SpecializedLBFGS::ρ
real_t & ρ(size_t i)
Definition: decl/specialized-lbfgs.hpp:72
pa::SpecializedLBFGS::α
const real_t & α(size_t i) const
Definition: decl/specialized-lbfgs.hpp:75
pa::SpecializedLBFGS::resize
void resize(size_t n, size_t history)
Re-allocate storage for a problem with a different size.
Definition: specialized-lbfgs.hpp:135
pa::SpecializedLBFGS::y
auto y(size_t i) const
Definition: decl/specialized-lbfgs.hpp:59
pa::SpecializedLBFGS::α
real_t & α(size_t i)
Definition: decl/specialized-lbfgs.hpp:74
pa::SpecializedLBFGS::history
size_t history() const
Get the number of previous vectors s, y, x and g stored in the buffer.
Definition: decl/specialized-lbfgs.hpp:48
pa::SpecializedLBFGS::initialize
void initialize(crvec x₀, crvec grad₀)
Initialize with the starting point x₀ and the gradient in that point.
Definition: specialized-lbfgs.hpp:11
pa::SpecializedLBFGS::x
auto x(size_t i) const
Definition: decl/specialized-lbfgs.hpp:61
pa::SpecializedLBFGS::storage_t
Eigen::Matrix< real_t, Eigen::Dynamic, Eigen::Dynamic > storage_t
Definition: decl/specialized-lbfgs.hpp:78
pa::SpecializedLBFGS::SpecializedLBFGS
SpecializedLBFGS(Params params, size_t n, size_t history)
Definition: decl/specialized-lbfgs.hpp:15
pa
Definition: alm.hpp:10
pa::SpecializedLBFGS::w
auto w() const
Definition: decl/specialized-lbfgs.hpp:71
pa::SpecializedLBFGS::pred
size_t pred(size_t i) const
Get the previous index in the circular buffer of previous s, y, x and g vectors.
Definition: decl/specialized-lbfgs.hpp:54
pa::SpecializedLBFGS::succ
size_t succ(size_t i) const
Get the next index in the circular buffer of previous s, y, x and g vectors.
Definition: decl/specialized-lbfgs.hpp:51
pa::SpecializedLBFGS::x
auto x(size_t i)
Definition: decl/specialized-lbfgs.hpp:60
pa::SpecializedLBFGS::s
auto s(size_t i)
Definition: decl/specialized-lbfgs.hpp:56
pa::Box
Definition: box.hpp:7
pa::SpecializedLBFGS::SpecializedLBFGS
SpecializedLBFGS(Params params)
Definition: decl/specialized-lbfgs.hpp:14
pa::SpecializedLBFGS::s
auto s(size_t i) const
Definition: decl/specialized-lbfgs.hpp:57
pa::SpecializedLBFGS::g
auto g(size_t i) const
Definition: decl/specialized-lbfgs.hpp:65
pa::SpecializedLBFGS::sto
storage_t sto
Definition: decl/specialized-lbfgs.hpp:80
pa::crvec
Eigen::Ref< const vec > crvec
Default type for immutable references to vectors.
Definition: vec.hpp:18
pa::SpecializedLBFGS::p
auto p() const
Definition: decl/specialized-lbfgs.hpp:69
pa::LBFGSParams
Parameters for the LBFGS and SpecializedLBFGS classes.
Definition: decl/lbfgs.hpp:12
pa::SpecializedLBFGS::p
auto p()
Definition: decl/specialized-lbfgs.hpp:68
pa::SpecializedLBFGS::g
auto g(size_t i)
Definition: decl/specialized-lbfgs.hpp:64
panocpy.test.C
C
Definition: test.py:204
pa::SpecializedLBFGS
Limited memory Broyden–Fletcher–Goldfarb–Shanno (L-BFGS) algorithm that can handle updates of the γ p...
Definition: decl/specialized-lbfgs.hpp:10
pa::SpecializedLBFGS::apply
void apply(Vec &&q)
Apply the inverse Hessian approximation to the given vector q.
Definition: specialized-lbfgs.hpp:109
pa::SpecializedLBFGS::w
auto w()
Definition: decl/specialized-lbfgs.hpp:70
pa::SpecializedLBFGS::reset
void reset()
Throw away the approximation and all previous vectors s and y.
Definition: specialized-lbfgs.hpp:142
pa::SpecializedLBFGS::old_γ
real_t old_γ
Definition: decl/specialized-lbfgs.hpp:83
pa::SpecializedLBFGS::y
auto y(size_t i)
Definition: decl/specialized-lbfgs.hpp:58
pa::SpecializedLBFGS::full
bool full
Definition: decl/specialized-lbfgs.hpp:82
pa::SpecializedLBFGS::update
bool update(crvec xₖ, crvec xₖ₊₁, crvec pₖ, crvec pₖ₊₁, crvec gradₖ₊₁, const Box &C, real_t γ)
Update the inverse Hessian approximation using the new vectors xₖ₊₁ and pₖ₊₁.
Definition: specialized-lbfgs.hpp:97
pa::SpecializedLBFGS::full_update
bool full_update(crvec xₖ, crvec xₖ₊₁, crvec pₖ_old_γ, crvec pₖ₊₁, crvec gradₖ₊₁, const Box &C, real_t γ)
L-BFGS update when changing the step size γ, recomputing everything.
Definition: specialized-lbfgs.hpp:50
pa::SpecializedLBFGS::n
size_t n() const
Get the size of the s, y, x and g vectors in the buffer.
Definition: decl/specialized-lbfgs.hpp:46
pa::real_t
double real_t
Default floating point type.
Definition: vec.hpp:8
pa::SpecializedLBFGS::params
Params params
Definition: decl/specialized-lbfgs.hpp:84
pa::SpecializedLBFGS::ρ
const real_t & ρ(size_t i) const
Definition: decl/specialized-lbfgs.hpp:73
pa::SpecializedLBFGS::standard_update
bool standard_update(crvec xₖ, crvec xₖ₊₁, crvec pₖ, crvec pₖ₊₁, crvec gradₖ₊₁)
Standard L-BFGS update without changing the step size γ.
Definition: specialized-lbfgs.hpp:19