16#include <Eigen/Cholesky>
17#include <Eigen/Eigenvalues>
44template <Config Conf = DefaultConfig>
65 [[maybe_unused]]
real_t γ_0, [[maybe_unused]]
crvec x_0,
66 [[maybe_unused]]
crvec x̂_0, [[maybe_unused]]
crvec p_0,
67 [[maybe_unused]]
crvec grad_ψx_0) {
69 throw std::invalid_argument(
70 "Structured Newton only supports box-constrained problems");
73 throw std::invalid_argument(
"Structured Newton requires hess_ψ");
88 mvec null{
nullptr, 0};
90 throw std::logic_error(
"Sparse hessians not yet implemented");
99 [[maybe_unused]]
crvec xₖ, [[maybe_unused]]
crvec xₙₑₓₜ,
100 [[maybe_unused]]
crvec pₖ, [[maybe_unused]]
crvec pₙₑₓₜ,
101 [[maybe_unused]]
crvec grad_ψxₖ,
102 [[maybe_unused]]
crvec grad_ψxₙₑₓₜ) {
115 for (
index_t i = 0; i < n; ++i) {
116 real_t gd = xₖ(i) - γₖ * grad_ψxₖ(i);
117 if (gd <= C.lowerbound(i)) {
119 }
else if (C.upperbound(i) <= gd) {
123 qₖ(i) = -grad_ψxₖ(i);
146 Eigen::SelfAdjointEigenSolver<mat> eig{H,
147 Eigen::ComputeEigenvectors};
149 auto λ_min = eig.eigenvalues().minCoeff(),
150 λ_max = eig.eigenvalues().maxCoeff();
158 qₖ = eig.eigenvectors().transpose() * qₖ;
159 qₖ = eig.eigenvalues().cwiseMax(ε).asDiagonal().inverse() * qₖ;
160 qₖ = eig.eigenvectors() * qₖ;
171 qₖ(J).noalias() -= H(J, K) * qₖ(K);
178 HJ.template triangularView<Eigen::Lower>() =
179 H(J, J).template triangularView<Eigen::Lower>();
184 Eigen::SelfAdjointEigenSolver<mat> eig{HJ, Eigen::ComputeEigenvectors};
186 auto λ_min = eig.eigenvalues().minCoeff(),
187 λ_max = eig.eigenvalues().maxCoeff();
190 std::cout <<
"λ(H_JJ): " <<
float_to_str(λ_min, 3) <<
", "
195 auto qJ = H.col(0).topRows(nJ);
197 qJ = eig.eigenvectors().transpose() * qJ;
198 qJ = eig.eigenvalues().cwiseMax(ε).asDiagonal().inverse() * qJ;
199 qₖ(J) = eig.eigenvectors() * qJ;
212 return "StructuredNewtonDirection<" +
213 std::string(config_t::get_name()) +
'>';
221 std::optional<crvec>
y = std::nullopt;
222 std::optional<crvec>
Σ = std::nullopt;
224 std::optional<vec>
y = std::nullopt;
225 std::optional<vec>
Σ = std::nullopt;
242#ifdef ALPAQA_WITH_QUAD_PRECISION
257#ifdef ALPAQA_WITH_QUAD_PRECISION
void eval_hess_ψ(crvec x, crvec y, crvec Σ, real_t scale, rindexvec inner_idx, rindexvec outer_ptr, rvec H_values) const
[Optional] Function that evaluates the Hessian of the augmented Lagrangian,
bool provides_get_box_C() const
Returns true if the problem provides an implementation of get_box_C.
length_t get_n() const
[Required] Number of decision variables.
bool provides_eval_hess_ψ() const
Returns true if the problem provides an implementation of eval_hess_ψ.
bool provides_get_box_D() const
Returns true if the problem provides an implementation of get_box_D.
const Box & get_box_C() const
[Optional] Get the rectangular constraint set of the decision variables, .
length_t get_hess_ψ_num_nonzeros() const
[Optional] Function that gets the number of nonzeros of the Hessian of the augmented Lagrangian.
#define USING_ALPAQA_CONFIG(Conf)
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
bool hessian_vec
Set this option to true to include the Hessian-vector product from equation 12b in ,...
typename Conf::indexvec indexvec
real_t min_eig
Minimum eigenvalue of the Hessian, scaled by , enforced by regularization using a multiple of identit...
typename Conf::real_t real_t
typename Conf::rindexvec rindexvec
typename Conf::index_t index_t
typename Conf::length_t length_t
typename Conf::crvec crvec
bool print_eig
Print the minimum and maximum eigenvalue of the Hessian.
std::string float_to_str(F value, int precision)
typename Conf::crindexvec crindexvec
Parameters for the StructuredNewtonDirection class.
Parameters for the StructuredNewtonDirection class.
Double-precision double configuration.
Single-precision float configuration.
long double configuration.
std::string get_name() const
void changed_γ(real_t γₖ, real_t old_γₖ)
StructuredNewtonDirection()=default
const auto & get_params() const
DirectionParams direction_params
DirectionParams direction
StructuredNewtonDirection(const AcceleratorParams ¶ms, const DirectionParams &directionparams={})
bool update(real_t γₖ, real_t γₙₑₓₜ, crvec xₖ, crvec xₙₑₓₜ, crvec pₖ, crvec pₙₑₓₜ, crvec grad_ψxₖ, crvec grad_ψxₙₑₓₜ)
StructuredNewtonDirection(const Params ¶ms)
AcceleratorParams reg_params
void initialize(const Problem &problem, crvec y, crvec Σ, real_t γ_0, crvec x_0, crvec x̂_0, crvec p_0, crvec grad_ψx_0)
bool apply(real_t γₖ, crvec xₖ, crvec x̂ₖ, crvec pₖ, crvec grad_ψxₖ, rvec qₖ) const
bool has_initial_direction() const
AcceleratorParams accelerator
static void compute_complement(std::span< const index_t > in, std::span< index_t > out)