16#include <Eigen/Cholesky>
17#include <Eigen/Eigenvalues>
45template <Config Conf = DefaultConfig>
66 [[maybe_unused]]
real_t γ_0, [[maybe_unused]]
crvec x_0,
67 [[maybe_unused]]
crvec x̂_0, [[maybe_unused]]
crvec p_0,
68 [[maybe_unused]]
crvec grad_ψx_0) {
70 throw std::invalid_argument(
71 "Structured Newton only supports box-constrained problems");
74 throw std::invalid_argument(
"Structured Newton requires hess_ψ");
89 mvec null{
nullptr, 0};
91 throw std::logic_error(
"Sparse hessians not yet implemented");
100 [[maybe_unused]]
crvec xₖ, [[maybe_unused]]
crvec xₙₑₓₜ,
101 [[maybe_unused]]
crvec pₖ, [[maybe_unused]]
crvec pₙₑₓₜ,
102 [[maybe_unused]]
crvec grad_ψxₖ,
103 [[maybe_unused]]
crvec grad_ψxₙₑₓₜ) {
116 for (
index_t i = 0; i < n; ++i) {
117 real_t gd = xₖ(i) - γₖ * grad_ψxₖ(i);
118 if (gd <= C.lowerbound(i)) {
120 }
else if (C.upperbound(i) <= gd) {
124 qₖ(i) = -grad_ψxₖ(i);
147 Eigen::SelfAdjointEigenSolver<mat> eig{H,
148 Eigen::ComputeEigenvectors};
150 auto λ_min = eig.eigenvalues().minCoeff(),
151 λ_max = eig.eigenvalues().maxCoeff();
159 qₖ = eig.eigenvectors().transpose() * qₖ;
160 qₖ = eig.eigenvalues().cwiseMax(ε).asDiagonal().inverse() * qₖ;
161 qₖ = eig.eigenvectors() * qₖ;
180 HJ.template triangularView<Eigen::Lower>() =
181 H(J, J).template triangularView<Eigen::Lower>();
186 Eigen::SelfAdjointEigenSolver<mat> eig{HJ, Eigen::ComputeEigenvectors};
188 auto λ_min = eig.eigenvalues().minCoeff(),
189 λ_max = eig.eigenvalues().maxCoeff();
192 std::cout <<
"λ(H_JJ): " <<
float_to_str(λ_min, 3) <<
", "
197 auto qJ = H.col(0).topRows(nJ);
199 qJ = eig.eigenvectors().transpose() * qJ;
200 qJ = eig.eigenvalues().cwiseMax(ε).asDiagonal().inverse() * qJ;
201 qₖ(J) = eig.eigenvectors() * qJ;
214 return "StructuredNewtonDirection<" +
215 std::string(config_t::get_name()) +
'>';
223 std::optional<crvec>
y = std::nullopt;
224 std::optional<crvec>
Σ = std::nullopt;
226 std::optional<vec>
y = std::nullopt;
227 std::optional<vec>
Σ = std::nullopt;
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_IF_QUADF(...)
#define ALPAQA_IF_LONGD(...)
#define ALPAQA_IF_FLOAT(...)
#define ALPAQA_EXPORT_EXTERN_TEMPLATE(...)
real_t hessian_vec_factor
Set this option to a nonzero value 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)