AbstractSingleObjectiveOptimizer.h
Go to the documentation of this file.
1//===========================================================================
2/*!
3 *
4 *
5 * \brief AbstractSingleObjectiveOptimizer
6 *
7 *
8 *
9 * \author T.Voss, T. Glasmachers, O.Krause
10 * \date 2010-2011
11 *
12 *
13 * \par Copyright 1995-2017 Shark Development Team
14 *
15 * <BR><HR>
16 * This file is part of Shark.
17 * <https://shark-ml.github.io/Shark/>
18 *
19 * Shark is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU Lesser General Public License as published
21 * by the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
23 *
24 * Shark is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU Lesser General Public License for more details.
28 *
29 * You should have received a copy of the GNU Lesser General Public License
30 * along with Shark. If not, see <http://www.gnu.org/licenses/>.
31 *
32 */
33//===========================================================================
34#ifndef SHARK_OBJECTIVEFUNCTIONS_ABSTRACTSINGLEOBJECTIVEOPTIMIZER_H
35#define SHARK_OBJECTIVEFUNCTIONS_ABSTRACTSINGLEOBJECTIVEOPTIMIZER_H
36
39
40namespace shark {
41
42 ///\defgroup gradientopt Gradient-based Single objective optimizers
43 ///\ingroup optimizers
44 /// Gradient-Based optimizers use the gradient of an objective function to find a local minimum in the search space.
45 /// If a function is not convex this local optimum might not be the global one.
46
47 ///\defgroup singledirect Single-objective Direct-Search optimizers
48 ///\ingroup optimizers
49 /// Group of optimization algorithms that find the local optimum of a function without using gradient information, only
50 /// the function values are used.
51
52 ///\brief Base class for all single objective optimizer
53 ///
54 /// This class is a spezialization of the AbstractOptimizer itnerface for the class of single objective optimizers. A single objective optimizer is an optimizer
55 /// which can only optimize functions with a single objective. This is the default case for most optimisation problems.
56 /// the class requires the ObjectiveFunction to provide a feasible starting point. If this is not possible, a second version of init is provided where the starting point can be
57 /// explicitely defined.
58 /// The Return type of an SingleObjectiveOptimizer is the SingleObjectiveResultSet which is a struct returning the best value of the function and together with it's point.
59 /// \ingroup optimizers
60 template<class PointType>
61 class AbstractSingleObjectiveOptimizer: public AbstractOptimizer<PointType,double,SingleObjectiveResultSet<PointType> >{
62 private:
64 public:
69
70 ///\brief By default most single objective optimizers only require a single point
71 std::size_t numInitPoints() const{
72 return 1;
73 }
74
75 using base_type::init;
76
77 /// \brief Initialize the optimizer for the supplied objective function using a set of initialisation points
78 ///
79 /// The default implementation picks either the first point in the set, or if it is enmpty, trys
80 /// to generate one from the function.
81 ///
82 /// Be aware that function.init() has to be called before calling this function!
83 ///
84 /// \param [in] function The objective function to initialize for.
85 /// \param [in] initPoints points used for initialisation. Should be at least numInitPoints().
86 virtual void init( ObjectiveFunctionType const& function, std::vector<SearchPointType> const& initPoints ){
87 if(initPoints.empty())
88 init(function);
89 else
90 init(function,initPoints[0]);
91 }
92
93 ///initializes the optimizer using a predefined starting point
94 virtual void init(ObjectiveFunctionType const& function, SearchPointType const& startingPoint)=0;
95 ///returns the current solution of the optimizer
96 virtual const SolutionType& solution() const{
97 return m_best;
98 }
99
100 protected:
101
102 SolutionType m_best; ///<Current solution of the optimizer
103 };
104
105}
106#endif