22 std::sqrt(std::numeric_limits<real_t>::epsilon());
49 [[maybe_unused]]
crvec x_0, [[maybe_unused]]
crvec x̂_0,
50 [[maybe_unused]]
crvec p_0,
51 [[maybe_unused]]
crvec grad_ψx_0) {
54 throw std::invalid_argument(
"NewtonTR without finite differences "
55 "requires Problem::eval_hess_ψ_prod()");
57 throw std::invalid_argument(
59 "Problem::eval_inactive_indices_res_lna()");
83 [[maybe_unused]]
crvec xₖ, [[maybe_unused]]
crvec xₙₑₓₜ,
84 [[maybe_unused]]
crvec pₖ, [[maybe_unused]]
crvec pₙₑₓₜ,
85 [[maybe_unused]]
crvec grad_ψxₖ,
86 [[maybe_unused]]
crvec grad_ψxₙₑₓₜ) {
96 if (!std::isfinite(radius))
97 throw std::logic_error(
"Invalid trust radius");
98 if (radius < std::numeric_limits<real_t>::epsilon())
99 throw std::logic_error(
"Trust radius too small");
107 auto J =
JK_sto.topRows(nJ);
108 auto K =
JK_sto.bottomRows(n - nJ);
110 auto rJ =
rJ_sto.topRows(nJ);
111 auto qJ =
qJ_sto.topRows(nJ);
112 rJ = (-
real_t(1) / γₖ) * pₖ(J);
115 real_t norm_qK_sq = pₖ(K).squaredNorm();
120 real_t ε = (1 + grad_ψxₖ.norm()) *
125 rJ.noalias() += (
work_2 - grad_ψxₖ)(J) *
134 auto hess_vec_mult = [&](
crvec p,
rvec Bp) {
136 real_t ε = (1 + grad_ψxₖ.norm()) *
142 Bp.topRows(nJ) = (
work_2 - grad_ψxₖ)(J) / ε;
147 Bp.topRows(nJ) =
work_2(J);
154 return qJ_model - norm_qK_sq / (2 * γₖ);
160 throw std::invalid_argument(
"NewtonTRDirection does not support "
161 "rescale_on_step_size_changes");
169 return "NewtonTRDirection<" + std::string(config_t::get_name()) +
'>';
180 std::optional<crvec>
y = std::nullopt;
181 std::optional<crvec>
Σ = std::nullopt;
183 std::optional<vec>
y = std::nullopt;
184 std::optional<vec>
Σ = std::nullopt;
bool provides_eval_hess_ψ_prod() const
Returns true if the problem provides an implementation of eval_hess_ψ_prod.
length_t get_n() const
[Required] Number of decision variables.
length_t get_m() const
[Required] Number of constraints.
bool provides_eval_inactive_indices_res_lna() const
Returns true if the problem provides an implementation of eval_inactive_indices_res_lna.
index_t eval_inactive_indices_res_lna(real_t γ, crvec x, crvec grad_ψ, rindexvec J) const
[Optional] Function that computes the inactive indices for the evaluation of the linear Newton appro...
void eval_grad_ψ(crvec x, crvec y, crvec Σ, rvec grad_ψ, rvec work_n, rvec work_m) const
[Optional] Calculate the gradient ∇ψ(x).
void eval_hess_ψ_prod(crvec x, crvec y, crvec Σ, real_t scale, crvec v, rvec Hv) const
[Optional] Function that evaluates the Hessian of the augmented Lagrangian multiplied by a vector,
#define USING_ALPAQA_CONFIG(Conf)
real_t hessian_vec_factor
typename Conf::indexvec indexvec
typename Conf::real_t real_t
typename Conf::index_t index_t
bool rescale_on_step_size_changes
real_t finite_diff_stepsize
typename Conf::crvec crvec
Parameters for the NewtonTRDirection class.
std::string get_name() const
void changed_γ(real_t γₖ, real_t old_γₖ)
SteihaugCG< config_t > steihaug
real_t apply(real_t γₖ, crvec xₖ, crvec x̂ₖ, crvec pₖ, crvec grad_ψxₖ, real_t radius, rvec qₖ) const
NewtonTRDirection(const Params ¶ms)
NewtonTRDirection(const AcceleratorParams ¶ms, const DirectionParams &directionparams={})
DirectionParams direction_params
DirectionParams direction
bool update(real_t γₖ, real_t γₙₑₓₜ, crvec xₖ, crvec xₙₑₓₜ, crvec pₖ, crvec pₙₑₓₜ, crvec grad_ψxₖ, crvec grad_ψxₙₑₓₜ)
NewtonTRDirection()=default
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 has_initial_direction() const
AcceleratorParams accelerator
Steihaug conjugate gradients procedure based on https://github.com/scipy/scipy/blob/583e70a50573169fc...
real_t solve(const auto &grad, const HessFun &hess_prod, real_t trust_radius, rvec step) const
static void compute_complement(std::span< const index_t > in, std::span< index_t > out)