Optimist  0.0.0
A C++ library for optimization
Loading...
Searching...
No Matches
Optimizer.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
2 * Copyright (c) 2025, Davide Stocco and Enrico Bertolazzi. *
3 * *
4 * The Optimist project is distributed under the BSD 2-Clause License. *
5 * *
6 * Davide Stocco Enrico Bertolazzi *
7 * University of Trento University of Trento *
8 * davide.stocco@unitn.it enrico.bertolazzi@unitn.it *
9\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
10
11#pragma once
12
13#ifndef OPTIMIST_OPTIMIZER_HH
14#define OPTIMIST_OPTIMIZER_HH
15
17
18namespace Optimist {
19
23 namespace Optimizer {
24
33 template <typename T, typename DerivedSolver>
37 : public SolverBase<T, typename TypeTrait<T>::Scalar, DerivedSolver> {
38 public:
39 friend class SolverBase<T, typename TypeTrait<T>::Scalar, DerivedSolver>;
40
41 static constexpr bool IsRootFinder{false};
42 static constexpr bool IsOptimizer{true};
43
44 // Input and output types
45 using Scalar = typename TypeTrait<T>::Scalar;
46 using Input = T;
47 using Output = Scalar;
48
49 // Derivative types
52
54
55
59
64 constexpr std::string name() const {
65 return static_cast<const DerivedSolver *>(this)->name_impl();
66 }
67
75
83
89 void max_gradient_evaluations(const Integer t_gradient_evaluations) {
90 this->max_first_derivative_evaluations(t_gradient_evaluations);
91 }
92
100
108
114 void max_hessian_evaluations(const Integer t_hessian_evaluations) {
115 this->max_second_derivative_evaluations(t_hessian_evaluations);
116 }
117
118 protected:
127 template <typename GradientLambda>
128 bool evaluate_gradient(GradientLambda &&gradient,
129 const Input &x,
130 FirstDerivative &out) {
131 return this->evaluate_first_derivative(
132 std::forward<GradientLambda>(gradient),
133 x,
134 out);
135 }
136
145 template <typename HessianLambda>
146 bool evaluate_hessian(HessianLambda &&hessian,
147 const Input &x,
148 SecondDerivative &out) {
149 return this->evaluate_second_derivative(
150 std::forward<HessianLambda>(hessian),
151 x,
152 out);
153 }
154
155 }; // class Optimizer
156
157 } // namespace Optimizer
158
159} // namespace Optimist
160
161#endif // OPTIMIST_OPTIMIZER_HH
#define OPTIMIST_BASIC_CONSTANTS(Scalar)
Definition Optimist.hh:70
Class container for the multi-dimensional optimizer.
Definition Optimizer.hh:37
static constexpr bool IsRootFinder
Definition Optimizer.hh:41
typename TypeTrait< T >::Scalar Scalar
Definition Optimizer.hh:45
Integer max_gradient_evaluations() const
Definition Optimizer.hh:80
Integer hessian_evaluations() const
Definition Optimizer.hh:97
Integer max_hessian_evaluations() const
Definition Optimizer.hh:105
void max_gradient_evaluations(const Integer t_gradient_evaluations)
Definition Optimizer.hh:89
Scalar Output
Definition Optimizer.hh:47
constexpr std::string name() const
Definition Optimizer.hh:64
void max_hessian_evaluations(const Integer t_hessian_evaluations)
Definition Optimizer.hh:114
bool evaluate_hessian(HessianLambda &&hessian, const Input &x, SecondDerivative &out)
Definition Optimizer.hh:146
T Input
Definition Optimizer.hh:46
Optimizer()
Definition Optimizer.hh:58
Integer gradient_evaluations() const
Definition Optimizer.hh:72
bool evaluate_gradient(GradientLambda &&gradient, const Input &x, FirstDerivative &out)
Definition Optimizer.hh:128
static constexpr bool IsOptimizer
Definition Optimizer.hh:42
Integer first_derivative_evaluations() const
Definition SolverBase.hh:324
bool evaluate_first_derivative(FirstDerivativeLambda &&function, const T &x, FirstDerivative &out)
Definition SolverBase.hh:1047
FunctionBase< Input, Output, DerivedSolver >::SecondDerivative SecondDerivative
Definition SolverBase.hh:74
bool evaluate_second_derivative(SecondDerivativeLambda &&function, const T &x, SecondDerivative &out)
Definition SolverBase.hh:1068
Integer max_first_derivative_evaluations() const
Definition SolverBase.hh:332
Integer second_derivative_evaluations() const
Definition SolverBase.hh:354
Integer max_second_derivative_evaluations() const
Definition SolverBase.hh:362
FunctionBase< Input, Output, DerivedSolver >::FirstDerivative FirstDerivative
Definition SolverBase.hh:72
Namespace for the Optimist library.
Definition Optimist.hh:90
OPTIMIST_DEFAULT_INTEGER_TYPE Integer
The Integer type as used for the API.
Definition Optimist.hh:98
Definition Optimist.hh:105