Honeycomb  0.1
Component-Model Framework
Minimize.h
Go to the documentation of this file.
1 // Honeycomb, Copyright (C) 2015 NewGamePlus Inc. Distributed under the Boost Software License v1.0.
2 #pragma once
3 
4 #include "Honey/Math/Alge/Alge.h"
5 
6 namespace honey
7 {
8 
10 template<class Real>
11 class Minimize
12 {
13  typedef Alge_<Real> Alge;
14 
15 public:
16  typedef function<Real (Real)> Func;
17 
23  Minimize(Real tol = Real_::zeroTol, int levelMax = 30, int bracketMax = 30)
24  : _tol(tol), _levelMax(levelMax), _bracketMax(bracketMax) {}
25 
27 
47  tuple<Real,Real> calc(const Func& func, Real min, Real max, Real init);
48 
49 private:
50  // Algorithm is adapted from the Wild Magic lib
52  void min(Real t0, Real f0, Real tm, Real t1, Real f1, int level);
54  void bracketedMin(Real t0, Real f0, Real tm, Real fm, Real t1, Real f1, int level);
55 
56  Real _tol;
57  int _levelMax;
58  int _bracketMax;
59  const Func* _func;
60  Real _tMin;
61  Real _fMin;
62 };
63 
64 extern template class Minimize<Float>;
65 extern template class Minimize<Double>;
66 extern template class Minimize<Quad>;
67 
68 }
69 
Algebra.
Definition: Alge.h:13
Find a local minimum of a 1-dimensional function using "Brent's method" – bisection and inverse quad...
Definition: Minimize.h:11
tuple< Real, Real > calc(const Func &func, Real min, Real max, Real init)
Find the minimum of a function within bounds [min,max] using init as an initial guess.
Definition: Minimize.cpp:9
function< Real(Real)> Func
Definition: Minimize.h:16
Minimize(Real tol=Real_::zeroTol, int levelMax=30, int bracketMax=30)
Definition: Minimize.h:23
float Real
Real number type. See Real_ for real number operations and constants.
Definition: Real.h:21
Global Honeycomb namespace.