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
c459c082
Commit
c459c082
authored
Apr 12, 2020
by
Erik Strand
Browse files
Options
Downloads
Patches
Plain Diff
Remove debug prints
parent
96a2b406
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/plots.py
+1
-2
1 addition, 2 deletions
apps/plots.py
optimization/optimizers/nelder_mead/main.cpp
+5
-5
5 additions, 5 deletions
optimization/optimizers/nelder_mead/main.cpp
optimization/optimizers/nelder_mead/nelder_mead.h
+2
-20
2 additions, 20 deletions
optimization/optimizers/nelder_mead/nelder_mead.h
with
8 additions
and
27 deletions
apps/plots.py
+
1
−
2
View file @
c459c082
...
...
@@ -90,8 +90,7 @@ if __name__ == "__main__":
data
=
vis_json
[
"
data
"
]
if
objective
==
"
rosenbrock
"
:
#fig, ax = rosenbrock_plot(-3, 3, -3, 3)
fig
,
ax
=
rosenbrock_plot
(
-
1
,
1
,
-
1
,
1
)
fig
,
ax
=
rosenbrock_plot
(
-
3
,
3
,
-
3
,
3
)
# need to implement this
#elif objective == "paraboloid":
# fig, ax = paraboloid_plot(-3, 3, -3, 3)
...
...
This diff is collapsed.
Click to expand it.
optimization/optimizers/nelder_mead/main.cpp
+
5
−
5
View file @
c459c082
...
...
@@ -29,15 +29,15 @@ int main(int const argc, char const** argv) {
}
Eigen
::
Matrix
<
Scalar
,
2
,
3
>
simplex
;
simplex
.
col
(
0
)
=
Vector2s
(
-
1
,
0
);
simplex
.
col
(
1
)
=
Vector2s
(
-
0.8
,
0
);
simplex
.
col
(
2
)
=
Vector2s
(
-
0.8
,
0
.2
);
simplex
.
col
(
0
)
=
Vector2s
(
-
2
,
-
1
);
simplex
.
col
(
1
)
=
Vector2s
(
-
1
,
-
1
);
simplex
.
col
(
2
)
=
Vector2s
(
-
2
,
0
);
//using Objective = Paraboloid<Vector2<Scalar>>;
//Objective objective(dim);
using
Objective
=
Rosenbrock
<
Vector2s
>
;
Objective
objective
;
NelderMead
<
Objective
,
-
1
>
optimizer
(
max_evaluations
,
relative_y_tolerance
);
NelderMead
<
Objective
,
2
>
optimizer
(
max_evaluations
,
relative_y_tolerance
);
optimizer
.
optimize
(
objective
,
simplex
);
if
(
!
log_file_path
.
empty
())
{
...
...
@@ -47,7 +47,7 @@ int main(int const argc, char const** argv) {
}
if
(
!
vis_file_path
.
empty
())
{
json
data
=
NelderMeadVis
<
Objective
,
-
1
>
{
optimizer
};
json
data
=
NelderMeadVis
<
Objective
,
2
>
{
optimizer
};
std
::
ofstream
vis_file
(
vis_file_path
);
vis_file
<<
data
.
dump
(
4
)
<<
'\n'
;
}
...
...
This diff is collapsed.
Click to expand it.
optimization/optimizers/nelder_mead/nelder_mead.h
+
2
−
20
View file @
c459c082
...
...
@@ -62,8 +62,6 @@ private:
template
<
typename
Objective
,
int32_t
D
>
auto
NelderMead
<
Objective
,
D
>::
optimize
(
Objective
const
&
objective
,
MatrixDN
const
&
simplex
)
->
VectorD
{
simplex_vertices_
=
simplex
;
std
::
cout
<<
"sv rows: "
<<
simplex_vertices_
.
rows
()
<<
'\n'
;
std
::
cout
<<
"sv cols: "
<<
simplex_vertices_
.
cols
()
<<
'\n'
;
n_vertices_
=
simplex_vertices_
.
cols
();
dim_
=
simplex_vertices_
.
rows
();
assert
(
n_vertices_
==
dim_
+
1
);
...
...
@@ -113,16 +111,11 @@ auto NelderMead<Objective, D>::optimize(Objective const& objective, MatrixDN con
}
// Try reflecting the worst point.
std
::
cout
<<
"========================================
\n
"
;
std
::
cout
<<
"reflect
\n
"
;
Scalar
const
y_1
=
try_new_point
(
objective
,
reflection_coefficient_
);
std
::
cout
<<
"new val "
<<
y_1
<<
"
\n
"
;
// If the new point is the best so far, try going further in the same direction (expansion).
if
(
y_1
<=
simplex_values_
[
i_lowest_
])
{
std
::
cout
<<
"expand
\n
"
;
Scalar
const
y_2
=
try_new_point
(
objective
,
expansion_coefficient_
);
std
::
cout
<<
"new val "
<<
y_2
<<
"
\n
"
;
try_new_point
(
objective
,
expansion_coefficient_
);
continue
;
}
...
...
@@ -133,10 +126,8 @@ auto NelderMead<Objective, D>::optimize(Objective const& objective, MatrixDN con
// If the reflected point is still the worst, try contracting along one dimension.
// Note that we could be contracting from the original point, or the reflected point.
std
::
cout
<<
"contract
\n
"
;
Scalar
const
y_hi
=
simplex_values_
[
i_highest_
];
Scalar
const
y_2
=
try_new_point
(
objective
,
contraction_coefficient_
);
std
::
cout
<<
"new val "
<<
y_2
<<
"
\n
"
;
// If the contracted point is better than the worst, keep it.
if
(
y_2
<
y_hi
)
{
...
...
@@ -144,7 +135,6 @@ auto NelderMead<Objective, D>::optimize(Objective const& objective, MatrixDN con
}
// If the contracted point is even worse, shrink everything.
std
::
cout
<<
"shrink
\n
"
;
for
(
uint32_t
i
=
0
;
i
<
n_vertices_
;
++
i
)
{
if
(
i
!=
i_lowest_
)
{
simplex_vertices_
.
col
(
i
)
=
...
...
@@ -164,15 +154,7 @@ Scalar NelderMead<Objective, D>::try_new_point(Objective const& objective, Scala
// Generate a new point by reflecting/expanding/contracting the worst point.
Scalar
const
t1
=
(
Scalar
(
1
)
-
factor
)
/
dim_
;
Scalar
const
t2
=
factor
-
t1
;
std
::
cout
<<
"vs size: "
<<
vertex_sum_
.
size
()
<<
'\n'
;
std
::
cout
<<
"sv rows: "
<<
simplex_vertices_
.
cols
()
<<
'\n'
;
std
::
cout
<<
"sv cols: "
<<
simplex_vertices_
.
rows
()
<<
'\n'
;
std
::
cout
<<
"vs: "
<<
vertex_sum_
.
size
()
<<
'\n'
;
std
::
cout
<<
"row: "
<<
simplex_vertices_
.
col
(
i_highest_
).
size
()
<<
'\n'
;
std
::
cout
<<
"vs2: "
<<
(
t1
*
vertex_sum_
).
size
()
<<
'\n'
;
std
::
cout
<<
"row2: "
<<
(
t2
*
simplex_vertices_
.
col
(
i_highest_
)).
size
()
<<
'\n'
;
auto
x_new_hm
=
t1
*
vertex_sum_
+
t2
*
simplex_vertices_
.
col
(
i_highest_
);
VectorD
const
x_new
=
x_new_hm
;
VectorD
const
x_new
=
t1
*
vertex_sum_
+
t2
*
simplex_vertices_
.
col
(
i_highest_
);
// Evaluate the new point.
Scalar
y_new
;
...
...
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