Slide 24
Slide 24 text
C++: BOOST, 2006
template
1
std::pair brent_find_minima(F f, T min, T max, int bits
2
noexcept(BOOST_MATH_IS_FLOAT(T) && noexcept(std::declval >
6
T tolerance = static_cast(ldexp(1.0, 1-bits));
7
T x; // minima so far
8
T w; // second best point
9
T v; // previous value of w
10
T u; // most recent evaluation point
11
T delta; // The distance moved in the last step
12
T delta2; // The distance moved in the step before last
13
T fu, fv, fw, fx; // function evaluations at u, v, w, x
14
T mid; // midpoint of min and max
15
T fract1 fract2; // minimal relative movement in x
16
template
1
std::pair brent_find_minima(F f, T min, T max, int bits
2
noexcept(BOOST_MATH_IS_FLOAT(T) && noexcept(std::declval >
6
T tolerance = static_cast(ldexp(1.0, 1-bits));
7
T x; // minima so far
8
T w; // second best point
9
T v; // previous value of w
10
T u; // most recent evaluation point
11
T delta; // The distance moved in the last step
12
T delta2; // The distance moved in the step before last
13
T fu, fv, fw, fx; // function evaluations at u, v, w, x
14
T mid; // midpoint of min and max
15
T fract1 fract2; // minimal relative movement in x
16
template
1
std::pair brent_find_minima(F f, T min, T max, int bits
2
noexcept(BOOST_MATH_IS_FLOAT(T) && noexcept(std::declval >
6
T tolerance = static_cast(ldexp(1.0, 1-bits));
7
T x; // minima so far
8
T w; // second best point
9
T v; // previous value of w
10
T u; // most recent evaluation point
11
T delta; // The distance moved in the last step
12
T delta2; // The distance moved in the step before last
13
T fu, fv, fw, fx; // function evaluations at u, v, w, x
14
T mid; // midpoint of min and max
15
T fract1 fract2; // minimal relative movement in x
16
template
1
std::pair brent_find_minima(F f, T min, T max, int bits
2
noexcept(BOOST_MATH_IS_FLOAT(T) && noexcept(std::declval >
6
T tolerance = static_cast(ldexp(1.0, 1-bits));
7
T x; // minima so far
8
T w; // second best point
9
T v; // previous value of w
10
T u; // most recent evaluation point
11
T delta; // The distance moved in the last step
12
T delta2; // The distance moved in the step before last
13
T fu, fv, fw, fx; // function evaluations at u, v, w, x
14
T mid; // midpoint of min and max
15
T fract1 fract2; // minimal relative movement in x
16
fw = fu;
102
}
103
else if((fu <= fv) || (v == x) || (v == w))
104
{
105
// third best:
106
v = u;
107
fv = fu;
108
}
109
}
110
111
}while(--count);
112
113
max_iter -= count;
114
115
return std::make_pair(x, fx);
116
}
117
27