13#ifndef OPTIMIST_OPTIMIZER_HH
14#define OPTIMIST_OPTIMIZER_HH
44 template <
typename Real, Integer N,
typename DerivedSolver>
49 static_assert(N !=
static_cast<Integer>(0),
50 "Have you ever heard of a zero-dimensional optimization problem?");
51 static_assert(N !=
static_cast<Integer>(1),
52 "Good try, but you should use a scalar solver for a one-dimensional optimization problem.");
86 std::string
name()
const {
return static_cast<const DerivedSolver *
>(
this)->name_impl();}
139 this->evaluate_first_derivative_impl(gradient, x, out);
150 this->evaluate_second_derivative_impl(hessian, x, out);
162 #define CMD "Optimist::Optimizer::solve(...): "
164 static_assert(DerivedSolver::requires_function,
165 CMD "the solver requires the function.");
166 return static_cast<DerivedSolver *
>(
this)->solve_impl(function, x_ini, x_sol);
181 #define CMD "Optimist::Optimizer::solve(...): "
183 static_assert(DerivedSolver::requires_function,
184 CMD "the solver requires the function.");
185 static_assert(DerivedSolver::requires_first_derivative,
186 CMD "the solver requires the first derivative.");
187 return static_cast<DerivedSolver *
>(
this)->solve_impl(function, gradient, x_ini, x_sol);
202 const & x_ini,
Vector & x_sol)
204 #define CMD "Optimist::Optimizer::solve(...): "
206 static_assert(DerivedSolver::requires_function,
207 CMD "the solver requires the function.");
208 static_assert(DerivedSolver::requires_first_derivative,
209 CMD "the solver requires the first derivative.");
210 static_assert(DerivedSolver::requires_second_derivative,
211 CMD "the solver requires the second derivative.");
212 return static_cast<DerivedSolver *
>(
this)->solve_impl(function, gradient, hessian, x_ini, x_sol);
#define OPTIMIST_BASIC_CONSTANTS(Real)
Definition Optimist.hh:70
Class container for the multi-dimensional optimizer.
Definition Optimizer.hh:46
void max_gradient_evaluations(Integer t_gradient_evaluations)
Definition Optimizer.hh:104
void evaluate_gradient(GradientWrapper gradient, const Vector &x, Matrix &out)
Definition Optimizer.hh:137
std::string name() const
Definition Optimizer.hh:86
Integer max_gradient_evaluations() const
Definition Optimizer.hh:98
static constexpr bool requires_function
Definition Optimizer.hh:59
typename Solver< Real, N, 1, DerivedSolver >::SecondDerivativeWrapper HessianWrapper
Definition Optimizer.hh:75
bool solve(FunctionWrapper function, Vector const &x_ini, Vector &x_sol)
Definition Optimizer.hh:160
Optimizer()
Definition Optimizer.hh:80
Integer gradient_evaluations() const
Definition Optimizer.hh:92
Integer hessian_evaluations() const
Definition Optimizer.hh:113
void evaluate_hessian(HessianWrapper hessian, const Vector &x, Matrix &out)
Definition Optimizer.hh:148
static constexpr bool is_rootfinder
Definition Optimizer.hh:56
static constexpr bool requires_second_derivative
Definition Optimizer.hh:61
typename Solver< Real, N, 1, DerivedSolver >::InputType Vector
Definition Optimizer.hh:66
typename Solver< Real, N, 1, DerivedSolver >::FirstDerivativeType RowVector
Definition Optimizer.hh:69
typename Solver< Real, N, 1, DerivedSolver >::SecondDerivativeType Matrix
Definition Optimizer.hh:70
bool solve(FunctionWrapper function, GradientWrapper gradient, HessianWrapper hessian, Vector const &x_ini, Vector &x_sol)
Definition Optimizer.hh:201
typename Solver< Real, N, 1, DerivedSolver >::FirstDerivativeWrapper GradientWrapper
Definition Optimizer.hh:74
void max_hessian_evaluations(Integer t_hessian_evaluations)
Definition Optimizer.hh:125
typename Solver< Real, N, 1, DerivedSolver >::FunctionWrapper FunctionWrapper
Definition Optimizer.hh:73
static constexpr bool requires_first_derivative
Definition Optimizer.hh:60
bool solve(FunctionWrapper function, GradientWrapper gradient, Vector const &x_ini, Vector &x_sol)
Definition Optimizer.hh:179
static constexpr bool is_optimizer
Definition Optimizer.hh:57
Integer max_hessian_evaluations() const
Definition Optimizer.hh:119
Integer first_derivative_evaluations() const
Definition Solver.hh:266
Solver()
Definition Solver.hh:106
typename std::conditional_t< SolInDim==1, Real, Eigen::Vector< Real, SolInDim > > InputType
Definition Solver.hh:53
typename std::function< void(const InputType &, FirstDerivativeType &)> FirstDerivativeWrapper
Definition Solver.hh:67
std::conditional_t< SolInDim==1 &&SolOutDim==1, Real, std::conditional_t< SolInDim==1||SolOutDim==1, Eigen::Matrix< Real, SolInDim, SolInDim >, std::vector< Eigen::Matrix< Real, SolInDim, SolInDim > > > > SecondDerivativeType
Definition Solver.hh:61
Integer max_second_derivative_evaluations() const
Definition Solver.hh:296
Integer max_first_derivative_evaluations() const
Definition Solver.hh:272
typename std::function< void(const InputType &, SecondDerivativeType &)> SecondDerivativeWrapper
Definition Solver.hh:68
Integer second_derivative_evaluations() const
Definition Solver.hh:290
std::conditional_t< SolInDim==1 &&SolOutDim==1, Real, Eigen::Matrix< Real, SolOutDim, SolInDim > > FirstDerivativeType
Definition Solver.hh:60
Namespace for the Optimist library.
Definition Optimist.hh:87
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:95