PARP Research Group University of Murcia, Spain


Numerical analisis and function minimization
[Math extensions]

Function optimization, numerical derivatives,. More...

Classes

class  QVFunction< Input, Output >
 Base class for function objects. More...

Enumerations

enum  GSLMultiminFDFMinimizerType { ConjugateFR = 0, ConjugatePR = 1, VectorBFGS = 2, SteepestDescent = 3 }
 GSL 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 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 function minimization using gradient information.

Detailed Description

Function optimization, numerical derivatives,.


Enumeration Type Documentation

GSL Minimization algorithms using gradient information.

See also:
qvGSLMinimizeFDF
Enumerator:
ConjugateFR  Fletcher-Reeves conjugate gradient algorithm.
ConjugatePR  Polak-Ribiere conjugate gradient algorithm.
VectorBFGS  Broyden-Fletcher-Goldfarb-Shanno (BFGS) algorithm.
SteepestDescent  The steepest descent algorithm.

Definition at line 77 of file qvnumericalanalysis.h.


Function Documentation

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:

$ \frac{ \partial f}{ \partial x_i} \left( \textbf{x} \right) = \lim_{h\to 0}{f(x_1, \ldots, x_i + h, \ldots, x_n)-f(x_1, \ldots, x_i, \ldots, x_n)\over h}$

The function to estimate the gradient is provided as a QVFunction object.

Parameters:
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.

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:

$ H_{i, j}(f) = \frac{ f(x_1, \ldots, x_i + h, \ldots, x_j + h, \ldots, x_n) + f(x_1, \ldots, x_i, \ldots, x_j, \ldots, x_n) f(x_1, \ldots, x_i + h, \ldots, x_j, \ldots, x_n) + f(x_1, \ldots, x_i, \ldots, x_j + h, \ldots, x_n) }{h^2}$

It is derived from the forward derivative formula used to estimate each partial derivative value:

$ \frac{ \partial f}{ \partial x_i} \left( \textbf{x} \right) = \lim_{h\to 0}{f(x_1, \ldots, x_i + h, \ldots, x_n)-f(x_1, \ldots, x_i, \ldots, x_n)\over h}$

The function to estimate the hessian is provided as a QVFunction object.

Parameters:
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 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 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;
        }

Parameters:
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 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.
Returns:
True if the search was successful. False else.
See also:
qvGSLMinimizeFDF(QVFunction<QVVector, double> &, QVVector &, const GSLMultiminFDFMinimizerType, const int, const double, const double, const double)

GSLMultiminFDFMinimizerType

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 function minimization using gradient information.

This function minimizes a multivariate function contained in a QVFunction object, using the GSL functionallity 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;;
        }

Parameters:
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.
Returns:
True if the search was successful. False else.
See also:
GSLMultiminFDFMinimizerType

Definition at line 84 of file qvnumericalanalysis.cpp.




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