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  * <http://shark-ml.org/>
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>
40 #include <shark/Core/DLLSupport.h>
42 
43 namespace shark {
44 ///\brief Wrapper for the linesearch class of functions in the linear algebra library.
45 ///
46 ///This class is a wrapper for the linesearch class of functions of the linear algebra library.
47 ///The class is used for example in CG or BFGS for their internal linesearch learning steps.
48 ///It is NOT an Optimizer on its own, since it needs the Newton direction to be specified.
49 class LineSearch:public ISerializable {
50 public:
55  };
57 
58  ///Initializes the internal variables of the class to useful default values.
59  ///Dlinmin is used as default
61  m_minInterval=0;
62  m_maxInterval=1;
64  }
65 
67  return m_lineSearchType;
68  }
70  return m_lineSearchType;
71  }
72  ///minInterval sets the minimum initial bracket
73  double minInterval()const {
74  return m_minInterval;
75  }
76  ///minInterval sets the minimum initial bracket
77  double &minInterval() {
78  return m_minInterval;
79  }
80  ///maxInterval sets the maximum initial bracket
81  double maxInterval()const {
82  return m_maxInterval;
83  }
84  ///maxInterval sets the maximum initial bracket
85  double &maxInterval() {
86  return m_maxInterval;
87  }
88 
89  ///initializes the internal state of the LineSearch class and sets the function on which the lineSearch is to be evaluated
90  void init(ObjectiveFunction const& objectiveFunction) {
91  m_function = &objectiveFunction;
92  }
93 
94  ///performs a linesearch on the objectiveFunction given the starting point, its value the newton direction and optionally the derivative at the starting point
95  ///@param searchPoint the point where the linesearch start
96  ///@param pointValue the value of the function at searchPoint
97  ///@param newtonDirection the search direction of the line search
98  ///@param derivative the derivative of the function at searchPoint
99  ///@param stepLength initial step length guess for guiding the line search
100  SHARK_EXPORT_SYMBOL void operator()(RealVector &searchPoint,double &pointValue,RealVector const& newtonDirection, RealVector &derivative, double stepLength = 1.0)const;
101 
102  //ISerializable
103  virtual void read(InArchive &archive) {
104  archive>>m_minInterval;
105  archive>>m_maxInterval;
106  archive>>m_lineSearchType;
107  }
108 
109  virtual void write(OutArchive &archive) const {
110  archive<<m_minInterval;
111  archive<<m_maxInterval;
112  archive<<m_lineSearchType;
113  }
114 
115 
116 protected:
117  ///initial [min,max] bracket for linesearch
119  ///initial [min,max] bracket for linesearch
121 
123 
124  ///function to optimize
125  ObjectiveFunction const* m_function;
126 };
127 }
128 
129 #endif