Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
exercise_4
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cp1_ws19
exercise_4
Commits
8dda6192
Commit
8dda6192
authored
5 years ago
by
Kevin Höllring
Browse files
Options
Downloads
Patches
Plain Diff
Extend Optimizer interface
parent
df271d71
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/optimizer.h
+9
-4
9 additions, 4 deletions
include/optimizer.h
src/optimizer.cpp
+12
-2
12 additions, 2 deletions
src/optimizer.cpp
with
21 additions
and
6 deletions
include/optimizer.h
+
9
−
4
View file @
8dda6192
...
@@ -18,13 +18,14 @@ template <typename argtype, typename valtype> class Optimizer {
...
@@ -18,13 +18,14 @@ template <typename argtype, typename valtype> class Optimizer {
/*
/*
Class using the gradient descent method in order to minimize a given
Class using the gradient descent method in order to minimize a given
function by performing
a
the gradient descent with a given factor applied to
function by performing the gradient descent with a given factor applied to
the gradient at each step.
the gradient at each step.
*/
*/
class
GradientDescent
:
public
Optimizer
<
double
,
double
>
{
class
GradientDescent
:
public
Optimizer
<
double
,
double
>
{
public:
public:
GradientDescent
(
Differentiator
<
double
,
double
>&
_diff
,
double
_stepsize
)
GradientDescent
(
Differentiator
<
double
,
double
>&
_diff
,
double
_stepsize
,
:
diff
(
_diff
),
stepsize
(
_stepsize
)
{}
double
_diff_precision
)
:
diff
(
_diff
),
stepsize
(
_stepsize
),
diff_precision
(
_diff_precision
)
{}
Coordinate
<
double
>
optimize
(
Function
<
Coordinate
<
double
>
,
double
>&
func
,
Coordinate
<
double
>
optimize
(
Function
<
Coordinate
<
double
>
,
double
>&
func
,
Coordinate
<
double
>&
start
,
Coordinate
<
double
>&
start
,
...
@@ -32,7 +33,7 @@ class GradientDescent : public Optimizer<double, double> {
...
@@ -32,7 +33,7 @@ class GradientDescent : public Optimizer<double, double> {
protected
:
protected
:
Differentiator
<
double
,
double
>&
diff
;
Differentiator
<
double
,
double
>&
diff
;
double
stepsize
;
double
stepsize
,
diff_precision
;
};
};
/*
/*
...
@@ -69,6 +70,10 @@ class ConjugateGradient : public Optimizer<double, double> {
...
@@ -69,6 +70,10 @@ class ConjugateGradient : public Optimizer<double, double> {
Coordinate
<
double
>&
start
,
Coordinate
<
double
>&
start
,
double
precision
)
const
override
;
double
precision
)
const
override
;
Coordinate
<
double
>
CGstep
(
Function
<
Coordinate
<
double
>
,
double
>&
func
,
Coordinate
<
double
>&
start
,
double
precision
)
const
override
;
protected
:
protected
:
Differentiator
<
double
,
double
>&
diff
;
Differentiator
<
double
,
double
>&
diff
;
double
diff_precision
;
double
diff_precision
;
...
...
This diff is collapsed.
Click to expand it.
src/optimizer.cpp
+
12
−
2
View file @
8dda6192
...
@@ -2,13 +2,14 @@
...
@@ -2,13 +2,14 @@
using
namespace
numerics
;
using
namespace
numerics
;
/*
/*
For an explanation on what the three methods do see the exercise sheet, your
For an explanation on what the three methods do
,
see the exercise sheet, your
lecture notes as well as the
i
nternet :)
lecture notes
, the header file
as well as
possibly
the
I
nternet :)
*/
*/
Coordinate
<
double
>
Coordinate
<
double
>
GradientDescent
::
optimize
(
Function
<
Coordinate
<
double
>
,
double
>&
func
,
GradientDescent
::
optimize
(
Function
<
Coordinate
<
double
>
,
double
>&
func
,
Coordinate
<
double
>&
start
,
double
precision
)
const
{
Coordinate
<
double
>&
start
,
double
precision
)
const
{
// TODO Problem 1
return
start
;
return
start
;
}
}
...
@@ -16,11 +17,20 @@ Coordinate<double>
...
@@ -16,11 +17,20 @@ Coordinate<double>
GradientRootfinder
::
optimize
(
Function
<
Coordinate
<
double
>
,
double
>&
func
,
GradientRootfinder
::
optimize
(
Function
<
Coordinate
<
double
>
,
double
>&
func
,
Coordinate
<
double
>&
start
,
Coordinate
<
double
>&
start
,
double
precision
)
const
{
double
precision
)
const
{
// TODO Problem 2
return
start
;
return
start
;
}
}
Coordinate
<
double
>
Coordinate
<
double
>
ConjugateGradient
::
optimize
(
Function
<
Coordinate
<
double
>
,
double
>&
func
,
ConjugateGradient
::
optimize
(
Function
<
Coordinate
<
double
>
,
double
>&
func
,
Coordinate
<
double
>&
start
,
double
precision
)
const
{
Coordinate
<
double
>&
start
,
double
precision
)
const
{
// TODO Problem 3
return
start
;
}
Coordinate
<
double
>
ConjugateGradient
::
CGstep
(
Function
<
Coordinate
<
double
>
,
double
>&
func
,
Coordinate
<
double
>&
start
,
double
precision
)
const
{
// TODO Problem 3
return
start
;
return
start
;
}
}
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