min_brent_boost.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2013-2017, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 #ifndef O2SCL_MIN_BRENT_BOOST_H
24 #define O2SCL_MIN_BRENT_BOOST_H
25 
26 /** \file min_brent_boost.h
27  \brief File defining \ref o2scl::min_brent_boost
28 */
29 
30 #include <boost/math/tools/minima.hpp>
31 
32 #include <o2scl/min.h>
33 
34 #ifndef DOXYGEN_NO_O2NS
35 namespace o2scl {
36 #endif
37 
38  /** \brief One-dimensional minimization using Brent's method (GSL)
39 
40  This is a wrapper for
41  <tt>boost::math::tools::brent_find_minima()</tt> .
42 
43  The value of fourth argument, <tt>digits</tt> is
44  taken to be \f$ - \log_{10}(t) \f$ where \f$ t \f$ is
45  the value of \ref o2scl::min_base::tol_rel .
46  */
47  template<class func_t=funct11> class min_brent_boost :
48  public min_bkt_base<func_t> {
49 
50  public:
51 
52  min_brent_boost() {
53  }
54 
55  virtual ~min_brent_boost() {}
56 
57  /** \brief Calculate the minimum \c fmin of \c func
58  with \c x2 bracketed between \c x1 and \c x3.
59 
60  The initial value of \c x2 is ignored.
61  */
62  virtual int min_bkt(double &x2, double x1, double x3, double &fmin,
63  func_t &func) {
64 
65  std::pair<double,double> res;
66  size_t digits;
67  if (this->tol_rel>1.0) digits=1;
68  else if (this->tol_rel<=0.0) digits=18;
69  else digits=((size_t)(-log10(this->tol_rel)));
70  res=boost::math::tools::brent_find_minima(func,x1,x3,digits);
71  x2=res.first;
72  fmin=res.second;
73  return success;
74  }
75 
76  /// Return string denoting type ("min_brent_boost")
77  virtual const char *type() { return "min_brent_boost"; }
78 
79  };
80 
81 #ifndef DOXYGEN_NO_O2NS
82 }
83 #endif
84 
85 #endif
One-dimensional bracketing minimization [abstract base].
Definition: min.h:229
double tol_rel
The tolerance for the minimum function value.
Definition: min.h:65
virtual const char * type()
Return string denoting type ("min_brent_boost")
The main O<span style=&#39;position: relative; top: 0.3em; font-size: 0.8em&#39;>2</span>scl O$_2$scl names...
Definition: anneal.h:42
virtual int min_bkt(double &x2, double x1, double x3, double &fmin, func_t &func)
Calculate the minimum fmin of func with x2 bracketed between x1 and x3.
static const double x3[11]
Definition: inte_qng_gsl.h:94
One-dimensional minimization using Brent&#39;s method (GSL)
static const double x2[5]
Definition: inte_qng_gsl.h:66
static const double x1[5]
Definition: inte_qng_gsl.h:48
Success.
Definition: err_hnd.h:47

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).