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
9cd5f3db
Commit
9cd5f3db
authored
Oct 12, 2014
by
Davis King
Browse files
Made the optimization functions throw an error when non-finite values
are supplied by the user.
parent
5b6e4dbe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
20 deletions
+40
-20
dlib/optimization/optimization.h
dlib/optimization/optimization.h
+40
-20
No files found.
dlib/optimization/optimization.h
View file @
9cd5f3db
...
@@ -176,8 +176,10 @@ namespace dlib
...
@@ -176,8 +176,10 @@ namespace dlib
double
f_value
=
f
(
x
);
double
f_value
=
f
(
x
);
g
=
der
(
x
);
g
=
der
(
x
);
DLIB_ASSERT
(
is_finite
(
f_value
),
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
f_value
))
DLIB_ASSERT
(
is_finite
(
g
),
"The objective function generated non-finite outputs"
);
throw
error
(
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
g
))
throw
error
(
"The objective function generated non-finite outputs"
);
while
(
stop_strategy
.
should_continue_search
(
x
,
f_value
,
g
)
&&
f_value
>
min_f
)
while
(
stop_strategy
.
should_continue_search
(
x
,
f_value
,
g
)
&&
f_value
>
min_f
)
{
{
...
@@ -194,8 +196,10 @@ namespace dlib
...
@@ -194,8 +196,10 @@ namespace dlib
// Take the search step indicated by the above line search
// Take the search step indicated by the above line search
x
+=
alpha
*
s
;
x
+=
alpha
*
s
;
DLIB_ASSERT
(
is_finite
(
f_value
),
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
f_value
))
DLIB_ASSERT
(
is_finite
(
g
),
"The objective function generated non-finite outputs"
);
throw
error
(
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
g
))
throw
error
(
"The objective function generated non-finite outputs"
);
}
}
return
f_value
;
return
f_value
;
...
@@ -238,8 +242,10 @@ namespace dlib
...
@@ -238,8 +242,10 @@ namespace dlib
double
f_value
=
-
f
(
x
);
double
f_value
=
-
f
(
x
);
g
=
-
der
(
x
);
g
=
-
der
(
x
);
DLIB_ASSERT
(
is_finite
(
f_value
),
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
f_value
))
DLIB_ASSERT
(
is_finite
(
g
),
"The objective function generated non-finite outputs"
);
throw
error
(
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
g
))
throw
error
(
"The objective function generated non-finite outputs"
);
while
(
stop_strategy
.
should_continue_search
(
x
,
f_value
,
g
)
&&
f_value
>
-
max_f
)
while
(
stop_strategy
.
should_continue_search
(
x
,
f_value
,
g
)
&&
f_value
>
-
max_f
)
{
{
...
@@ -262,8 +268,10 @@ namespace dlib
...
@@ -262,8 +268,10 @@ namespace dlib
g
*=
-
1
;
g
*=
-
1
;
f_value
*=
-
1
;
f_value
*=
-
1
;
DLIB_ASSERT
(
is_finite
(
f_value
),
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
f_value
))
DLIB_ASSERT
(
is_finite
(
g
),
"The objective function generated non-finite outputs"
);
throw
error
(
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
g
))
throw
error
(
"The objective function generated non-finite outputs"
);
}
}
return
-
f_value
;
return
-
f_value
;
...
@@ -303,8 +311,10 @@ namespace dlib
...
@@ -303,8 +311,10 @@ namespace dlib
double
f_value
=
f
(
x
);
double
f_value
=
f
(
x
);
g
=
derivative
(
f
,
derivative_eps
)(
x
);
g
=
derivative
(
f
,
derivative_eps
)(
x
);
DLIB_ASSERT
(
is_finite
(
f_value
),
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
f_value
))
DLIB_ASSERT
(
is_finite
(
g
),
"The objective function generated non-finite outputs"
);
throw
error
(
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
g
))
throw
error
(
"The objective function generated non-finite outputs"
);
while
(
stop_strategy
.
should_continue_search
(
x
,
f_value
,
g
)
&&
f_value
>
min_f
)
while
(
stop_strategy
.
should_continue_search
(
x
,
f_value
,
g
)
&&
f_value
>
min_f
)
{
{
...
@@ -325,8 +335,10 @@ namespace dlib
...
@@ -325,8 +335,10 @@ namespace dlib
g
=
derivative
(
f
,
derivative_eps
)(
x
);
g
=
derivative
(
f
,
derivative_eps
)(
x
);
DLIB_ASSERT
(
is_finite
(
f_value
),
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
f_value
))
DLIB_ASSERT
(
is_finite
(
g
),
"The objective function generated non-finite outputs"
);
throw
error
(
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
g
))
throw
error
(
"The objective function generated non-finite outputs"
);
}
}
return
f_value
;
return
f_value
;
...
@@ -481,8 +493,10 @@ namespace dlib
...
@@ -481,8 +493,10 @@ namespace dlib
double
f_value
=
f
(
x
);
double
f_value
=
f
(
x
);
g
=
der
(
x
);
g
=
der
(
x
);
DLIB_ASSERT
(
is_finite
(
f_value
),
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
f_value
))
DLIB_ASSERT
(
is_finite
(
g
),
"The objective function generated non-finite outputs"
);
throw
error
(
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
g
))
throw
error
(
"The objective function generated non-finite outputs"
);
// gap_eps determines how close we have to get to a bound constraint before we
// gap_eps determines how close we have to get to a bound constraint before we
// start basically dropping it from the optimization and consider it to be an
// start basically dropping it from the optimization and consider it to be an
...
@@ -516,8 +530,10 @@ namespace dlib
...
@@ -516,8 +530,10 @@ namespace dlib
x
=
clamp
(
x
+
alpha
*
s
,
x_lower
,
x_upper
);
x
=
clamp
(
x
+
alpha
*
s
,
x_lower
,
x_upper
);
g
=
der
(
x
);
g
=
der
(
x
);
DLIB_ASSERT
(
is_finite
(
f_value
),
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
f_value
))
DLIB_ASSERT
(
is_finite
(
g
),
"The objective function generated non-finite outputs"
);
throw
error
(
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
g
))
throw
error
(
"The objective function generated non-finite outputs"
);
}
}
return
f_value
;
return
f_value
;
...
@@ -608,8 +624,10 @@ namespace dlib
...
@@ -608,8 +624,10 @@ namespace dlib
double
f_value
=
-
f
(
x
);
double
f_value
=
-
f
(
x
);
g
=
-
der
(
x
);
g
=
-
der
(
x
);
DLIB_ASSERT
(
is_finite
(
f_value
),
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
f_value
))
DLIB_ASSERT
(
is_finite
(
g
),
"The objective function generated non-finite outputs"
);
throw
error
(
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
g
))
throw
error
(
"The objective function generated non-finite outputs"
);
// gap_eps determines how close we have to get to a bound constraint before we
// gap_eps determines how close we have to get to a bound constraint before we
// start basically dropping it from the optimization and consider it to be an
// start basically dropping it from the optimization and consider it to be an
...
@@ -647,8 +665,10 @@ namespace dlib
...
@@ -647,8 +665,10 @@ namespace dlib
// unnegated version of f()
// unnegated version of f()
f_value
*=
-
1
;
f_value
*=
-
1
;
DLIB_ASSERT
(
is_finite
(
f_value
),
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
f_value
))
DLIB_ASSERT
(
is_finite
(
g
),
"The objective function generated non-finite outputs"
);
throw
error
(
"The objective function generated non-finite outputs"
);
if
(
!
is_finite
(
g
))
throw
error
(
"The objective function generated non-finite outputs"
);
}
}
return
-
f_value
;
return
-
f_value
;
...
...
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