29struct 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;
67template<
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);
128 this->minimize(initialGuess);
133 using Base::m_numIterations;
134 using Base::m_finalObjective;
137 using Base::m_verbose;
138 using Base::m_maxIterations;
140 using Base::defaultOptions;
141 using Base::getOptions;
146 T m_minGradientLength;
149 gdc::GradientDescent<T, gsGradientDescentObjective<T>, StepSize, Callback, FiniteDifferences> m_solver;
This class describes the gradient descent method.
Definition gsGradientDescent.h:72
gsOptionList m_options
Options.
Definition gsOptimizer.h:108
gsMatrix< T > m_curDesign
Current design variables (and starting point )
Definition gsOptimizer.h:105
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
Class defining an optimization problem.
Definition gsOptProblem.h:25
Class defining an optimizer.
Definition gsOptimizer.h:28
gsOptionList m_options
Options.
Definition gsOptimizer.h:108
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
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.
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.
The G+Smo namespace, containing all definitions for the library.