![]() |
University of Murcia ![]() |
Numerical analisis and function minimizationFunction optimization, numerical derivatives,.
More... |
Classes | |
class | QVFunction< Input, Output > |
Base class for function objects. More... | |
Enumerations | |
enum | GSLMinFMinimizer { GoldenSection = 0, BrentMinimization = 1 } |
GSL Minimization algorithms. More... | |
enum | GSLMultiminFDFMinimizerType { ConjugateFR = 0, ConjugatePR = 1, VectorBFGS = 2, SteepestDescent = 3 } |
GSL multidimensional minimization algorithms using gradient information. More... | |
Functions | |
const QVVector | qvEstimateGradient (const QVFunction< QVVector, double > &function, const QVVector &point, const double h=1e-6) |
Estimates the gradient vector for the function using the forward two-points rule for the derivative approximation. | |
const QVMatrix | qvEstimateHessian (const QVFunction< QVVector, double > &function, const QVVector &point, const double h=1e-3) |
Estimates the hessian matrix for the function using the forward two-point rule for the derivative approximation. | |
const bool | qvGSLMinimizeFDF (QVFunction< QVVector, double > &function, QVVector &point, const GSLMultiminFDFMinimizerType gslMinimizerAlgorithm=ConjugateFR, const int maxIterations=100, const double maxGradientNorm=1e-3, const double step=0.01, const double tol=1e-4) |
Wrapper to GSL multivariate function minimization using gradient information. | |
const bool | qvGSLMinimizeFDF (QVFunction< QVVector, double > &function, QVFunction< QVVector, QVVector > &gradientFunction, QVVector &point, const GSLMultiminFDFMinimizerType gslMinimizerAlgorithm=ConjugateFR, const int maxIterations=100, const double maxGradientNorm=1e-3, const double step=0.01, const double tol=1e-4) |
Wrapper to GSL multivariate function minimization using gradient information. | |
const bool | qvGSLMinimize (QVFunction< double, double > &function, double &x, double &lower, double &upper, const GSLMinFMinimizer gslMinimizerAlgorithm=BrentMinimization, const int maxIterations=100, const double absoluteError=1e-3, const double relativeError=0.0) |
Wrapper to GSL function minimization. |
enum GSLMinFMinimizer |
GSL Minimization algorithms.
Definition at line 77 of file qvnumericalanalysis.h.
GSL multidimensional minimization algorithms using gradient information.
Definition at line 92 of file qvnumericalanalysis.h.
const QVVector qvEstimateGradient | ( | const QVFunction< QVVector, double > & | function, | |
const QVVector & | point, | |||
const double | h = 1e-6 | |||
) |
Estimates the gradient vector for the function using the forward two-points rule for the derivative approximation.
This function obtains a numerical approximation of the gradient at a given point for a function. The forward derivative formula is used to estimate each partial derivative value, component of the gradient vector:
The function to estimate the gradient is provided as a QVFunction object.
function | object containing the function to estimate gradient. | |
point | Point to evaluate the gradient vector. | |
h | Increment coeficient for the derivative formula. |
Definition at line 28 of file qvnumericalanalysis.cpp.
Referenced by qvEstimateHessian().
const QVMatrix qvEstimateHessian | ( | const QVFunction< QVVector, double > & | function, | |
const QVVector & | point, | |||
const double | h = 1e-3 | |||
) |
Estimates the hessian matrix for the function using the forward two-point rule for the derivative approximation.
This function obtains a numerical approximation of the hessian matrix at a given pointfor a function. The following formula is used to compute the components fo the hessian matrix:
It is derived from the forward derivative formula used to estimate each partial derivative value:
The function to estimate the hessian is provided as a QVFunction object.
function | object containing the function to estimate hessian. | |
point | Point to evaluate the hessian matrix. | |
h | Increment coeficient for the derivative formula. |
Definition at line 42 of file qvnumericalanalysis.cpp.
const bool qvGSLMinimize | ( | QVFunction< double, double > & | function, | |
double & | x, | |||
double & | lower, | |||
double & | upper, | |||
const GSLMinFMinimizer | gslMinimizerAlgorithm = BrentMinimization , |
|||
const int | maxIterations = 100 , |
|||
const double | absoluteError = 1e-3 , |
|||
const double | relativeError = 0.0 | |||
) |
Wrapper to GSL function minimization.
This function uses the GSL to obtain the minimum of a function, provided in a QVFunction object. An example code usage follows:
#include <qvnumericalanalysis.h> // Creation of a sinoidal function class type class SinoidalFunction: public QVFunction<double, double> { private: double evaluate(const double &x) const { return cos(x) + 1.0; } public: SinoidalFunction(): QVFunction<double, double>() { }; }; int main(int argc, char *argv[]) { const SinoidalFunction function; double x = 2.0, lower = 0.0, upper = 6.0; qvGSLMinimize(function, x, lower, upper); printf ("Minimum found at %.7f\n", x); exit(0); }
function | Object containing the function to minimize. | |
x | Starting value for the minimization. This variable will contain the obtained minimum when the function returns. | |
gslMinimizerAlgorithm | Minimization algorithm. See enumeration GSLMinFMinimizer for possible values. | |
lower | Minimal value for the search range. | |
upper | Maximum value for the search range. | |
maxIterations | Maximum number of steps to perform the minimization. | |
maxGradientNorm | Minimal value of the gradient size (norm 2) to stop the minimization when reached. | |
absoluteError | Corresponds to parameter epsabs for the gsl_min_test_interval function. | |
relativeError | Corresponds to parameter epsrel for the gsl_min_test_interval function. |
Definition at line 210 of file qvnumericalanalysis.cpp.
const bool qvGSLMinimizeFDF | ( | QVFunction< QVVector, double > & | function, | |
QVFunction< QVVector, QVVector > & | gradientFunction, | |||
QVVector & | point, | |||
const GSLMultiminFDFMinimizerType | gslMinimizerAlgorithm = ConjugateFR , |
|||
const int | maxIterations = 100 , |
|||
const double | maxGradientNorm = 1e-3 , |
|||
const double | step = 0.01 , |
|||
const double | tol = 1e-4 | |||
) |
Wrapper to GSL multivariate function minimization using gradient information.
This is an overloaded version of the function qvGSLMinimizeFDF(QVFunction<QVVector, double> &, QVVector &, const GSLMultiminFDFMinimizerType, const int, const double, const double, const double) provided for convenience.
The real gradient of the function is used in the form of a vector function object, instead of the numerical approximation qvEstimateGradient to the gradient, which is less accurate and generally less efficient. An example code usage follows:
#include <qvnumericalanalysis.h> // Creation of a quadratic function class type class QuadraticFunction: public QVFunction<QVVector, double> { private: const QVMatrix A; const QVVector b; const double c; double evaluate(const QVVector &x) const { return x*A*x + b*x + c; } public: QuadraticFunction(const QVMatrix &A, const QVVector &b, const double c): QVFunction<QVVector, double>(), A(A), b(b), c(c) { } }; // Creation of a quadratic vector function class type, corresponding to the gradient of the previous function class QuadraticFunctionGradient: public QVFunction<QVVector, QVVector> { private: const QVMatrix A; const QVVector b; const double c; QVVector evaluate(const QVVector &x) const { return A*x*2 + b; } public: QuadraticFunctionGradient(const QVMatrix &A, const QVVector &b, const double c): QVFunction<QVVector, QVVector>(), A(A), b(b), c(c) { } }; // Main code int main() { // Example quadratic function and corresponding gradient objects creation QVMatrix A = QVMatrix::zeros(3,3); QVVector b = QVVector(3,0); double c; A(0,0) = 70; A(1,1) = 11; A(2,2) = 130; b = QVVector(3); b[0] = -100; b[1] = 20; b[2] = -30; c = 100; QuadraticFunction f(A, b, c); QuadraticFunctionGradient g(A, b, c); // Function minimization QVVector minimum(3,0); qvGSLMinimizeFDF(f, g, minimum); std::cout << "Function minimum value = " << f(minimum) << std::endl; std::cout << "Reached at point = " << minimum << std::endl; }
function | Object containing the function to minimize. | |
gradientFunction | Object containing the gradient vector function. | |
point | Starting point for the minimization. This vector will contain the obtained minimum when the function returns. | |
gslMinimizerAlgorithm | Minimization algorithm. See enumeration GSLMultiminFDFMinimizerType for possible values. | |
maxIterations | Maximum number of steps to perform the minimization. | |
maxGradientNorm | Minimal value of the gradient size (norm 2) to stop the minimization when reached. | |
step | Corresponds to parameter step for the gsl_multimin_fdfminimizer_set function. | |
tol | Corresponds to parameter tol for the gsl_multimin_fdfminimizer_set function. |
Definition at line 151 of file qvnumericalanalysis.cpp.
const bool qvGSLMinimizeFDF | ( | QVFunction< QVVector, double > & | function, | |
QVVector & | point, | |||
const GSLMultiminFDFMinimizerType | gslMinimizerAlgorithm = ConjugateFR , |
|||
const int | maxIterations = 100 , |
|||
const double | maxGradientNorm = 1e-3 , |
|||
const double | step = 0.01 , |
|||
const double | tol = 1e-4 | |||
) |
Wrapper to GSL multivariate function minimization using gradient information.
This function minimizes a multivariate function contained in a QVFunction object, using the GSL functionality for that purpose. The gradient of that function is estimated using the qvEstimateGradient function, and is used in the minimization process.
An usage example follows:
#include <qvnumericalanalysis.h> // Creation of a quadratic function class type class QuadraticFunction: public QVFunction<QVVector, double> { private: const QVMatrix A; const QVVector b; const double c; double evaluate(const QVVector &x) const { return x*A*x + b*x + c; } public: QuadraticFunction(const QVMatrix &A, const QVVector &b, const double c): QVFunction<QVVector, double>(), A(A), b(b), c(c) { } }; // Main code int main() { // Example quadratic function object creation QVMatrix A = QVMatrix::zeros(3,3); QVVector b = QVVector(3,0); double c; A(0,0) = 70; A(1,1) = 11; A(2,2) = 130; b = QVVector(3); b[0] = -100; b[1] = 20; b[2] = -30; c = 100; QuadraticFunction f(A, b, c); // Function minimization QVVector minimum(3,0); qvGSLMinimizeFDF(f, minimum); std::cout << "Function minimum value = " << f(minimum) << std::endl; std::cout << "Reached at point = " << minimum << std::endl;; }
function | Object containing the function to minimize. | |
point | Starting point for the minimization. This vector will contain the obtained minimum when the function returns. | |
gslMinimizerAlgorithm | Minimization algorithm. See enumeration GSLMultiminFDFMinimizerType for possible values. | |
maxIterations | Maximum number of steps to perform by the minimization. | |
maxGradientNorm | Minimal value of the gradient size (norm 2) to stop the minimization when reached. | |
step | Corresponds to parameter step for the gsl_multimin_fdfminimizer_set function. | |
tol | Corresponds to parameter tol for the gsl_multimin_fdfminimizer_set function. |
Definition at line 84 of file qvnumericalanalysis.cpp.
Referenced by GetPinholeCameraIntrinsicsFromPlanarHomography().