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