Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
optimization
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Erik Strand
optimization
Commits
10658ad2
Commit
10658ad2
authored
5 years ago
by
Erik Strand
Browse files
Options
Downloads
Patches
Plain Diff
Add absolute bracket width termination condition
parent
341b55f4
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
optimization/optimizers/line_search/golden_section.h
+11
-4
11 additions, 4 deletions
optimization/optimizers/line_search/golden_section.h
with
11 additions
and
4 deletions
optimization/optimizers/line_search/golden_section.h
+
11
−
4
View file @
10658ad2
...
@@ -10,8 +10,12 @@ namespace optimization {
...
@@ -10,8 +10,12 @@ namespace optimization {
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
class
GoldenSection
{
class
GoldenSection
{
public:
public:
// Note: This tolerance default is suitable for double precision floats.
// Note:
GoldenSection
(
Scalar
tolerance
=
3e-8
)
:
tolerance_
(
tolerance
),
n_evaluations_
(
0
)
{}
// - the default absolute tolerance is equivalent to no absolute termination condition
// - the default relative tolerance is suitable for double precision floats
GoldenSection
(
Scalar
abs_tol
=
-
1
,
Scalar
rel_tol
=
3e-8
)
:
abs_tol_
(
abs_tol
),
rel_tol_
(
rel_tol
),
n_evaluations_
(
0
)
{}
uint32_t
n_evaluations
()
const
{
return
n_evaluations_
;
}
uint32_t
n_evaluations
()
const
{
return
n_evaluations_
;
}
...
@@ -19,7 +23,10 @@ public:
...
@@ -19,7 +23,10 @@ public:
Sample
<
Scalar
>
optimize
(
Objective
const
&
objective
,
Bracket
const
&
bracket
);
Sample
<
Scalar
>
optimize
(
Objective
const
&
objective
,
Bracket
const
&
bracket
);
private
:
private
:
Scalar
tolerance_
;
// Goal for absolute width of the bracket. Put a negative number if you want to abs tol.
Scalar
abs_tol_
;
// Goal for width of bracket relative to central value. Should always have this.
Scalar
rel_tol_
;
uint32_t
n_evaluations_
;
uint32_t
n_evaluations_
;
static
constexpr
Scalar
golden_ratio_big_
=
0.618034
;
static
constexpr
Scalar
golden_ratio_big_
=
0.618034
;
...
@@ -65,7 +72,7 @@ Sample<Scalar> GoldenSection::optimize(Objective const& objective, Bracket const
...
@@ -65,7 +72,7 @@ Sample<Scalar> GoldenSection::optimize(Objective const& objective, Bracket const
// Keep interpolating until our bracket is sufficiently tight.
// Keep interpolating until our bracket is sufficiently tight.
// See Numerical Recipes for the thought behind this particular test.
// See Numerical Recipes for the thought behind this particular test.
while
(
x_3
-
x_0
>
tolerance
_
*
(
std
::
abs
(
x_1
)
+
std
::
abs
(
x_2
)))
{
while
(
x_3
-
x_0
>
abs_tol_
&&
x_3
-
x_0
>
rel_tol
_
*
(
std
::
abs
(
x_1
)
+
std
::
abs
(
x_2
)))
{
if
(
y_2
<
y_1
)
{
if
(
y_2
<
y_1
)
{
// x_1 is our new left edge; interpolate between x_2 and x_3
// x_1 is our new left edge; interpolate between x_2 and x_3
shift
(
x_0
,
x_1
,
x_2
,
golden_ratio_big_
*
x_2
+
golden_ratio_small_
*
x_3
);
shift
(
x_0
,
x_1
,
x_2
,
golden_ratio_big_
*
x_2
+
golden_ratio_small_
*
x_3
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment