12#include <Eigen/Cholesky>
16using std::chrono::duration_cast;
17using std::chrono::microseconds;
27 bool always_overwrite_results,
35 auto start_time = std::chrono::steady_clock::now();
59 vec work_n(
n), work_m(
m);
65 using indexvec = std::vector<vec::Index>;
66 using bvec = Eigen::Matrix<bool, Eigen::Dynamic, 1>;
67 bvec inactive_C = bvec::Zero(
n);
76 unsigned no_progress = 0;
105 xₖ, ψₖ, grad_ψₖ,
y,
Σ, x̂ₖ, pₖ, ŷx̂ₖ, ψx̂ₖ, pₖᵀpₖ, grad_ψₖᵀpₖ, Lₖ, γₖ);
109 std::cout <<
"[PANOC] " << std::setw(6) << k
110 <<
": ψ = " << std::setw(13) << ψₖ
111 <<
", ‖∇ψ‖ = " << std::setw(13) << grad_ψₖ.norm()
112 <<
", ‖p‖ = " << std::setw(13) << std::sqrt(pₖᵀpₖ)
113 <<
", γ = " << std::setw(13) << γₖ
114 <<
", εₖ = " << std::setw(13) << εₖ <<
"\r\n";
125 ψₖ, grad_ψₖ, x̂ₖ, grad_̂ψₖ, work_n, work_m);
133 if (not std::isfinite(Lₖ)) {
142 calc_x̂(γₖ, xₖ, grad_ψₖ, x̂ₖ, pₖ);
145 real_t grad_ψₖᵀpₖ = grad_ψₖ.dot(pₖ);
146 real_t pₖᵀpₖ = pₖ.squaredNorm();
159 ψx̂ₖ, pₖᵀpₖ, grad_ψₖᵀpₖ, Lₖ, γₖ);
160 φₖ = ψₖ + 1 / (2 * γₖ) * pₖᵀpₖ + grad_ψₖᵀpₖ;
173 progress_cb({k, xₖ, pₖ, pₖᵀpₖ, x̂ₖ, ψₖ, grad_ψₖ, ψx̂ₖ, grad_̂ψₖ, Lₖ,
176 auto time_elapsed = std::chrono::steady_clock::now() - start_time;
186 always_overwrite_results) {
193 s.
elapsed_time = duration_cast<microseconds>(time_elapsed);
208 for (vec::Index i = 0; i <
n; ++i) {
209 real_t gd_step = xₖ(i) - γₖ * grad_ψₖ(i);
210 if (gd_step <
problem.C.lowerbound(i)) {
212 }
else if (
problem.C.upperbound(i) < gd_step) {
219 bool newton_success =
true;
226 hess_q +=
H(j, k) * qₖ(k);
227 rhs(ri++) = -grad_ψₖ(j) - hess_q;
231 auto hess_Ljj =
H.block(0, 0, J.size(), J.size());
236 hess_Ljj(r,
c) =
H(rj, cj);
241 auto ldl = hess_Ljj.ldlt();
242 if (ldl.isPositive()) {
243 qJ.topRows(J.size()) = ldl.solve(rhs.topRows(J.size()));
245 std::cerr <<
"\x1b[0;31m"
259 real_t σₖγₖ⁻¹pₖᵀpₖ = (1 - γₖ * Lₖ) * pₖᵀpₖ / (2 * γₖ);
260 real_t φₖ₊₁, ψₖ₊₁, ψx̂ₖ₊₁, grad_ψₖ₊₁ᵀpₖ₊₁, pₖ₊₁ᵀpₖ₊₁;
265 if (not newton_success || not qₖ.allFinite()) {
279 grad_ψₖ₊₁.swap(grad_̂ψₖ);
284 xₖ₊₁ = xₖ + (1 - τ) * pₖ + τ * qₖ;
290 calc_x̂(γₖ₊₁, xₖ₊₁, grad_ψₖ₊₁, x̂ₖ₊₁, pₖ₊₁);
295 grad_ψₖ₊₁ᵀpₖ₊₁ = grad_ψₖ₊₁.dot(pₖ₊₁);
296 pₖ₊₁ᵀpₖ₊₁ = pₖ₊₁.squaredNorm();
297 real_t pₖ₊₁ᵀpₖ₊₁_ₖ = pₖ₊₁ᵀpₖ₊₁;
303 ψx̂ₖ₊₁, pₖ₊₁ᵀpₖ₊₁, grad_ψₖ₊₁ᵀpₖ₊₁,
308 φₖ₊₁ = ψₖ₊₁ + 1 / (2 * γₖ₊₁) * pₖ₊₁ᵀpₖ₊₁ + grad_ψₖ₊₁ᵀpₖ₊₁;
310 ls_cond = φₖ₊₁ - (φₖ - σₖγₖ⁻¹pₖᵀpₖ);
312 ls_cond -= (0.5 / γₖ₊₁ - 0.5 / γₖ) * pₖ₊₁ᵀpₖ₊₁_ₖ;
330 no_progress = xₖ == xₖ₊₁ ? no_progress + 1 : 0;
344 grad_ψₖ.swap(grad_ψₖ₊₁);
345 grad_ψₖᵀpₖ = grad_ψₖ₊₁ᵀpₖ₊₁;
348 throw std::logic_error(
"[PANOC] loop error");
std::function< void(const ProgressInfo &)> progress_cb
AtomicStopSignal stop_signal
std::chrono::microseconds elapsed_time
unsigned linesearch_failures
Stats operator()(const Problem &problem, crvec Σ, real_t ε, bool always_overwrite_results, rvec x, rvec y, rvec err_z)
real_t calc_error_stop_crit(const Box &C, PANOCStopCrit crit, crvec pₖ, real_t γ, crvec xₖ, crvec x̂ₖ, crvec ŷₖ, crvec grad_ψₖ, crvec grad_̂ψₖ)
Compute the ε from the stopping criterion, see PANOCStopCrit.
SolverStatus check_all_stop_conditions(const ParamsT ¶ms, DurationT time_elapsed, unsigned iteration, const AtomicStopSignal &stop_signal, real_t ε, real_t εₖ, unsigned no_progress)
Check all stop conditions (required tolerance reached, out of time, maximum number of iterations exce...
real_t calc_ψ_ŷ(const Problem &p, crvec x, crvec y, crvec Σ, rvec ŷ)
Calculate both ψ(x) and the vector ŷ that can later be used to compute ∇ψ.
real_t descent_lemma(const Problem &problem, real_t rounding_tolerance, real_t L_max, crvec xₖ, real_t ψₖ, crvec grad_ψₖ, crvec y, crvec Σ, rvec x̂ₖ, rvec pₖ, rvec ŷx̂ₖ, real_t &ψx̂ₖ, real_t &norm_sq_pₖ, real_t &grad_ψₖᵀpₖ, real_t &Lₖ, real_t &γₖ)
Increase the estimate of the Lipschitz constant of the objective gradient and decrease the step size ...
void calc_augmented_lagrangian_hessian(const Problem &problem, crvec xₖ, crvec ŷxₖ, crvec y, crvec Σ, rvec g, mat &H, rvec work_n)
Compute the Hessian matrix of the augmented Lagrangian function.
real_t calc_ψ_grad_ψ(const Problem &p, crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m)
Calculate both ψ(x) and its gradient ∇ψ(x).
void calc_err_z(const Problem &p, crvec x̂, crvec y, crvec Σ, rvec err_z)
Calculate the error between ẑ and g(x).
real_t initial_lipschitz_estimate(const Problem &problem, crvec xₖ, crvec y, crvec Σ, real_t ε, real_t δ, real_t L_min, real_t L_max, real_t &ψ, rvec grad_ψ, rvec work_n1, rvec work_n2, rvec work_n3, rvec work_m)
Estimate the Lipschitz constant of the gradient using finite differences.
void calc_grad_ψ_from_ŷ(const Problem &p, crvec x, crvec ŷ, rvec grad_ψ, rvec work_n)
Calculate ∇ψ(x) using ŷ.
void calc_x̂(const Problem &prob, real_t γ, crvec x, crvec grad_ψ, rvec x̂, rvec p)
void print_progress(unsigned k, real_t ψₖ, crvec grad_ψₖ, real_t pₖᵀpₖ, real_t γₖ, real_t εₖ)
LipschitzEstimateParams Lipschitz
Parameters related to the Lipschitz constant estimate and step size.
real_t Lγ_factor
Factor that relates step size γ and Lipschitz constant.
bool alternative_linesearch_cond
Eigen::Ref< const vec > crvec
Default type for immutable references to vectors.
real_t δ
Minimum step size for initial finite difference Lipschitz estimate.
bool update_lipschitz_in_linesearch
unsigned max_no_progress
Maximum number of iterations without any progress before giving up.
real_t L_max
Maximum Lipschitz constant estimate.
@ Interrupted
Solver was interrupted by the user.
@ Converged
Converged and reached given tolerance.
@ NotFinite
Intermediate results were infinite or not-a-number.
realmat mat
Default type for matrices.
realvec vec
Default type for vectors.
real_t ε
Relative step size for initial finite difference Lipschitz estimate.
real_t L₀
Initial estimate of the Lipschitz constant of ∇ψ(x)
real_t quadratic_upperbound_tolerance_factor
double real_t
Default floating point type.
unsigned print_interval
When to print progress.
real_t τ_min
Minimum weight factor between Newton step and projected gradient step.
real_t L_min
Minimum Lipschitz constant estimate.
unsigned max_iter
Maximum number of inner PANOC iterations.
PANOCStopCrit stop_crit
What stopping criterion to use.
Eigen::Ref< vec > rvec
Default type for mutable references to vectors.
Problem description for minimization problems.