#include <qvmath/qvfunctionminimizer.h>
Public Member Functions | |
QVFunctionMinimizer (const bool useGoldenSection=true) | |
Constructor for the class. | |
virtual double | function (const double value)=0 |
Function to be optimized. | |
void | setStartingValue (const double value) |
Specifies the search starting value. | |
void | setSearchRange (const double min, const double max) |
Specifies the search range. | |
const double & | getMinimum () const |
Returns the minimum obtained in the last search. | |
const int & | getIterations () const |
Number of iterations elapsed in the last search. | |
bool | iterate (const int maxIterations=100, const double maxError=0.00001) |
Launchs a minimization search. |
This is a baseclass to create function minimizator objects. It is based on the GSL functionality for that matter.
An example subclass for QVFunctionMinimization follows:
class FMinimizer: public QVFunctionMinimizer { public: fMinimizer(): QVFunctionMinimizer() {} double function(double value) { return f(value); } // Or whatever the function is. }
The following code ilustrates the usage of this class to perform optimization for function f
[...] // We create the minimization object FMinimizer fMinimizer; // and start a minimization search of 100 iterations if (fMinimizer.iterate(100)) std::cout << "The search found a minimum at value " << fMinimizer.getMinimum() << std::endl; else std::cout << "No minimum could be found." << std::endl; [...]
Definition at line 74 of file qvfunctionminimizer.h.
QVFunctionMinimizer::QVFunctionMinimizer | ( | const bool | useGoldenSection = true |
) | [inline] |
Constructor for the class.
useGolenSection | explain ??? |
Definition at line 88 of file qvfunctionminimizer.h.
virtual double QVFunctionMinimizer::function | ( | const double | value | ) | [pure virtual] |
Function to be optimized.
This method should be implemented by the subclass containing the function to be minimized.
value | value to evaluate the function. |
void QVFunctionMinimizer::setStartingValue | ( | const double | value | ) | [inline] |
Specifies the search starting value.
The search will start looking for the minimum around it. By default this value is set to 0 when the minimizer object is constructed.
value | the starting search value. |
Definition at line 106 of file qvfunctionminimizer.h.
void QVFunctionMinimizer::setSearchRange | ( | const double | min, | |
const double | max | |||
) | [inline] |
Specifies the search range.
The search will constrain to the given range. By default this range is [-1,1].
value | the starting search value. |
Definition at line 114 of file qvfunctionminimizer.h.
const double& QVFunctionMinimizer::getMinimum | ( | ) | const [inline] |
Returns the minimum obtained in the last search.
After a successful search started with function iterate, this method return the minimum value obtained in it, if the search was successful.
Definition at line 123 of file qvfunctionminimizer.h.
const int& QVFunctionMinimizer::getIterations | ( | ) | const [inline] |
Number of iterations elapsed in the last search.
This will return the number of iterations which took to the last search (started with function iterate) to find a minimum, or stopping, if none was found.
Definition at line 132 of file qvfunctionminimizer.h.
bool QVFunctionMinimizer::iterate | ( | const int | maxIterations = 100 , |
|
const double | maxError = 0.00001 | |||
) |
Launchs a minimization search.
This method will start a new search.
maxIteration | maximum number of steps to perform in the search | |
maxError | maximum ????? |
Definition at line 34 of file qvfunctionminimizer.cpp.