25struct gsLevenbergMarquardtObjective
27 typedef gsEigen::Matrix<T, gsEigen::Dynamic, 1> Vector;
28 typedef gsEigen::Matrix<T, gsEigen::Dynamic, gsEigen::Dynamic> Matrix;
30 gsLevenbergMarquardtObjective(gsOptProblem<T>* objective)
35 gsLevenbergMarquardtObjective()
40 T operator()(
const Vector &xval, Vector &fval, Matrix &jacobian)
const
42 gsAsConstVector<T> xvec(xval.data(),xval.size());
43 const T val = obj->evalObj(xvec);
47 jacobian.resize(1, obj->numDesignVars());
48 gsAsVector<T> gvec(jacobian.data(), jacobian.size());
49 obj->gradObj_into(xvec,gvec);
53 gsOptProblem<T> * obj;
66template<
typename T = real_t,
67 typename StepSize=lsq::BarzilaiBorwein<T>,
68 typename Callback=lsq::NoCallback<T>,
69 typename FiniteDifferences=lsq::CentralDifferences<T> >
74 typedef typename lsq::LevenbergMarquardt<T, gsLevenbergMarquardtObjective<T>>::Result Result;
82 this->defaultOptions();
83 gsLevenbergMarquardtObjective<T> obj(m_op);
84 m_solver.setErrorFunction(obj);
93 m_result = m_solver.minimize(initialGuess);
94 m_numIterations = m_result.iterations;
95 m_finalObjective = m_result.fval.value();
99 Result result() {
return m_result; };
102 void defaultOptions()
104 Base::defaultOptions();
112 m_solver.setMaxIterations(m_maxIterations);
115 m_solver.setVerbosity(m_verbose);
118 m_solver.setMinError(0);
129 this->minimize(initialGuess);
134 using Base::m_numIterations;
135 using Base::m_finalObjective;
138 using Base::m_verbose;
139 using Base::m_maxIterations;
141 using Base::defaultOptions;
142 using Base::getOptions;
147 T m_minGradientLength;
149 lsq::LevenbergMarquardt<T, gsLevenbergMarquardtObjective<T> > m_solver;
This class describes the gradient descent method.
Definition gsLevenbergMarquardt.h:71
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.