`#include <cstdio>`

`#include <cmath>`

`#include <limits>`

Include dependency graph for Uncmin.h:

Go to the source code of this file.

## Classes | |

class | Uncmin< V, M, FUNC > |

This software is available at http://www.smallwaters.com/software/cpp/uncmin.html

Version 0080309 This release updates original work by Brad Hanson (http://www.b-a-h.com/) in 2001.

The UNCMIN routines are based on Appendix A of:

Dennis, J. E., & Schnabel, R. B. (1996). Numerical methods for unconstrained optimization and nonlinear equations. Philadelphia: Society for Industrual and Applied Mathematics.

The original UNCMIN routines in FORTRAN are available from GAMS (http://gams.nist.gov/) as OPTIF9 and OPTIF0.

FORTRAN UNCMIN routines were translated to java (Uncmin_f77.java) by Steve Verrill (steve@ws13.fpl.fs.fed.us). Uncmin_F77.java is available at http://www1.fpl.fs.fed.us/optimization.html

The routines in Uncmin_f77.java were translated to C++ by Brad Hanson.

(c) 2008, Werner Wothke, maintenance programming and documentation.

Uncmin is a templated class with template parameters:

V - A vector class of double precision numbers. Member functions that should be defined for class V are:

V& operator=(const V &A); // assignment

V& operator=(const double& scalar); // assign a value to all elements

double& operator()(int i); // FORTRAN style one-offset subscripting

int size(); // returns number of elements in vector

M - A matrix class of double precision numbers. Member functions that should be defined for class M are:

double operator()(int i, int j); // FORTRAN style one-offset subscripting

int num_rows(); // returns number of rows in matrix int num_cols(); // returns number of columns in matrix

FUNC - A class defining the function to minimize, its gradient and hessian. An example of how this class should be defined is:

V is vector class, M is matrix class template <class V, class M> class minclass { double f_to_minimize(V &x); Returns value of function to minimize

void gradient(V &x, V &g); Returns gradient of function in g. This does not have to be defined, in which case the gradient is approximated. If the gradient is not defined Analytic_Gradient should return 0;

void hessian(V &x, M &h); Returns hessian of function in h. This does not have to be defined, in which case the hessian is approximated. If the hessian is not defined Analytic_Hessian should return 0;

int HasAnalyticGradient(); Returns 1 if gradient is defined, otherwise returns 0

int HasAnalyticHessian(); Returns 1 if hessian is defined, otherwise returns 0

int ValidParameters(V &x); Returns 1 if f_to_minimize(x) is defined for argument x.

int dim(); Returns dimension of problem (number of elements in vector x passed to f_to_minimize) }

An example of how to use Uncmin to minimize a function defined in a class minclass with vector and matrix classes from the Simple C++ Numerical Toolkit (http://www.smallwaters.com/software/cpp/scppnt.html):

include "Uncmin.h" include "vec.h" // Simple C++ Numeric Toolkit (SCPPNT) vector class include "cmat.h" // Simple C++ Numeric Toolkit (SCPPNT) matrix class include <cstdio>

using namespace SCPPNT;

Dimension of problem (number of parameters) const int dim = 4;

Create function object minclass<Vector<double>, Matrix<double> > test;

create Uncmin object Uncmin<Vector<double>, Matrix<double>, minclass> min(&test);

Starting values double start_values[4] = {1.0, 1.0, 1.0, 1.0}; // use some appropriate values here Vector<double> start(start_values, start_values+dim);

xpls will contain solution, gpls will contain gradient at solution after call to min.Minimize Vector<double> xpls(dim), gpls(dim);

fpls contains the value of the function at the solution given by xpls. double fpls;

Minimize function. Minimize returns zero if successful (0, 1, 2, 3 returned by GetMessage), non-zero if not successful. if (min.Minimize(start, xpls, fpls, gpls)) { int msg = min.GetMessage(); // find out what went wrong std::printf("\nMessage returned from Uncmin: %d\n", msg); }

The GetMessage member function returns the status of the solution found by the last call to the Minimize member function. Possible values returned by GetMessage are:

0 = Optimal solution found, terminated with gradient small 1 = Terminated with gradient small, xpls is probably optimal. 2 = Terminated with stepsize small, xpls is probably optimal. 3 = Lower point cannot be found, xpls is probably optimal. 4 = Iteration limit (default 150) exceeded. 5 = Too many large steps, function may be unbounded. -1 = Analytic gradient check requested, but no analytic gradient supplied -2 = Analytic hessian check requested, but no analytic hessian supplied -3 = Illegal dimension -4 = Illegal tolerance -5 = Illegal iteration limit -6 = Minimization function has no good digits -7 = Iteration limit exceeded in lnsrch -20 = Function not defined at starting value -21 = Check of analytic gradient failed -22 = Check of analytic hessian failed

The symbol BOOST_NO_STDC_NAMESPACE should be defined if the C++ compiler does not put the standard C library functions in the std namespace (this is needed for Visual C++ 6).

The symbol BOOST_NO_LIMITS should be defined if the standard C++ library header file <limits> is not available. (this is needed for Visual C++ 6).

Version History

Version 080309 (March 9, 2008)

Edited doxygen-compatible documentation, second pass. Added descriptive comments, much as possible, incorporated any useful information from the existing FORTRAN and Java documentation sets and removed these out-dated documentations afterwards.

Version 071226 (December 26, 2007)

Refactored num_cols property to num_columns in UNCMIN::minimize(). Tagged all public methods and properties with doxygen-compatible comments.

Version 0.001206 (February 10, 2001)

Added BOOST_NO_STDC_NAMESPACE and BOOST_NO_LIMITS symbols which need to be defined to compile Uncmin.h using Microsoft Visual C++ 6.

Definition in file Uncmin.h.

Generated on Sun Mar 9 14:31:59 2008 for UNCMIN by 1.5.4