alpaqa
1.0.0a12
Nonconvex constrained optimization
Loading...
Searching...
No Matches
src
interop
lbfgsb
include
alpaqa
lbfgsb
lbfgsb-adapter.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
alpaqa/config/config.hpp
>
4
#include <
alpaqa/inner/inner-solve-options.hpp
>
5
#include <
alpaqa/inner/internal/panoc-stop-crit.hpp
>
6
#include <
alpaqa/inner/internal/solverstatus.hpp
>
7
#include <alpaqa/lbfgsb-adapter-export.h>
8
#include <
alpaqa/problem/type-erased-problem.hpp
>
9
#include <
alpaqa/util/atomic-stop-signal.hpp
>
10
11
#include <chrono>
12
#include <iostream>
13
14
namespace
alpaqa::lbfgsb
{
15
16
struct
LBFGSB_ADAPTER_EXPORT
LBFGSBParams
{
17
USING_ALPAQA_CONFIG
(
alpaqa::EigenConfigd
);
18
19
unsigned
memory = 10;
20
unsigned
max_iter = 1000;
21
std::chrono::nanoseconds max_time = std::chrono::minutes(5);
22
PANOCStopCrit
stop_crit = PANOCStopCrit::ProjGradUnitNorm;
23
int
print = -1;
24
unsigned
print_interval = 0;
25
int
print_precision = std::numeric_limits<real_t>::max_digits10 / 2;
26
};
27
28
struct
LBFGSB_ADAPTER_EXPORT
LBFGSBStats
{
29
USING_ALPAQA_CONFIG
(
alpaqa::EigenConfigd
);
30
31
SolverStatus
status = SolverStatus::Busy;
32
real_t
ε = inf<config_t>;
33
std::chrono::nanoseconds elapsed_time{};
34
unsigned
iterations = 0;
35
real_t
final_ψ = 0;
36
unsigned
lbfgs_rejected = 0;
37
};
38
39
/// L-BFGS-B solver for ALM.
40
/// @ingroup grp_InnerSolvers
41
class
LBFGSB_ADAPTER_EXPORT
LBFGSBSolver
{
42
public
:
43
USING_ALPAQA_CONFIG
(
alpaqa::EigenConfigd
);
44
45
using
Problem
=
TypeErasedProblem<config_t>
;
46
using
Params
=
LBFGSBParams
;
47
using
Stats
=
LBFGSBStats
;
48
using
SolveOptions
=
InnerSolveOptions<config_t>
;
49
50
LBFGSBSolver
(
const
Params
¶ms) : params(params) {}
51
52
Stats operator()(
const
Problem &problem,
// in
53
const
SolveOptions &opts,
// in
54
rvec
x,
// inout
55
rvec
y,
// inout
56
crvec
Σ,
// in
57
rvec
err_z);
// out
58
59
template
<
class
P>
60
Stats
operator()
(
const
P &problem,
const
SolveOptions
&opts,
rvec
u,
rvec
y,
61
crvec
Σ,
rvec
e) {
62
return
operator()(Problem::template make<P>(problem), opts, u, y, Σ, e);
63
}
64
65
std::string get_name()
const
;
66
67
void
stop
() { stop_signal.stop(); }
68
69
const
Params
&
get_params
()
const
{
return
params; }
70
71
private
:
72
Params
params
;
73
AtomicStopSignal
stop_signal
;
74
75
public
:
76
std::ostream *os = &std::cout;
77
};
78
79
}
// namespace alpaqa::lbfgsb
80
81
namespace
alpaqa
{
82
83
template
<
class
InnerSolverStats>
84
struct
InnerStatsAccumulator
;
85
86
template
<>
87
struct
InnerStatsAccumulator
<lbfgsb::LBFGSBStats> {
88
USING_ALPAQA_CONFIG
(
alpaqa::EigenConfigd
);
89
90
/// Total elapsed time in the inner solver.
91
std::chrono::nanoseconds elapsed_time{};
92
/// Total number of inner PANOC iterations.
93
unsigned
iterations = 0;
94
/// Final value of the smooth cost @f$ \psi(\hat x) @f$.
95
real_t
final_ψ = 0;
96
/// Total number of times that the L-BFGS update was rejected (i.e. it
97
/// could have resulted in a non-positive definite Hessian estimate).
98
unsigned
lbfgs_rejected = 0;
99
};
100
101
inline
InnerStatsAccumulator<lbfgsb::LBFGSBStats>
&
102
operator+=
(
InnerStatsAccumulator<lbfgsb::LBFGSBStats>
&
acc
,
103
const
lbfgsb::LBFGSBStats
&s) {
104
acc
.
iterations
+= s.
iterations
;
105
acc
.elapsed_time += s.
elapsed_time
;
106
acc
.final_ψ = s.
final_ψ
;
107
acc
.lbfgs_rejected += s.
lbfgs_rejected
;
108
return
acc
;
109
}
110
111
}
// namespace alpaqa
atomic-stop-signal.hpp
alpaqa::AtomicStopSignal
Definition
atomic-stop-signal.hpp:7
alpaqa::TypeErasedProblem< config_t >
alpaqa::lbfgsb::LBFGSBSolver
L-BFGS-B solver for ALM.
Definition
lbfgsb-adapter.hpp:41
alpaqa::lbfgsb::LBFGSBSolver::params
Params params
Definition
lbfgsb-adapter.hpp:72
alpaqa::lbfgsb::LBFGSBSolver::operator()
Stats operator()(const P &problem, const SolveOptions &opts, rvec u, rvec y, crvec Σ, rvec e)
Definition
lbfgsb-adapter.hpp:60
alpaqa::lbfgsb::LBFGSBSolver::LBFGSBSolver
LBFGSBSolver(const Params ¶ms)
Definition
lbfgsb-adapter.hpp:50
alpaqa::lbfgsb::LBFGSBSolver::stop_signal
AtomicStopSignal stop_signal
Definition
lbfgsb-adapter.hpp:73
alpaqa::lbfgsb::LBFGSBSolver::stop
void stop()
Definition
lbfgsb-adapter.hpp:67
alpaqa::lbfgsb::LBFGSBSolver::get_params
const Params & get_params() const
Definition
lbfgsb-adapter.hpp:69
config.hpp
USING_ALPAQA_CONFIG
#define USING_ALPAQA_CONFIG(Conf)
Definition
config.hpp:56
inner-solve-options.hpp
alpaqa::lbfgsb
Definition
lbfgsb-adapter.hpp:14
alpaqa::lbfgsb::LBFGSBStats::lbfgs_rejected
unsigned lbfgs_rejected
Definition
lbfgsb-adapter.hpp:36
alpaqa::lbfgsb::LBFGSBStats::elapsed_time
std::chrono::nanoseconds elapsed_time
Definition
lbfgsb-adapter.hpp:33
alpaqa::lbfgsb::LBFGSBStats::final_ψ
real_t final_ψ
Definition
lbfgsb-adapter.hpp:35
alpaqa::lbfgsb::LBFGSBStats::iterations
unsigned iterations
Definition
lbfgsb-adapter.hpp:34
alpaqa::lbfgsb::LBFGSBParams
Definition
lbfgsb-adapter.hpp:16
alpaqa::lbfgsb::LBFGSBStats
Definition
lbfgsb-adapter.hpp:28
alpaqa
Definition
anderson.hpp:10
alpaqa::PANOCStopCrit
PANOCStopCrit
Definition
panoc-stop-crit.hpp:8
alpaqa::operator+=
InnerStatsAccumulator< PANOCOCPStats< Conf > > & operator+=(InnerStatsAccumulator< PANOCOCPStats< Conf > > &acc, const PANOCOCPStats< Conf > &s)
Definition
panoc-ocp.hpp:255
alpaqa::SolverStatus
SolverStatus
Exit status of a numerical solver such as ALM or PANOC.
Definition
solverstatus.hpp:11
alpaqa::real_t
typename Conf::real_t real_t
Definition
config.hpp:65
alpaqa::inf
constexpr const auto inf
Definition
config.hpp:85
alpaqa::rvec
typename Conf::rvec rvec
Definition
config.hpp:69
alpaqa::crvec
typename Conf::crvec crvec
Definition
config.hpp:70
alpaqa::InnerStatsAccumulator< PANOCOCPStats< Conf > >::iterations
unsigned iterations
Total number of inner PANOC iterations.
Definition
panoc-ocp.hpp:221
alpaqa::InnerSolveOptions
Definition
inner-solve-options.hpp:11
alpaqa::InnerStatsAccumulator
Definition
panoc.hpp:190
panoc-stop-crit.hpp
solverstatus.hpp
alpaqa::EigenConfigd
Double-precision double configuration.
Definition
config.hpp:135
type-erased-problem.hpp
Generated on Wed Sep 27 2023 for alpaqa by
1.9.8