COPASI API  4.16.103
FminBrent.h
Go to the documentation of this file.
2 // \$Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/optimization/FminBrent.h,v \$
3 // \$Revision: 1.5 \$
4 // \$Name: \$
5 // \$Author: ssahle \$
6 // \$Date: 2009/04/24 12:50:05 \$
8
9 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
11 // and The University of Manchester.
13
14 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc. and EML Research, gGmbH.
17
18 #ifndef COAPSI_FminBrent
19 #define COAPSI_FminBrent
20
21 /**
22  *
23  * Adapted by Pedro Mendes to suit Gepasi's optimisation framework
24  * 9 Aug 1997
25  *
26  **ORIGINAL**in**netlib**********************************************
27  * C math library
28  * function FMINBR - one-dimensional search for a function minimum
29  * over the given range
30  *
31  * Input
32  * double FminBrent(a, b, f, min, fmin, tol, maxiter)
33  * @param double a; Minimum will be seeked for over
34  * @param double b; a range [a,b], a being < b.
35  * @param double (*f)(double x); Name of the function whose minimum
36  * will be seeked for
37  * @param double *min, Location of minimum (output)
38  * @param double *fmin, Value of minimum (ouput)
39  * @param double tol; Acceptable tolerance for the minimum
40  * location. It have to be positive
41  * (e.g. may be specified as EPSILON)
42  * @param int maxiter Maximum number of iterations
43  *
44  * Output
45  * Fminbr returns an estimate for the minimum location with accuracy
46  * 3*SQRT_EPSILON*abs(x) + tol.
47  * The function always obtains a local minimum which coincides with
48  * the global one only if a function under investigation being
49  * unimodular.
50  * If a function being examined possesses no local minimum within
51  * the given range, Fminbr returns 'a' (if f(a) < f(b)), otherwise
52  * it returns the right range boundary value b.
53  *
54  * @ return int (0: success, 1: negative tolerance, 2: b < a 3: iteration limit exceeded)
55  *
56  * Algorithm
57  * G.Forsythe, M.Malcolm, C.Moler, Computer methods for mathematical
58  * computations. M., Mir, 1980, p.202 of the Russian edition
59  *
60  * The function makes use of the "gold section" procedure combined with
61  * the parabolic interpolation.
62  * At every step program operates three abscissae - x,v, and w.
63  * x - the last and the best approximation to the minimum location,
64  * i.e. f(x) <= f(a) or/and f(x) <= f(b)
65  * (if the function f has a local minimum in (a,b), then the both
66  * conditions are fulfiled after one or two steps).
67  * v,w are previous approximations to the minimum location. They may
68  * coincide with a, b, or x (although the algorithm tries to make all
69  * u, v, and w distinct). Points x, v, and w are used to construct
70  * interpolating parabola whose minimum will be treated as a new
71  * approximation to the minimum location if the former falls within
72  * [a,b] and reduces the range enveloping minimum more efficient than
73  * the gold section procedure.
74  * When f(x) has a second derivative positive at the minimum location
75  * (not coinciding with a or b) the procedure converges superlinearly
76  * at a rate order about 1.324
77  *
78  ************************************************************************
79  */
80
81 class FDescent
82 {
83 public:
84  virtual ~FDescent() {};
85
86  virtual C_FLOAT64 operator()(const C_FLOAT64 & C_UNUSED(value))
87  {return std::numeric_limits<C_FLOAT64>::quiet_NaN();}
88 };
89
90 template <class CType> class FDescentTemplate : public FDescent
91 {
92 private:
93  C_FLOAT64(CType::*mMethod)(const C_FLOAT64 &); // pointer to member function
94  CType * mpType; // pointer to object
95
96 public:
97
98  // constructor - takes pointer to an object and pointer to a member and stores
99  // them in two private variables
100  FDescentTemplate(CType * pType,
101  C_FLOAT64(CType::*method)(const C_FLOAT64 &))
102  {
103  mpType = pType;
104  mMethod = method;
105  };
106
107  virtual ~FDescentTemplate() {};
108
109  // override operator "()"
110  virtual C_FLOAT64 operator()(const C_FLOAT64 & value)
111  {return (*mpType.*mMethod)(value);} ; // execute member function
112 };
113
114 int FminBrent(double a, /* Left border */
115  double b, /* Right border */
116  FDescent * pF, /* Functor for function under investigation */
117  double *min, /* Location of minimum */
118  double *fmin, /* Value of minimum */
119  double tol, /* Acceptable tolerance */
120  int maxiter); /* Maximum number of iterations */
121
122 #endif // COAPSI_FminBrent
#define C_UNUSED(p)
Definition: copasi.h:220
int FminBrent(double a, double b, FDescent *pF, double *min, double *fmin, double tol, int maxiter)
Definition: FminBrent.cpp:30
virtual ~FDescentTemplate()
Definition: FminBrent.h:107
virtual C_FLOAT64 operator()(const C_FLOAT64 &C_UNUSED(value))
Definition: FminBrent.h:86
virtual ~FDescent()
Definition: FminBrent.h:84
virtual C_FLOAT64 operator()(const C_FLOAT64 &value)
Definition: FminBrent.h:110
#define C_FLOAT64
Definition: copasi.h:92
CType * mpType
Definition: FminBrent.h:94
C_FLOAT64(CType::* mMethod)(const C_FLOAT64 &)
Definition: FminBrent.h:93
FDescentTemplate(CType *pType, C_FLOAT64(CType::*method)(const C_FLOAT64 &))
Definition: FminBrent.h:100
#define min(a, b)
Definition: f2c.h:175