Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
c75bbc7d
Commit
c75bbc7d
authored
Sep 14, 2013
by
Davis King
Browse files
Added a version of poly_min_extrap() that uses a 2nd degree model.
parent
aaeb52ba
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
0 deletions
+50
-0
dlib/optimization/optimization_line_search.h
dlib/optimization/optimization_line_search.h
+18
-0
dlib/optimization/optimization_line_search_abstract.h
dlib/optimization/optimization_line_search_abstract.h
+16
-0
dlib/test/optimization.cpp
dlib/test/optimization.cpp
+16
-0
No files found.
dlib/optimization/optimization_line_search.h
View file @
c75bbc7d
...
...
@@ -193,6 +193,24 @@ namespace dlib
return
put_in_range
(
0
,
1
,
x
);
}
// ----------------------------------------------------------------------------------------
inline
double
poly_min_extrap
(
double
f0
,
double
d0
,
double
f1
)
{
const
double
temp
=
2
*
(
f1
-
f0
-
d0
);
if
(
std
::
abs
(
temp
)
<=
d0
*
std
::
numeric_limits
<
double
>::
epsilon
())
return
0.5
;
const
double
alpha
=
-
d0
/
temp
;
// now make sure the minimum is within the allowed range of (0,1)
return
put_in_range
(
0
,
1
,
alpha
);
}
// ----------------------------------------------------------------------------------------
inline
double
lagrange_poly_min_extrap
(
...
...
dlib/optimization/optimization_line_search_abstract.h
View file @
c75bbc7d
...
...
@@ -103,6 +103,22 @@ namespace dlib
- returns the point in the range [0,1] that minimizes the polynomial c(x)
!*/
// ----------------------------------------------------------------------------------------
inline
double
poly_min_extrap
(
double
f0
,
double
d0
,
double
f1
);
/*!
ensures
- let c(x) be a 2nd degree polynomial such that:
- c(0) == f0
- c(1) == f1
- derivative of c(x) at x==0 is d0
- returns the point in the range [0,1] that minimizes the polynomial c(x)
!*/
// ----------------------------------------------------------------------------------------
inline
double
lagrange_poly_min_extrap
(
...
...
dlib/test/optimization.cpp
View file @
c75bbc7d
...
...
@@ -917,6 +917,21 @@ namespace
}
void
test_poly_min_extract_2nd
()
{
double
off
;
off
=
0.0
;
DLIB_TEST
(
std
::
abs
(
poly_min_extrap
(
off
*
off
,
-
2
*
off
,
(
1
-
off
)
*
(
1
-
off
))
-
off
)
<
1e-13
);
off
=
0.1
;
DLIB_TEST
(
std
::
abs
(
poly_min_extrap
(
off
*
off
,
-
2
*
off
,
(
1
-
off
)
*
(
1
-
off
))
-
off
)
<
1e-13
);
off
=
0.2
;
DLIB_TEST
(
std
::
abs
(
poly_min_extrap
(
off
*
off
,
-
2
*
off
,
(
1
-
off
)
*
(
1
-
off
))
-
off
)
<
1e-13
);
off
=
0.3
;
DLIB_TEST
(
std
::
abs
(
poly_min_extrap
(
off
*
off
,
-
2
*
off
,
(
1
-
off
)
*
(
1
-
off
))
-
off
)
<
1e-13
);
off
=
0.4
;
DLIB_TEST
(
std
::
abs
(
poly_min_extrap
(
off
*
off
,
-
2
*
off
,
(
1
-
off
)
*
(
1
-
off
))
-
off
)
<
1e-13
);
off
=
0.5
;
DLIB_TEST
(
std
::
abs
(
poly_min_extrap
(
off
*
off
,
-
2
*
off
,
(
1
-
off
)
*
(
1
-
off
))
-
off
)
<
1e-13
);
off
=
0.6
;
DLIB_TEST
(
std
::
abs
(
poly_min_extrap
(
off
*
off
,
-
2
*
off
,
(
1
-
off
)
*
(
1
-
off
))
-
off
)
<
1e-13
);
off
=
0.8
;
DLIB_TEST
(
std
::
abs
(
poly_min_extrap
(
off
*
off
,
-
2
*
off
,
(
1
-
off
)
*
(
1
-
off
))
-
off
)
<
1e-13
);
off
=
0.9
;
DLIB_TEST
(
std
::
abs
(
poly_min_extrap
(
off
*
off
,
-
2
*
off
,
(
1
-
off
)
*
(
1
-
off
))
-
off
)
<
1e-13
);
off
=
1.0
;
DLIB_TEST
(
std
::
abs
(
poly_min_extrap
(
off
*
off
,
-
2
*
off
,
(
1
-
off
)
*
(
1
-
off
))
-
off
)
<
1e-13
);
}
class
optimization_tester
:
public
tester
{
...
...
@@ -930,6 +945,7 @@ namespace
void
perform_test
(
)
{
test_poly_min_extract_2nd
();
optimization_test
();
}
}
a
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment