29 struct gsGradientDescentObjective
31 typedef gsEigen::Matrix<T, gsEigen::Dynamic, 1> Vector;
34 gsGradientDescentObjective(gsOptProblem<T>* objective)
39 gsGradientDescentObjective()
45 T operator()(
const Vector & vx, Vector & vfgrad)
const
47 vfgrad.resize(obj->numDesignVars());
48 gsAsConstVector<T> xvec(vx.data(),vx.size());
49 gsAsVector<T> gvec(vfgrad.data(),vfgrad.size());
50 obj->gradObj_into(xvec,gvec);
51 return obj->evalObj(xvec);
54 gsOptProblem<T> * obj;
67 template<
typename T = real_t,
68 typename StepSize=gdc::BarzilaiBorwein<T>,
69 typename Callback=gdc::NoCallback<T>,
70 typename FiniteDifferences=gdc::CentralDifferences<T> >
75 typedef typename gdc::GradientDescent<T, gsGradientDescentObjective<T>, StepSize, Callback, FiniteDifferences>::Result Result;
83 this->defaultOptions();
84 gsGradientDescentObjective<T> obj(m_op);
85 m_solver.setObjective(obj);
94 m_result = m_solver.minimize(initialGuess);
95 m_numIterations = m_result.iterations;
96 m_finalObjective = m_result.fval;
100 Result result() {
return m_result; };
103 void defaultOptions()
105 Base::defaultOptions();
116 m_solver.setMaxIterations(m_maxIterations);
117 m_solver.setMinGradientLength(m_minGradientLength);
118 m_solver.setMinStepLength(m_minStepLength);
119 m_solver.setVerbosity(m_verbose);
127 this->minimize(initialGuess);
132 using Base::m_numIterations;
133 using Base::m_finalObjective;
136 using Base::m_verbose;
137 using Base::m_maxIterations;
139 using Base::defaultOptions;
140 using Base::getOptions;
145 T m_minGradientLength;
148 gdc::GradientDescent<T, gsGradientDescentObjective<T>, StepSize, Callback, FiniteDifferences> m_solver;
Class defining an optimization problem.
Definition: gsOptProblem.h:24
Class defining an optimizer.
Definition: gsOptimizer.h:27
gsOptionList m_options
Options.
Definition: gsOptimizer.h:108
Provides declaration of an optimization problem.
This file is part of the G+Smo library.
Provides a list of labeled parameters/options that can be set and accessed easily.
void addReal(const std::string &label, const std::string &desc, const Real &value)
Adds a option named label, with description desc and value value.
Definition: gsOptionList.cpp:211
This is the main header file that collects wrappers of Eigen for linear algebra.
gsMatrix< T > m_curDesign
Current design variables (and starting point )
Definition: gsOptimizer.h:105
Real getReal(const std::string &label) const
Reads value for option label from options.
Definition: gsOptionList.cpp:44
This class describes the gradient descent method.
Definition: gsGradientDescent.h:71