![]() |
University of Murcia, Spain ![]() |
QVFunctionMinimizer Class ReferenceWrapper class for GSL function minimization.
More...
|
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.
To use this class, a subclass must be created containing the function to be optimized. Method function should be redefined in the subclass with the code for that function. An example subclass for QVFunctionMinimization usage 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; [...]
Parameter useGoldenSection in the constructor indicates which of the two minimization algorithms implemented in the GSL will be used to perform the minimization: the Golden Section algorithm, or the Brent minimization algorithm.
Definition at line 73 of file qvfunctionminimizer.h.
QVFunctionMinimizer::QVFunctionMinimizer | ( | const bool | useGoldenSection = true |
) | [inline] |
Constructor for the class.
useGolenSection | indicates wether the minimization algorithm used should be the Golden Section or the Brent algorithm. |
Definition at line 86 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 104 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 112 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 121 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 130 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 | maximal relative error admisible for the solution. The minimization will stop when reached. |
Definition at line 34 of file qvfunctionminimizer.cpp.