npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
goldenSectionSearch.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_GOLDENSECTIONSEARCH_HH_
2 #define NPSTAT_GOLDENSECTIONSEARCH_HH_
3 
4 /*!
5 // \file goldenSectionSearch.hh
6 //
7 // \brief Search for 1-d function minimum in log space using
8 // the golden section method
9 //
10 // Author: I. Volobouev
11 //
12 // October 2011
13 */
14 
17 
18 namespace npstat {
19  class DualAxis;
20 
21  /**
22  // Search for 1-d function minimum using the golden section method.
23  //
24  // Input arguments are as follows:
25  //
26  // f -- The functor whose value we are minimizing. The comparison
27  // operator "<" must be defined for the Result type.
28  //
29  // x0 -- The starting point for the search. For Arg1, operation of
30  // multiplication by a double must be defined. The space
31  // searched for minimum will be x0*c, where c is a positive
32  // constant (for example, Arg1 can be a vector).
33  //
34  // tol -- Tolerance parameter. It will often be reasonable to set
35  // tol = sqrt(DBL_EPSILON). Typically, the found minimum
36  // will be within a factor of 1 +- tol of the real one.
37  //
38  // minimum -- Location where the found minimum will be stored.
39  //
40  // fmin -- Provide this if you want the function value at the minimum.
41  //
42  // logstep -- Initial step in the log space. The code will first try
43  // the points x0*exp(logstep) and x0/exp(logstep) to bound
44  // the minimum, and will descend along the slope from there.
45  // "false" will be returned if the initial interval bounds
46  // a maximum instead.
47  //
48  // The function returns "true" if it finds the minimum, "false" otherwise.
49  */
50  template <typename Result, typename Arg1>
52  const Arg1& x0, double tol,
53  Arg1* minimum, Result* fmin = 0,
54  double logstep = 0.5);
55 
56  /**
57  // Search for 1-d function minimum using the golden section method
58  // on a discrete grid. The purpose is to find a 3-cell interval
59  // whose middle cell corresponds to the lowest function value.
60  // This search can be useful for functions that are expensive to
61  // evaluate: it memoizes the results internally and will never call
62  // the function twice with the same argument. The function returns
63  // the search status.
64  //
65  // Input arguments are as follows:
66  //
67  // f -- The functor whose value we are minimizing.
68  //
69  // axis -- The axis which defines locations of the grid points.
70  //
71  // i0 -- The starting grid cell for the search.
72  //
73  // initialStep -- The initial step, in units of cells.
74  //
75  // imin -- Location where the found minimum will be stored
76  // in case returned status in not MIN_SEARCH_FAILED.
77  //
78  // fMinusOne, fmin, fPlusOne -- In case the status is MIN_SEARCH_OK,
79  // these will contain function values the at the grid
80  // cell which precedes the minimum, at the minimum
81  // cell, and at the next cell, respectively. In case
82  // the status is MIN_ON_LEFT_EDGE, *fMinusOne will be
83  // set to *fmin. In case the status is MIN_ON_RIGHT_EDGE,
84  // *fPlusOne will be set to *fmin. In case the status
85  // is MIN_SEARCH_FAILED, the results are undefined.
86  */
87  MinSearchStatus1D goldenSectionSearchOnAGrid(
88  const Functor1<double,double>& f, const DualAxis& axis,
89  unsigned i0, unsigned initialStep,
90  unsigned* imin, double* fMinusOne, double* fmin, double* fPlusOne);
91 }
92 
93 #include "npstat/nm/goldenSectionSearch.icc"
94 
95 #endif // NPSTAT_GOLDENSECTIONSEARCH_HH_
Summary status of a search for a function minimum of a 1-d interval.
Interface definitions and concrete simple functors for a variety of functor-based calculations.
Definition: DualAxis.hh:25
Definition: AbsArrayProjector.hh:14
MinSearchStatus1D goldenSectionSearchOnAGrid(const Functor1< double, double > &f, const DualAxis &axis, unsigned i0, unsigned initialStep, unsigned *imin, double *fMinusOne, double *fmin, double *fPlusOne)
bool goldenSectionSearchInLogSpace(const Functor1< Result, Arg1 > &f, const Arg1 &x0, double tol, Arg1 *minimum, Result *fmin=0, double logstep=0.5)
Definition: SimpleFunctors.hh:58