Skip to content
Snippets Groups Projects
Commit 8dda6192 authored by Kevin Höllring's avatar Kevin Höllring
Browse files

Extend Optimizer interface

parent df271d71
No related branches found
No related tags found
No related merge requests found
...@@ -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;
......
...@@ -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 internet :) lecture notes, the header file as well as possibly the Internet :)
*/ */
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;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment