MCPcopy Create free account
hub / github.com/davisking/dlib / find_min

Function find_min

dlib/optimization/optimization.h:153–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151 typename T
152 >
153 double find_min (
154 search_strategy_type search_strategy,
155 stop_strategy_type stop_strategy,
156 const funct& f,
157 const funct_der& der,
158 T& x,
159 double min_f
160 )
161 {
162 COMPILE_TIME_ASSERT(is_matrix<T>::value);
163 // The starting point (i.e. x) must be a column vector.
164 COMPILE_TIME_ASSERT(T::NC <= 1);
165
166 DLIB_CASSERT (
167 is_col_vector(x),
168 "\tdouble find_min()"
169 << "\n\tYou have to supply column vectors to this function"
170 << "\n\tx.nc(): " << x.nc()
171 );
172
173
174 T g, s;
175
176 double f_value = f(x);
177 g = der(x);
178
179 if (!is_finite(f_value))
180 throw error("The objective function generated non-finite outputs");
181 if (!is_finite(g))
182 throw error("The objective function generated non-finite outputs");
183
184 while(stop_strategy.should_continue_search(x, f_value, g) && f_value > min_f)
185 {
186 s = search_strategy.get_next_direction(x, f_value, g);
187
188 double alpha = line_search(
189 make_line_search_function(f,x,s, f_value),
190 f_value,
191 make_line_search_function(der,x,s, g),
192 dot(g,s), // compute initial gradient for the line search
193 search_strategy.get_wolfe_rho(), search_strategy.get_wolfe_sigma(), min_f,
194 search_strategy.get_max_line_search_iterations());
195
196 // Take the search step indicated by the above line search
197 x += alpha*s;
198
199 if (!is_finite(f_value))
200 throw error("The objective function generated non-finite outputs");
201 if (!is_finite(g))
202 throw error("The objective function generated non-finite outputs");
203 }
204
205 return f_value;
206 }
207
208// ----------------------------------------------------------------------------------------
209

Callers 8

test_apqFunction · 0.85
test_simpleFunction · 0.85
test_rosenFunction · 0.85
do_the_testMethod · 0.85
learn_platt_scalingFunction · 0.85
mainFunction · 0.85

Calls 14

is_col_vectorFunction · 0.85
derClass · 0.85
errorClass · 0.85
line_searchFunction · 0.85
get_next_directionMethod · 0.80
fFunction · 0.50
is_finiteFunction · 0.50
dotFunction · 0.50
ncMethod · 0.45
get_wolfe_rhoMethod · 0.45

Tested by 4

test_apqFunction · 0.68
test_simpleFunction · 0.68
test_rosenFunction · 0.68
do_the_testMethod · 0.68