5 #include "../ScalarTraits.hpp" 6 #include "../Types.hpp" 7 #include "DefineOutputMacros.hpp" 8 #include "ProblemTraits.hpp" 9 #include "SubspaceUtils.hpp" 14 namespace Implementation {
22 template<
typename Problem,
typename Scalar,
typename Storage>
27 "Problem must provide lower bounds function: Vector<Scalar> lower_bounds()");
31 "Problem must provide upper bounds function: Vector<Scalar> upper_bounds()");
94 template<
typename OutputFunction>
100 const Scalar& check_epsilon,
101 const Scalar& machine_epsilon,
102 OutputFunction& output_function);
105 template<
typename Problem,
typename Scalar,
typename Storage>
108 return (problem.lower_bounds().array() <= problem.upper_bounds().array()).all();
111 template<
typename Problem,
typename Scalar,
typename Storage>
118 auto lb = problem.lower_bounds();
119 auto ub = problem.upper_bounds();
122 r.array() = x.array().max(lb.array()).min(ub.array());
127 template<
typename Problem,
typename Scalar,
typename Storage>
134 return projected_gradient_norm(x, g, problem.lower_bounds(), problem.upper_bounds());
137 template<
typename Problem,
typename Scalar,
typename Storage>
148 for (Eigen::Index i = 0; i < p.size(); ++i) {
149 const Scalar& pi = p(i);
151 if (pi < Scalar{0}) {
152 Scalar lower_dist = lower_bounds(i) - x(i);
154 if (lower_dist >= Scalar{0}) {
155 alpha_max = Scalar{0};
157 else if (pi * alpha_max < lower_dist) {
158 alpha_max = lower_dist / pi;
161 else if (pi > Scalar{0}) {
162 Scalar upper_dist = upper_bounds(i) - x(i);
164 if (upper_dist <= Scalar{0}) {
165 alpha_max = Scalar{0};
167 else if (pi * alpha_max > upper_dist) {
168 alpha_max = upper_dist / pi;
180 for (Eigen::Index i = 0; i < p.size(); ++i) {
181 const Scalar& pi = p(i);
182 if (pi < Scalar{0}) {
183 if (x(i) + alpha_max * p(i) < lower_bounds(i)) {
184 alpha_max /= Scalar{2};
187 else if (pi > Scalar{0}) {
188 if (x(i) + alpha_max * p(i) > upper_bounds(i)) {
189 alpha_max /= Scalar{2};
197 template<
typename Problem,
typename Scalar,
typename Storage>
198 template<
typename OutputFunction>
204 const Scalar& check_epsilon,
205 const Scalar& machine_epsilon,
206 OutputFunction& output_function)
210 problem.lower_bounds(), problem.upper_bounds(), machine_epsilon);
213 problem.lower_bounds(), problem.upper_bounds(), check_epsilon);
223 "Detected numerical instability during subspace minimization!");
decltype(upper_bound_probe(*dummy_problem)) upper_bound_type
return type of the upper_bounds function; void if not provided
Definition: ProblemTraits.hpp:91
Traits for scalar values.
Definition: ScalarTraits.hpp:16
static Scalar max_step_length(Problem &problem, const Vector< Scalar > &x, const Vector< Scalar > &p)
Calculate the maximum allowed step length.
Definition: BoxConstrainedAlgorithm.hpp:138
static Vector< Scalar > search_direction(Problem &problem, Storage &storage, const Vector< Scalar > &x, const Vector< Scalar > &g, const Scalar &check_epsilon, const Scalar &machine_epsilon, OutputFunction &output_function)
Calculate the new search direction.
Definition: BoxConstrainedAlgorithm.hpp:199
Generic implementation of box constrained quasi-Newton algorithms.
Definition: BoxConstrainedAlgorithm.hpp:23
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Vector type used.
Definition: Types.hpp:15
static Scalar gradient_norm(Problem &problem, const Vector< Scalar > &x, const Vector< Scalar > &g)
Calculate the projected gradient norm ( norm)
Definition: BoxConstrainedAlgorithm.hpp:128
Traits for the problem.
Definition: ProblemTraits.hpp:31
BFGS optimizations.
Definition: BFGS.hpp:24
static Vector< Scalar > truncate_x(Problem &problem, const Vector< Scalar > &x)
Truncate vector such that it fulfills the box constraints.
Definition: BoxConstrainedAlgorithm.hpp:112
static bool check_bounds(Problem &problem)
Verify that the bounds are correct.
Definition: BoxConstrainedAlgorithm.hpp:106
decltype(lower_bound_probe(*dummy_problem)) lower_bound_type
return type of the lower_bounds function; void if not provided
Definition: ProblemTraits.hpp:84