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
d7dfd8ad
Commit
d7dfd8ad
authored
Apr 17, 2018
by
Davis King
Browse files
Made find_min_single_variable() more stable. Fixes
https://github.com/davisking/dlib/issues/1224
.
parent
854801d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
6 deletions
+27
-6
dlib/optimization/optimization_line_search.h
dlib/optimization/optimization_line_search.h
+9
-6
dlib/test/optimization.cpp
dlib/test/optimization.cpp
+18
-0
No files found.
dlib/optimization/optimization_line_search.h
View file @
d7dfd8ad
...
@@ -785,13 +785,16 @@ namespace dlib
...
@@ -785,13 +785,16 @@ namespace dlib
// make sure one side of the bracket isn't super huge compared to the other
// make sure one side of the bracket isn't super huge compared to the other
// side. If it is then contract it.
// side. If it is then contract it.
const
double
bracket_ratio
=
abs
(
p1
-
p2
)
/
abs
(
p2
-
p3
);
const
double
bracket_ratio
=
abs
(
p1
-
p2
)
/
abs
(
p2
-
p3
);
if
(
!
(
bracket_ratio
<
10
&&
bracket_ratio
>
0.1
)
)
// Force p_min to be on a reasonable side. But only if lagrange_poly_min_extrap(
)
{
// didn't put it on a good side already.
// Force p_min to be on a reasonable side. But only if lagrange_poly_min_extrap(
)
if
(
bracket_ratio
>=
10
)
// didn't put it on a good side already.
{
if
(
bracket_ratio
>
1
&&
p_min
>
p2
)
if
(
p_min
>
p2
)
p_min
=
(
p1
+
p2
)
/
2
;
p_min
=
(
p1
+
p2
)
/
2
;
else
if
(
p_min
<
p2
)
}
else
if
(
bracket_ratio
<=
0.1
)
{
if
(
p_min
<
p2
)
p_min
=
(
p2
+
p3
)
/
2
;
p_min
=
(
p2
+
p3
)
/
2
;
}
}
...
...
dlib/test/optimization.cpp
View file @
d7dfd8ad
...
@@ -1202,6 +1202,23 @@ namespace
...
@@ -1202,6 +1202,23 @@ namespace
}
}
// ----------------------------------------------------------------------------------------
void
test_find_min_single_variable
()
{
auto
f
=
[](
double
x
)
{
return
(
x
-
0.2
)
*
(
x
-
0.2
);
};
double
x
=
0.8
;
try
{
find_min_single_variable
(
f
,
x
,
0
,
1
,
1e-9
);
DLIB_TEST
(
std
::
abs
(
x
-
0.2
)
<
1e-7
);
}
catch
(
optimize_single_variable_failure
&
)
{
DLIB_TEST
(
false
);
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
class
optimization_tester
:
public
tester
class
optimization_tester
:
public
tester
...
@@ -1223,6 +1240,7 @@ namespace
...
@@ -1223,6 +1240,7 @@ namespace
test_poly_min_extract_2nd
();
test_poly_min_extract_2nd
();
optimization_test
();
optimization_test
();
test_solve_trust_region_subproblem_bounded
();
test_solve_trust_region_subproblem_bounded
();
test_find_min_single_variable
();
}
}
}
a
;
}
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