1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// Copyright (C) 2008 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_OPTIMIZATIOn_SEARCH_STRATEGIES_ABSTRACT_
#ifdef DLIB_OPTIMIZATIOn_SEARCH_STRATEGIES_ABSTRACT_
#include <cmath>
#include <limits>
#include "../matrix/matrix_abstract.h"
#include "../algs.h"
namespace dlib
{
/*
A good discussion of the search strategies in this file can be found in the
following book: Numerical Optimization by Nocedal and Wright.
*/
// ----------------------------------------------------------------------------------------
class cg_search_strategy
{
/*!
WHAT THIS OBJECT REPRESENTS
This object represents a strategy for determining which direction
a line search should be carried out along. This particular object
is an implementation of the Polak-Ribiere conjugate gradient method
for determining this direction.
This method uses an amount of memory that is linear in the number
of variables to be optimized. So it is capable of handling problems
with a very large number of variables. However, it is generally
not as good as the L-BFGS algorithm (which is defined below in
the lbfgs_search_strategy class).
!*/
public:
cg_search_strategy(
);
/*!
ensures
- This object is properly initialized and ready to generate
search directions.
!*/
double get_wolfe_rho (
) const;
/*!
ensures
- returns the value of the Wolfe rho parameter that should be used when
this search strategy is used with the line_search() function.
!*/
double get_wolfe_sigma (
) const;
/*!
ensures
- returns the value of the Wolfe sigma parameter that should be used when
this search strategy is used with the line_search() function.
!*/
template <typename T>
const matrix<double,0,1>& get_next_direction (
const T& x,
const double funct_value,
const T& funct_derivative
);
/*!
requires
- this function is only called once per search iteration
- for some objective function f():
- x == the search point for the current iteration
- funct_value == f(x)
- funct_derivative == derivative(f)(x)
ensures
- Assuming that a line search is going to be conducted starting from the point x,
this function returns the direction in which the search should proceed.
!*/
};
// ----------------------------------------------------------------------------------------
class bfgs_search_strategy
{
/*!
WHAT THIS OBJECT REPRESENTS
This object represents a strategy for determining which direction
a line search should be carried out along. This particular object
is an implementation of the BFGS quasi-newton method for determining
this direction.
This method uses an amount of memory that is quadratic in the number
of variables to be optimized. It is generally very effective but
if your problem has a very large number of variables then it isn't
appropriate. Instead You should try the lbfgs_search_strategy.
!*/
public:
bfgs_search_strategy(
);
/*!
ensures
- This object is properly initialized and ready to generate
search directions.
!*/
double get_wolfe_rho (
) const;
/*!
ensures
- returns the value of the Wolfe rho parameter that should be used when
this search strategy is used with the line_search() function.
!*/
double get_wolfe_sigma (
) const;
/*!
ensures
- returns the value of the Wolfe sigma parameter that should be used when
this search strategy is used with the line_search() function.
!*/
template <typename T>
const matrix<double,0,1>& get_next_direction (
const T& x,
const double funct_value,
const T& funct_derivative
);
/*!
requires
- this function is only called once per search iteration
- for some objective function f():
- x == the search point for the current iteration
- funct_value == f(x)
- funct_derivative == derivative(f)(x)
ensures
- Assuming that a line search is going to be conducted starting from the point x,
this function returns the direction in which the search should proceed.
!*/
};
// ----------------------------------------------------------------------------------------
class lbfgs_search_strategy
{
/*!
WHAT THIS OBJECT REPRESENTS
This object represents a strategy for determining which direction
a line search should be carried out along. This particular object
is an implementation of the L-BFGS quasi-newton method for determining
this direction.
This method uses an amount of memory that is linear in the number
of variables to be optimized. This makes it an excellent method
to use when an optimization problem has a large number of variables.
!*/
public:
lbfgs_search_strategy(
unsigned long max_size
);
/*!
requires
- max_size > 0
ensures
- This object is properly initialized and ready to generate
search directions.
- L-BFGS works by remembering a certain number of position and gradient
pairs. It uses this remembered information to compute search directions.
The max_size argument determines how many of these pairs will be remembered.
Typically, using between 3 and 30 pairs performs well for many problems.
!*/
double get_wolfe_rho (
) const;
/*!
ensures
- returns the value of the Wolfe rho parameter that should be used when
this search strategy is used with the line_search() function.
!*/
double get_wolfe_sigma (
) const;
/*!
ensures
- returns the value of the Wolfe sigma parameter that should be used when
this search strategy is used with the line_search() function.
!*/
template <typename T>
const matrix<double,0,1>& get_next_direction (
const T& x,
const double funct_value,
const T& funct_derivative
);
/*!
requires
- this function is only called once per search iteration
- for some objective function f():
- x == the search point for the current iteration
- funct_value == f(x)
- funct_derivative == derivative(f)(x)
ensures
- Assuming that a line search is going to be conducted starting from the point x,
this function returns the direction in which the search should proceed.
!*/
};
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_OPTIMIZATIOn_SEARCH_STRATEGIES_ABSTRACT_