31 std::sqrt(std::numeric_limits<real_t>::epsilon());
58 [[maybe_unused]]
crvec x_0, [[maybe_unused]]
crvec x̂_0,
59 [[maybe_unused]]
crvec p_0,
60 [[maybe_unused]]
crvec grad_ψx_0) {
62 !
problem.provides_eval_augmented_lagrangian_hessian_product() &&
63 !(
problem.provides_eval_lagrangian_hessian_product() &&
64 problem.get_num_constraints() == 0))
65 throw std::invalid_argument(
66 "NewtonTR without finite differences requires "
67 "Problem::eval_augmented_lagrangian_hessian_product()");
68 if (!
problem.provides_eval_inactive_indices_res_lna())
69 throw std::invalid_argument(
71 "Problem::eval_inactive_indices_res_lna()");
77 const auto n =
problem.get_num_variables(),
78 m =
problem.get_num_constraints();
96 [[maybe_unused]]
crvec xₖ, [[maybe_unused]]
crvec xₙₑₓₜ,
97 [[maybe_unused]]
crvec pₖ, [[maybe_unused]]
crvec pₙₑₓₜ,
98 [[maybe_unused]]
crvec grad_ψxₖ,
99 [[maybe_unused]]
crvec grad_ψxₙₑₓₜ) {
109 if (!std::isfinite(radius))
110 throw std::logic_error(
"Invalid trust radius");
111 if (radius < std::numeric_limits<real_t>::epsilon())
112 throw std::logic_error(
"Trust radius too small");
117 const auto n =
problem->get_num_variables();
119 problem->eval_inactive_indices_res_lna(γₖ, xₖ, grad_ψxₖ,
JK_sto);
123 auto rJ =
rJ_sto.topRows(nJ);
124 auto qJ =
qJ_sto.topRows(nJ);
125 rJ = (-
real_t(1) / γₖ) * pₖ(J);
128 real_t norm_qK_sq = pₖ(K).squaredNorm();
137 problem->eval_augmented_lagrangian_gradient(
139 rJ.noalias() += (
work_2 - grad_ψxₖ)(J) *
142 problem->eval_augmented_lagrangian_hessian_product(xₖ, *
y, *
Σ,
149 auto hess_vec_mult = [&](
crvec p,
rvec Bp) {
156 problem->eval_augmented_lagrangian_gradient(
158 Bp.topRows(nJ) = (
work_2 - grad_ψxₖ)(J) / ε;
162 problem->eval_augmented_lagrangian_hessian_product(
164 Bp.topRows(nJ) =
work_2(J);
171 return qJ_model - norm_qK_sq / (2 * γₖ);
183 return "NewtonTRDirection<" + std::string(config_t::get_name()) +
'>';
194 std::optional<crvec>
y = std::nullopt;
195 std::optional<crvec>
Σ = std::nullopt;
197 std::optional<vec>
y = std::nullopt;
198 std::optional<vec>
Σ = std::nullopt;
The main polymorphic minimization problem interface.
#define USING_ALPAQA_CONFIG(Conf)
real_t hessian_vec_factor
real_t finite_diff_stepsize
Parameters for the NewtonTRDirection class.
Parameters for SteihaugCG.
typename Conf::indexvec indexvec
typename Conf::real_t real_t
typename Conf::rindexvec rindexvec
typename Conf::index_t index_t
typename Conf::crvec crvec
typename Conf::crindexvec crindexvec
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)
SteihaugCGParams< config_t > AcceleratorParams
bool has_initial_direction() const
AcceleratorParams accelerator
NewtonTRDirectionParams< config_t > DirectionParams
TypeErasedProblem< config_t > Problem
Steihaug conjugate gradients procedure based on https://github.com/scipy/scipy/blob/583e70a50573169fc...
static void compute_complement(std::span< const index_t > in, std::span< index_t > out)