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
77759efc
Commit
77759efc
authored
Apr 17, 2020
by
Erik Strand
Browse files
Options
Downloads
Patches
Plain Diff
Allow move semantics for Nelder-Mead
parent
26cbb2f5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
optimization/optimizers/nelder_mead/main.cpp
+2
-2
2 additions, 2 deletions
optimization/optimizers/nelder_mead/main.cpp
optimization/optimizers/nelder_mead/nelder_mead.h
+37
-36
37 additions, 36 deletions
optimization/optimizers/nelder_mead/nelder_mead.h
with
39 additions
and
38 deletions
optimization/optimizers/nelder_mead/main.cpp
+
2
−
2
View file @
77759efc
...
...
@@ -46,9 +46,9 @@ int main(int const argc, char const** argv) {
// Only log stuff if we're going to use it.
if
(
log_file_path
.
empty
()
&&
vis_file_path
.
empty
())
{
optimizer
.
optimize
(
objective
,
simplex
);
optimizer
.
optimize
(
objective
,
std
::
move
(
simplex
)
)
;
}
else
{
optimizer
.
optimize
(
objective
,
simplex
,
log
);
optimizer
.
optimize
(
objective
,
std
::
move
(
simplex
)
,
log
);
}
std
::
cout
<<
"n evaluations: "
<<
optimizer
.
n_evaluations
()
<<
'\n'
;
...
...
This diff is collapsed.
Click to expand it.
optimization/optimizers/nelder_mead/nelder_mead.h
+
37
−
36
View file @
77759efc
...
...
@@ -48,14 +48,17 @@ public:
}
Scalar
value
()
const
{
return
simplex_values_
[
i_lowest_
];
}
//
Constructs a simplex from an initial point by offsetting all coordinate values
.
// These
methods return the best point, as a reference to a column (like point())
.
//
All optimization methods return the best point, as a reference to a column (like point())
.
// These
two construct a simplex from an initial point by offsetting all coordinate values
.
template
<
typename
Objective
>
decltype
(
auto
)
optimize
(
Objective
&
objective
,
VectorD
const
&
initial_point
,
Scalar
offset
=
1
);
)
{
NelderMeadLogNothing
log
;
return
optimize
(
objective
,
initial_point
,
offset
,
log
);
}
template
<
typename
Objective
,
typename
Log
>
decltype
(
auto
)
optimize
(
Objective
&
objective
,
...
...
@@ -63,14 +66,34 @@ public:
Scalar
offset
,
Log
&
log
);
// Each column of simplex is a vertex.
// These four take a full simplex. Each column is a vertex.
template
<
typename
Objective
>
decltype
(
auto
)
optimize
(
Objective
&
objective
,
MatrixDN
const
&
simplex
);
decltype
(
auto
)
optimize
(
Objective
&
objective
,
MatrixDN
&&
simplex
)
{
NelderMeadLogNothing
log
;
return
optimize
(
objective
,
std
::
move
(
simplex
),
log
);
}
template
<
typename
Objective
,
typename
Log
>
decltype
(
auto
)
optimize
(
Objective
&
objective
,
MatrixDN
const
&
simplex
,
Log
&
log
);
decltype
(
auto
)
optimize
(
Objective
&
objective
,
MatrixDN
&&
simplex
,
Log
&
log
)
{
simplex_vertices_
=
std
::
move
(
simplex
);
return
optimize_impl
(
objective
,
log
);
}
template
<
typename
Objective
>
decltype
(
auto
)
optimize
(
Objective
&
objective
,
MatrixDN
const
&
simplex
)
{
NelderMeadLogNothing
log
;
return
optimize
(
objective
,
simplex
,
log
);
}
template
<
typename
Objective
,
typename
Log
>
decltype
(
auto
)
optimize
(
Objective
&
objective
,
MatrixDN
const
&
simplex
,
Log
&
log
)
{
simplex_vertices_
=
simplex
;
return
optimize_impl
(
objective
,
log
);
}
private
:
// Does the optimization assuming simplex_vertices_ has been initialized.
template
<
typename
Objective
,
typename
Log
>
decltype
(
auto
)
optimize_impl
(
Objective
&
objective
,
Log
&
log
);
// Helper method for optimize_impl.
template
<
typename
Objective
>
Scalar
try_new_point
(
Objective
&
objective
,
Scalar
factor
);
...
...
@@ -102,18 +125,6 @@ private:
static
constexpr
Scalar
tiny_
=
1e-10
;
};
//..................................................................................................
template
<
int32_t
D
>
template
<
typename
Objective
>
decltype
(
auto
)
NelderMead
<
D
>::
optimize
(
Objective
&
objective
,
VectorD
const
&
initial_point
,
Scalar
offset
)
{
NelderMeadLogNothing
log
;
return
optimize
(
objective
,
initial_point
,
offset
,
log
);
}
//..................................................................................................
template
<
int32_t
D
>
template
<
typename
Objective
,
typename
Log
>
...
...
@@ -123,30 +134,20 @@ decltype(auto) NelderMead<D>::optimize(
Scalar
offset
,
Log
&
log
)
{
MatrixDN
simplex
;
simplex
.
resize
(
initial_point
.
size
(),
initial_point
.
size
()
+
1
);
simplex
.
col
(
0
)
=
initial_point
;
simplex_vertices_
.
resize
(
initial_point
.
size
(),
initial_point
.
size
()
+
1
);
simplex_vertices_
.
col
(
0
)
=
initial_point
;
for
(
uint32_t
i
=
0
;
i
<
initial_point
.
size
();
++
i
)
{
simplex
.
col
(
i
+
1
)
=
initial_point
;
simplex
(
i
,
i
+
1
)
+=
offset
;
simplex
_vertices_
.
col
(
i
+
1
)
=
initial_point
;
simplex
_vertices_
(
i
,
i
+
1
)
+=
offset
;
}
return
optimize
(
objective
,
simplex
,
log
);
}
//..................................................................................................
template
<
int32_t
D
>
template
<
typename
Objective
>
decltype
(
auto
)
NelderMead
<
D
>::
optimize
(
Objective
&
objective
,
MatrixDN
const
&
simplex
)
{
NelderMeadLogNothing
log
;
return
optimize
(
objective
,
simplex
,
log
);
return
optimize_impl
(
objective
,
log
);
}
//..................................................................................................
template
<
int32_t
D
>
template
<
typename
Objective
,
typename
Log
>
decltype
(
auto
)
NelderMead
<
D
>::
optimize
(
Objective
&
objective
,
MatrixDN
const
&
simplex
,
Log
&
log
)
{
// initialize state
simplex_vertices_
=
simplex
;
decltype
(
auto
)
NelderMead
<
D
>::
optimize_impl
(
Objective
&
objective
,
Log
&
log
)
{
// initialize state, assuming simplex_vertices_ is already set
n_vertices_
=
simplex_vertices_
.
cols
();
dim_
=
simplex_vertices_
.
rows
();
assert
(
n_vertices_
==
dim_
+
1
);
...
...
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
sign in
to comment