AbstractLineSearchOptimizer.h
Go to the documentation of this file.
1 //===========================================================================
2 /*!
3  *
4  *
5  * \brief Base class for Line Search Optimizer
6  *
7  *
8  *
9  * \author O. Krause
10  * \date 2013
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 
36 #ifndef SHARK_ALGORITHMS_GRADIENTDESCENT_ABSTRACTLINESEARCHOPTIMIZER_H
37 #define SHARK_ALGORITHMS_GRADIENTDESCENT_ABSTRACTLINESEARCHOPTIMIZER_H
38 
39 #include <shark/Core/DLLSupport.h>
42 
43 namespace shark {
44 
45 /// \brief Basis class for line search methods.
46 ///
47 /// Line Search optimizer find an iterative optimum by starting from some point, choosing a search direction and than
48 /// performing a line search in that direction. To choose the search direction a local model of the function is often used.
49 /// This class is a base class for all line search method which implement the general behaviour of line search methods.
50 /// Derived classes only need to implement initModel() and computeSearchDirection() to initializee and update
51 /// the model and find a new line search direction. The remaining functionality is implemented by the optimizer.
52 ///
53 /// Also derived classes should specialise read() and write() methods for serialization if they have additional members
54 /// as well as choose a name() for the optimizer.
56 protected:
57  /// \brief Initializes the internal model.
58  ///
59  /// Line Search Methods use a Model to search for the next search direction.
60  /// The model is initialized during init()
61  virtual void initModel() = 0;
62 
63  /// \brief Updates the Model and computes the next search direction
64  ///
65  /// After a step was performed, this method is called to compute the next
66  /// search direction. This usually involves updating the internal model using the
67  /// new and old step information. Afterwards m_searchDirection should contain
68  /// the next search direction.
69  virtual void computeSearchDirection(ObjectiveFunctionType const& objectiveFunction) = 0;
70 
71 public:
73 
74  SHARK_EXPORT_SYMBOL void init(ObjectiveFunctionType const& objectiveFunction, SearchPointType const& startingPoint) ;
75 
77 
78  SHARK_EXPORT_SYMBOL void step(ObjectiveFunctionType const& objectiveFunction);
79 
80  //from ISerializable
81  SHARK_EXPORT_SYMBOL void read(InArchive &archive);
82  SHARK_EXPORT_SYMBOL void write(OutArchive &archive) const;
83 
84 
85  //linesearch handling
86  LineSearch const& lineSearch()const {
87  return m_linesearch;
88  }
90  return m_linesearch;
91  }
92 
93  /// \brief Returns the derivative at the current point. Can be used for stopping criteria.
94  RealVector const& derivative()const{
95  return m_derivative;
96  }
97 
98 
99 protected: // Instance vars
100 
101  LineSearch m_linesearch; ///< used line search method.
102  std::size_t m_dimension; ///< number of parameters
103  double m_initialStepLength;///< Initial step length to begin with the line search.
104 
105  RealVector m_derivative; ///< gradient of m_best.point
106  RealVector m_searchDirection;///< search direction of next step
107 
108  //information from previous step
109  RealVector m_lastPoint; ///< previous point
110  RealVector m_lastDerivative; ///< gradient of the previous point
111  double m_lastValue; ///< value of the previous point
112 };
113 
114 }
115 #endif