PARP Research Group University of Murcia, Spain


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 
00073 class QVFunctionMinimizer
00074         {
00075         private:
00076                 int iterations;
00077                 bool useGoldenSection;
00078                 double actual, minimum, maximum;
00079 
00080                 static double static_function (const double v, void *functionMinimizerPtr);
00081 
00082         public: 
00086                 QVFunctionMinimizer(const bool useGoldenSection = true):
00087                         useGoldenSection(useGoldenSection), actual(0), minimum(-1), maximum(1)  { }
00088 
00095                 virtual double function(const double value) = 0;
00096 
00104                 void setStartingValue(const double value)                       { actual = value; }
00105 
00112                 void setSearchRange(const double min, const double max )        { minimum = min; maximum = max; }
00113 
00121                 const double & getMinimum()     const   { return actual; }
00122 
00130                 const int & getIterations()     const   { return iterations; }
00131 
00139                 bool iterate(const int maxIterations = 100, const double maxError = 0.00001);
00140         };
00141 
00142 #endif
00143 



QVision framework. PARP research group, copyright 2007, 2008.