1 #ifndef _LDAPLUSPLUS_OPTIMIZATION_GRADIENT_DESCENT_HPP_ 2 #define _LDAPLUSPLUS_OPTIMIZATION_GRADIENT_DESCENT_HPP_ 10 namespace optimization {
18 template <
typename ProblemType,
typename ParameterType>
22 typedef typename ParameterType::Scalar Scalar;
38 const ProblemType &problem,
39 Eigen::Ref<ParameterType> x0,
40 const ParameterType &grad_x0,
41 const ParameterType &direction
52 template <
typename ProblemType,
typename ParameterType>
56 typedef typename ParameterType::Scalar Scalar;
64 const ProblemType &problem,
65 Eigen::Ref<ParameterType> x0,
66 const ParameterType &grad_x0,
67 const ParameterType &direction
69 x0 -= alpha_ * direction;
71 return problem.value(x0);
99 template <
typename ProblemType,
typename ParameterType>
103 typedef typename ParameterType::Scalar Scalar;
114 const ProblemType &problem,
115 Eigen::Ref<ParameterType> x0,
116 const ParameterType &grad_x0,
117 const ParameterType &direction
119 ParameterType x_copy(x0.rows(), x0.cols());
120 Scalar value_x0 = problem.value(x0);
121 Scalar decrease = beta_ * (grad_x0.array() * direction.array()).sum();
122 Scalar value = value_x0;
125 while (value > value_x0 - a * decrease) {
127 x_copy = x0 - a * direction;
128 value = problem.value(x_copy);
157 template <
typename ProblemType,
typename ParameterType>
161 typedef typename ParameterType::Scalar Scalar;
171 std::function<
bool(Scalar, Scalar,
size_t)> progress
172 ) : line_search_(line_search),
186 void minimize(
const ProblemType &problem, Eigen::Ref<ParameterType> x0) {
188 ParameterType grad(x0.rows(), x0.cols());
191 Scalar value = problem.value(x0);
194 size_t iterations = 0;
197 while (progress_(value, grad.template lpNorm<Eigen::Infinity>(), iterations++)) {
198 problem.gradient(x0, grad);
199 value = line_search_->search(problem, x0, grad, grad);
204 std::shared_ptr<LineSearch<ProblemType, ParameterType> > line_search_;
205 std::function<bool(Scalar, Scalar, size_t)> progress_;
212 #endif // _LDAPLUSPLUS_OPTIMIZATION_GRADIENT_DESCENT_HPP_ ArmijoLineSearch(Scalar beta=0.001, Scalar tau=0.5)
Definition: GradientDescent.hpp:109
Definition: GradientDescent.hpp:100
Scalar search(const ProblemType &problem, Eigen::Ref< ParameterType > x0, const ParameterType &grad_x0, const ParameterType &direction)
Definition: GradientDescent.hpp:63
GradientDescent(std::shared_ptr< LineSearch< ProblemType, ParameterType > > line_search, std::function< bool(Scalar, Scalar, size_t)> progress)
Definition: GradientDescent.hpp:169
Definition: GradientDescent.hpp:158
Definition: GradientDescent.hpp:19
void minimize(const ProblemType &problem, Eigen::Ref< ParameterType > x0)
Definition: GradientDescent.hpp:186
virtual Scalar search(const ProblemType &problem, Eigen::Ref< ParameterType > x0, const ParameterType &grad_x0, const ParameterType &direction)=0
ConstantLineSearch(Scalar alpha)
Definition: GradientDescent.hpp:61
Definition: GradientDescent.hpp:53
Scalar search(const ProblemType &problem, Eigen::Ref< ParameterType > x0, const ParameterType &grad_x0, const ParameterType &direction)
Definition: GradientDescent.hpp:113
Definition: Document.hpp:11