src/qvmath/qvfunctionminimizer.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00024 
00025 #ifndef QVFUNCTIONMINIMIZER_H
00026 #define QVFUNCTIONMINIMIZER_H
00027 
00028 #include <qvmath.h>
00029 #include <QVVector>
00030 
00031 #include <gsl/gsl_errno.h>
00032 #include <gsl/gsl_math.h>
00033 #include <gsl/gsl_min.h>
00034 
00075 class QVFunctionMinimizer
00076         {
00077         private:
00078                 int iterations;
00079                 bool useGoldenSection;
00080                 double actual, minimum, maximum;
00081 
00082                 static double static_function (const double v, void *functionMinimizerPtr);
00083 
00084         public: 
00089                 QVFunctionMinimizer(const bool useGoldenSection = true):
00090                         useGoldenSection(useGoldenSection), actual(0), minimum(-1), maximum(1)  { }
00091 
00098                 virtual double function(const double value) = 0;
00099 
00107                 void setStartingValue(const double value)                       { actual = value; }
00108 
00115                 void setSearchRange(const double min, const double max )        { minimum = min; maximum = max; }
00116 
00124                 const double & getMinimum()     const   { return actual; }
00125 
00133                 const int & getIterations()     const   { return iterations; }
00134 
00144                 bool iterate(const int maxIterations = 100, const double maxError = 0.00001);
00145         };
00146 
00147 #endif
00148