From 8dda6192deb9bae79a91c71f8325c37b090e5512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20H=C3=B6llring?= <kevin.hoellring@fau.de> Date: Mon, 25 Nov 2019 02:29:13 +0100 Subject: [PATCH] Extend Optimizer interface --- include/optimizer.h | 13 +++++++++---- src/optimizer.cpp | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/optimizer.h b/include/optimizer.h index 6aa23d6..fa4aca3 100644 --- a/include/optimizer.h +++ b/include/optimizer.h @@ -18,13 +18,14 @@ template <typename argtype, typename valtype> class Optimizer { /* 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. */ class GradientDescent : public Optimizer<double, double> { public: - GradientDescent(Differentiator<double, double>& _diff, double _stepsize) - : diff(_diff), stepsize(_stepsize) {} + GradientDescent(Differentiator<double, double>& _diff, double _stepsize, + double _diff_precision) + : diff(_diff), stepsize(_stepsize), diff_precision(_diff_precision) {} Coordinate<double> optimize(Function<Coordinate<double>, double>& func, Coordinate<double>& start, @@ -32,7 +33,7 @@ class GradientDescent : public Optimizer<double, double> { protected: Differentiator<double, double>& diff; - double stepsize; + double stepsize, diff_precision; }; /* @@ -69,6 +70,10 @@ class ConjugateGradient : public Optimizer<double, double> { Coordinate<double>& start, double precision) const override; + Coordinate<double> CGstep(Function<Coordinate<double>, double>& func, + Coordinate<double>& start, + double precision) const override; + protected: Differentiator<double, double>& diff; double diff_precision; diff --git a/src/optimizer.cpp b/src/optimizer.cpp index 8a16555..2595bce 100644 --- a/src/optimizer.cpp +++ b/src/optimizer.cpp @@ -2,13 +2,14 @@ using namespace numerics; /* - For an explanation on what the three methods do see the exercise sheet, your - lecture notes as well as the internet :) + For an explanation on what the three methods do, see the exercise sheet, your + lecture notes, the header file as well as possibly the Internet :) */ Coordinate<double> GradientDescent::optimize(Function<Coordinate<double>, double>& func, Coordinate<double>& start, double precision) const { + // TODO Problem 1 return start; } @@ -16,11 +17,20 @@ Coordinate<double> GradientRootfinder::optimize(Function<Coordinate<double>, double>& func, Coordinate<double>& start, double precision) const { + // TODO Problem 2 return start; } Coordinate<double> ConjugateGradient::optimize(Function<Coordinate<double>, double>& func, 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; } -- GitLab