8#include <kernel/solver/base.hpp>
9#include <kernel/solver/iterative.hpp>
10#include <kernel/solver/linesearch.hpp>
11#include <kernel/solver/nloptls.hpp>
12#include <kernel/solver/nlopt_precond.hpp>
31 template<
typename Functional_,
typename Filter_>
47 typedef typename Functional_::DataType
DataType;
90 explicit NLSD(Functional_& functional_, Filter_& filter_,
91 std::shared_ptr<LinesearchType> linesearch_,
92 bool keep_iterates =
false, std::shared_ptr<PrecondType> precond =
nullptr) :
93 BaseClass(
"NLSD", functional_, filter_, precond),
104 iterates =
new std::deque<VectorType>;
131 Functional_& functional_, Filter_& filter_, std::shared_ptr<LinesearchType> linesearch_,
132 std::shared_ptr<PrecondType> precond =
nullptr) :
133 BaseClass(
"NLSD", section_name, section, functional_, filter_, precond),
142 auto keep_iterates_p = section->
query(
"keep_iterates");
143 if(keep_iterates_p.second && std::stoul(keep_iterates_p.first) == 1)
145 iterates =
new std::deque<VectorType>;
167 _linesearch->init_symbolic();
177 this->_vec_p.clear();
178 this->_vec_r.clear();
201 iterates =
new std::deque<VectorType>;
215 this->_vec_r.copy(vec_def);
217 if(this->_precond !=
nullptr)
219 this->_precond->prepare(vec_cor, this->
_filter);
234 this->_vec_r.scale(this->_vec_r,
DataType(-1));
235 this->
_filter.filter_def(this->_vec_r);
237 if(this->_precond !=
nullptr)
239 this->_precond->prepare(vec_sol, this->
_filter);
264 Statistics::add_solver_expression(std::make_shared<ExpressionStartSolve>(this->
name()));
267 _linesearch->reset();
271 iterates->push_back(std::move(vec_sol.clone()));
278 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
283 this->_vec_p.copy(this->_vec_r);
293 DataType eta(this->_vec_p.dot(this->_vec_r));
299 this->_vec_p.copy(this->_vec_r);
310 _linesearch->set_initial_fval(this->
_fval);
311 _linesearch->set_grad_from_defect(this->_vec_r);
313 if(this->_precond !=
nullptr)
319 status =
_linesearch->correct(vec_sol, this->_vec_p);
322 this->
_fval = _linesearch->get_final_fval();
323 this->
_ls_its = _linesearch->get_num_iter();
330 iterates->push_back(vec_sol.clone());
338 Statistics::add_solver_expression(std::make_shared<ExpressionEndSolve>(this->
name(), status, this->
get_num_iter()));
343 if(this->_precond !=
nullptr)
345 this->_precond->prepare(vec_sol, this->
_filter);
356 eta = this->_vec_p.dot(this->_vec_r);
362 this->_vec_p.copy(this->_vec_r);
394 template<
typename Functional_,
typename Filter_,
typename Linesearch_>
395 inline std::shared_ptr<NLSD<Functional_, Filter_>>
new_nlsd(
396 Functional_& functional, Filter_& filter, Linesearch_& linesearch,
bool keep_iterates =
false,
399 return std::make_shared<NLSD<Functional_, Filter_>>(functional, filter, linesearch,
400 keep_iterates, precond);
427 template<
typename Functional_,
typename Filter_,
typename Linesearch_>
428 inline std::shared_ptr<NLSD<Functional_, Filter_>>
new_nlsd(
430 Functional_& functional, Filter_& filter, Linesearch_& linesearch,
433 return std::make_shared<NLSD<Functional_, Filter_>>(section_name, section, functional, filter, linesearch,
#define XASSERT(expr)
Assertion macro definition.
A class organizing a tree of key-value pairs.
std::pair< String, bool > query(String key_path) const
Queries a value by its key path.
Helper class for iteration statistics collection.
Index get_num_iter() const
Returns number of performed iterations.
Status _status
current status of the solver
virtual void plot_summary() const
Plot a summary of the last solver run.
Base class for line search based nonlinear optimizers.
virtual Status _set_initial_defect(const VectorType &vec_def, const VectorType &vec_sol) override
Internal function: sets the initial defect vector.
DataType _fval_prev
Functional value from the previous iteration.
virtual Status _set_new_defect(const VectorType &vec_r, const VectorType &vec_sol) override
Internal function: sets the new defect norm.
DataType _fval
Current functional value.
Functional_ & _functional
Our nonlinear functional.
virtual void set_ls_iter_digits(Index digits)
Sets the number of digits used to plot line search iteration numbers.
Index _ls_its
The number of iterations the linesearch performed in the last iteration of this solver.
Filter_ & _filter
The filter we apply to the gradient.
DataType _steplength
The last step length of the line search.
Abstract base class for preconditioners for nonlinear optimization.
Nonlinear Steepest Descent method for finding a minimum of an functional's gradient.
std::shared_ptr< PrecondType > _precond
NLOptPrecond< typename Functional_::VectorTypeL, Filter_ > PrecondType
Generic preconditioner.
void set_keep_iterates(bool keep_iterates)
Sets the iterates deque according to a bool.
virtual void done_symbolic() override
Symbolic finalization method.
NLSD(const String §ion_name, const PropertyMap *section, Functional_ &functional_, Filter_ &filter_, std::shared_ptr< LinesearchType > linesearch_, std::shared_ptr< PrecondType > precond=nullptr)
Constructor using a PropertyMap.
virtual Status apply(VectorType &vec_cor, const VectorType &vec_def) override
Solver application method.
NLSD(Functional_ &functional_, Filter_ &filter_, std::shared_ptr< LinesearchType > linesearch_, bool keep_iterates=false, std::shared_ptr< PrecondType > precond=nullptr)
Standard constructor.
Filter_ FilterType
The filter type.
Functional_ FunctionalType
The nonlinear functional type.
virtual String name() const override
Returns a descriptive string.
Linesearch< FunctionalType, FilterType > LinesearchType
The baseclass for all applicable linesearches.
virtual Status correct(VectorType &vec_sol, const VectorType &vec_rhs) override
Solver correction method.
virtual void init_symbolic() override
Symbolic initialization method.
VectorType _vec_p
descend direction vector
NLOptLS< Functional_, Filter_ > BaseClass
Our baseclass.
virtual Status _apply_intern(VectorType &vec_sol)
Internal function, applies the solver.
virtual ~NLSD()
Virtual destructor.
Functional_::DataType DataType
Underlying floating point type.
Functional_::GradientType GradientType
Type of the functional's gradient has.
std::shared_ptr< LinesearchType > _linesearch
The linesearch used along the descent direction.
VectorType _vec_r
defect vector
Functional_::VectorTypeR VectorType
Input type for the gradient.
std::deque< VectorType > * iterates
For debugging purposes, all iterates can be logged to here.
bool _apply_precond(VectorType &vec_cor, const VectorType &vec_def, const Filter_ &filter)
Applies the preconditioner onto a defect vector.
virtual void init_symbolic()
Symbolic initialization method.
virtual void done_symbolic()
Symbolic finalization method.
String class implementation.
T_ ilog10(T_ x)
Computes the integral base-10 logarithm of an integer, i.e. its number of non-zero decimal digits.
std::shared_ptr< NLSD< Functional_, Filter_ > > new_nlsd(Functional_ &functional, Filter_ &filter, Linesearch_ &linesearch, bool keep_iterates=false, std::shared_ptr< NLOptPrecond< typename Functional_::VectorTypeL, Filter_ > > precond=nullptr)
Creates a new NLSD solver object.
Status
Solver status return codes enumeration.
@ progress
continue iteration (internal use only)
@ undefined
undefined status
@ aborted
premature abort (solver aborted due to internal errors or preconditioner failure)