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

Function lagrange_poly_min_extrap

dlib/optimization/optimization_line_search.h:243–280  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

241// ----------------------------------------------------------------------------------------
242
243 inline double lagrange_poly_min_extrap (
244 double p1,
245 double p2,
246 double p3,
247 double f1,
248 double f2,
249 double f3
250 )
251 {
252 DLIB_ASSERT(p1 < p2 && p2 < p3 && f1 >= f2 && f2 <= f3,
253 " p1: " << p1
254 << " p2: " << p2
255 << " p3: " << p3
256 << " f1: " << f1
257 << " f2: " << f2
258 << " f3: " << f3);
259
260 // This formula is out of the book Nonlinear Optimization by Andrzej Ruszczynski. See section 5.2.
261 double temp1 = f1*(p3*p3 - p2*p2) + f2*(p1*p1 - p3*p3) + f3*(p2*p2 - p1*p1);
262 double temp2 = 2*(f1*(p3 - p2) + f2*(p1 - p3) + f3*(p2 - p1) );
263
264 if (temp2 == 0)
265 {
266 return p2;
267 }
268
269 const double result = temp1/temp2;
270
271 // do a final sanity check to make sure the result is in the right range
272 if (p1 <= result && result <= p3)
273 {
274 return result;
275 }
276 else
277 {
278 return std::min(std::max(p1,result),p3);
279 }
280 }
281
282// ----------------------------------------------------------------------------------------
283

Callers 2

find_min_single_variableFunction · 0.85
max_point_interpolatedFunction · 0.85

Calls 2

minFunction · 0.50
maxFunction · 0.50

Tested by

no test coverage detected