5 #include "../Types.hpp" 6 #include "../ScalarTraits.hpp" 11 namespace Implementation {
17 using type =
typename std::remove_cv<typename std::remove_reference<T>::type>
::type;
30 template<
typename Problem,
typename Scalar>
33 static constexpr Problem*
const dummy_problem =
nullptr;
36 static auto value_probe(U& u) -> decltype(u.value(*dummy_vec));
37 static void value_probe(...);
40 static auto gradient_probe(U& u) -> decltype(u.gradient(*dummy_vec));
41 static void gradient_probe(...);
44 static auto lower_bound_probe(U& u) -> decltype(u.lower_bounds());
45 static void lower_bound_probe(...);
48 static auto upper_bound_probe(U& u) -> decltype(u.upper_bounds());
49 static void upper_bound_probe(...);
52 static auto initial_step_length_probe(U& u)
53 -> decltype(u.initial_step_length(*dummy_vec, *dummy_vec));
54 static void initial_step_length_probe(...);
57 static auto change_acceptable_probe(U& u)
58 -> decltype(u.change_acceptable(*dummy_vec, *dummy_vec));
59 static void change_acceptable_probe(...);
62 static auto is_check_acceptable_first_probe(U& u) -> decltype(u.is_check_acceptable_first());
63 static void is_check_acceptable_first_probe(...);
66 static auto reparameterize_probe(U& u) -> decltype(u.reparameterize(*dummy_vec, *dummy_vec));
67 static void reparameterize_probe(...);
71 using value_type = decltype(value_probe(*dummy_problem));
73 static constexpr
const bool has_value
74 = std::is_same<Scalar, typename remove_cvref<value_type>::type>::value;
79 static constexpr
const bool has_gradient
80 = std::is_same<Vector<Scalar>,
86 static constexpr
const bool has_lower_bound
87 = std::is_same<Vector<Scalar>,
93 static constexpr
const bool has_upper_bound
94 = std::is_same<Vector<Scalar>,
100 static constexpr
const bool has_initial_step_length
101 = std::is_same<Scalar,
107 static constexpr
const bool has_change_acceptable
108 = std::is_same<Scalar,
114 static constexpr
const bool has_is_check_acceptable_first
121 static constexpr
const bool has_reparameterize
126 template<
typename Problem,
typename Scalar>
144 "Problem must provide initial step length function: Scalar initial_step_length(...)");
146 return problem.initial_step_length(x, p);
162 "Problem must provide change acceptable function: Scalar change_acceptable(...)");
164 return problem.change_acceptable(x0, x);
175 return _is_check_acceptable_first(problem);
181 typename std::enable_if<!problem_traits<U, Scalar>::has_is_check_acceptable_first,
183 static constexpr
bool _is_check_acceptable_first(
190 typename std::enable_if<problem_traits<U, Scalar>::has_is_check_acceptable_first,
191 void>::type* =
nullptr>
192 static bool _is_check_acceptable_first(
195 return problem.is_check_acceptable_first();
203 template<
typename Problem,
typename Scalar>
240 template<
typename Problem,
typename Scalar>
257 return _reparameterize(problem, x, grad);
263 typename std::enable_if<!problem_traits<U, Scalar>::has_reparameterize,
265 static constexpr
bool _reparameterize(
274 typename std::enable_if<problem_traits<U, Scalar>::has_reparameterize,
276 static constexpr
bool _reparameterize(
281 return problem.reparameterize(x, grad);
decltype(upper_bound_probe(*dummy_problem)) upper_bound_type
return type of the upper_bounds function; void if not provided
Definition: ProblemTraits.hpp:91
The no step length identifier.
Definition: ProblemTraits.hpp:204
static constexpr bool is_check_acceptable_first(Problem &)
Check if change acceptability should be checked first.
Definition: ProblemTraits.hpp:233
static constexpr Scalar initial_step_length(Problem &, const Vector< Scalar > &, const Vector< Scalar > &)
Get the intial step length from problem.
Definition: ProblemTraits.hpp:209
static Scalar initial_step_length(Problem &problem, const Vector< Scalar > &x, const Vector< Scalar > &p)
Get the initial step length from problem.
Definition: ProblemTraits.hpp:138
decltype(change_acceptable_probe(*dummy_problem)) change_acceptable_type
return type of the change_acceptable function; void if not provided
Definition: ProblemTraits.hpp:105
!
Definition: ProblemTraits.hpp:15
static bool reparameterize(Problem &problem, Vector< Scalar > &x, Vector< Scalar > &grad)
Reparemeterize x and recalculate the gradient.
Definition: ProblemTraits.hpp:252
Traits for scalar values.
Definition: ScalarTraits.hpp:16
static Scalar change_acceptable(Problem &problem, const Vector< Scalar > &x0, const Vector< Scalar > &x)
Check if suggested step is acceptable.
Definition: ProblemTraits.hpp:156
static constexpr Scalar change_acceptable(Problem &, const Vector< Scalar > &, const Vector< Scalar > &)
Check if change is acceptable.
Definition: ProblemTraits.hpp:221
static bool is_check_acceptable_first(Problem &problem)
Check if change acceptability should be checked first.
Definition: ProblemTraits.hpp:172
decltype(value_probe(*dummy_problem)) value_type
return type of the value function; void if not provided
Definition: ProblemTraits.hpp:71
decltype(is_check_acceptable_first_probe(*dummy_problem)) is_check_acceptable_first_type
return type of the check_acceptable_first function; void if not provided
Definition: ProblemTraits.hpp:112
Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > Vector
Vector type used.
Definition: Types.hpp:15
decltype(initial_step_length_probe(*dummy_problem)) initial_step_length_type
return type of the initial_step_length function; void if not provided
Definition: ProblemTraits.hpp:98
typename std::remove_cv< typename std::remove_reference< T >::type >::type type
!
Definition: ProblemTraits.hpp:17
decltype(gradient_probe(*dummy_problem)) gradient_type
return type of the gradient function; void if not provided
Definition: ProblemTraits.hpp:77
Traits for the problem.
Definition: ProblemTraits.hpp:31
BFGS optimizations.
Definition: BFGS.hpp:24
The max step length identifier.
Definition: ProblemTraits.hpp:130
Reparameterizer.
Definition: ProblemTraits.hpp:244
decltype(reparameterize_probe(*dummy_problem)) reparameterize_type
return type of the reparameterize function; void if not provided
Definition: ProblemTraits.hpp:119
decltype(lower_bound_probe(*dummy_problem)) lower_bound_type
return type of the lower_bounds function; void if not provided
Definition: ProblemTraits.hpp:84