//=========================================================================== // GoTools Core - SINTEF Geometry Tools Core library, version 2.0.1 // // Copyright (C) 2000-2007, 2010 SINTEF ICT, Applied Mathematics, Norway. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation version 2 of the License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., // 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // Contact information: E-mail: tor.dokken@sintef.no // SINTEF ICT, Department of Applied Mathematics, // P.O. Box 124 Blindern, // 0314 Oslo, Norway. // // Other licenses are also available for this software, notably licenses // for: // - Building commercial software. // - Building software whose source code you wish to keep private. //=========================================================================== 00013 #ifndef _BRENT_MINIMIZE_H 00014 #define _BRENT_MINIMIZE_H 00015 00016 #include "GoTools/utils/GeneralFunctionMinimizer.h" 00017 00018 namespace Go 00019 { 00024 template<class Functor> 00025 class Fun2Fun 00026 { 00027 public: 00028 Fun2Fun(const Functor& f, double a, double b) : f_(f), a_(a), b_(b) {} 00029 double operator()(const double* arg) const 00030 { 00031 return f_(*arg); 00032 } 00034 double minPar(int n) const { return a_; } 00035 double maxPar(int n) const { return b_; } 00036 private: 00037 Functor f_; 00038 double a_; 00039 double b_; 00040 }; 00041 00042 //=========================================================================== 00043 template<class Functor> 00044 inline double brent_minimize(const Functor& f, 00045 double a, double b, double c, 00046 double& parmin, 00047 const double rel_tolerance = std::sqrt(std::numeric_limits<double>::epsilon())) 00048 //=========================================================================== 00049 { 00050 Fun2Fun<Functor> f2(f, a, c); 00051 Go::FunctionMinimizer<Fun2Fun<Functor> > fmin(1, f2, &a, rel_tolerance); 00052 Go::Point dir(1); 00053 dir[0] = 1.0; 00054 double bracket[3]; 00055 double fval_brak[3]; 00056 bracket[0] = 0.0; 00057 bracket[1] = b-a; 00058 bracket[2] = c-a; 00059 fval_brak[0] = f(a); 00060 fval_brak[1] = f(b); 00061 fval_brak[2] = f(c); 00062 double minimum = fmin.linminBrent(dir, bracket, fval_brak); 00063 parmin = fmin.getPar(0); 00064 return minimum; 00065 } 00066 00067 00068 } // namespace Go 00069 00070 #endif // _BRENT_MINIMIZE_H 00071
Generated on Tue Sep 21 15:44:17 2010 for GoTools Core by  doxygen 1.6.3