LineSearch.h
Go to the documentation of this file.
1//===========================================================================
2/*!
3 *
4 *
5 * \brief LineSearch
6 *
7 *
8 *
9 * \author O. Krause, S. Dahlgaard
10 * \date 2010-2017
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
35#ifndef SHARK_ALGORITHMS_GRADIENTDESCENT_LINESEARCH_H
36#define SHARK_ALGORITHMS_GRADIENTDESCENT_LINESEARCH_H
37
38#include <shark/LinAlg/Base.h>
41
42namespace shark {
43
44enum class LineSearchType {
45 Dlinmin,
48};
49
50///\brief Wrapper for the linesearch class of functions in the linear algebra library.
51///
52///This class is a wrapper for the linesearch class of functions of the linear algebra library.
53///The class is used for example in CG or BFGS for their internal linesearch learning steps.
54///It is NOT an Optimizer on its own, since it needs the Newton direction to be specified.
55/// \ingroup gradientopt
56template<class SearchPointType>
58public:
59
61
62 ///Initializes the internal variables of the class to useful default values.
63 ///Dlinmin is used as default
69
76 ///minInterval sets the minimum initial bracket
77 double minInterval()const {
78 return m_minInterval;
79 }
80 ///minInterval sets the minimum initial bracket
81 double &minInterval() {
82 return m_minInterval;
83 }
84 ///maxInterval sets the maximum initial bracket
85 double maxInterval()const {
86 return m_maxInterval;
87 }
88 ///maxInterval sets the maximum initial bracket
89 double &maxInterval() {
90 return m_maxInterval;
91 }
92
93 ///initializes the internal state of the LineSearch class and sets the function on which the lineSearch is to be evaluated
94 void init(ObjectiveFunction const& objectiveFunction) {
95 m_function = &objectiveFunction;
96 }
97
98 ///performs a linesearch on the objectiveFunction given the starting point, its value the newton direction and optionally the derivative at the starting point
99 ///@param searchPoint the point where the linesearch start
100 ///@param pointValue the value of the function at searchPoint
101 ///@param newtonDirection the search direction of the line search
102 ///@param derivative the derivative of the function at searchPoint
103 ///@param stepLength initial step length guess for guiding the line search
104 void operator()(SearchPointType &searchPoint,double &pointValue,SearchPointType const& newtonDirection, SearchPointType &derivative, double stepLength = 1.0)const;
105
106 //ISerializable
107 virtual void read(InArchive &archive) {
108 archive>>m_minInterval;
109 archive>>m_maxInterval;
110 archive>>m_lineSearchType;
111 }
112
113 virtual void write(OutArchive &archive) const {
114 archive<<m_minInterval;
115 archive<<m_maxInterval;
116 archive<<m_lineSearchType;
117 }
118
119
120protected:
121 ///initial [min,max] bracket for linesearch
123 ///initial [min,max] bracket for linesearch
125
127
128 ///function to optimize
130};
131
132extern template class LineSearch<RealVector>;
133extern template class LineSearch<FloatVector>;
134#ifdef SHARK_USE_OPENCL
135extern template class LineSearch<RealGPUVector>;
136extern template class LineSearch<FloatGPUVector>;
137#endif
138}
139
140#endif