diff --git a/include/optimizer.h b/include/optimizer.h index 6aa23d6050a43df7155bae4aa20c4385698e3be5..fa4aca370480cf7f3009aed0a5fc239a8a753bbd 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 8a16555516217069f2d6f330bb39cb7ed56b2af7..2595bce08b4806e6fc36ff468be52ff13c8ea1b7 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; }