module Brent: sig
.. end
Function minimization in one dimension with golden section search,
or brent's parabolic interpolation.
This Ocaml code inspired from the chapter 10 of "Numerical Recipes in C:
The Art of Scientific Computing, Cambridge University Press, Press W. H.,
Teukolsky S. A., Vetterling W. T., and Flannery B. P., 1992".
val verbose : bool ref
Verbose printing on standard output.
exception Bad_float
val safe : (float -> float) -> float -> float
safe f
returns a function with the same features as f
, except that
it allows to handle NaN results and any exception raised by f
, by
raising a Bad_float
exception.
exception Not_descending
val first_step : (float -> float) -> float -> float -> float -> bool -> float * float
first_step f a step tol debug
recursively searches the interval
between a
and a+step
and returns a couple (b,fb)
for which
f(b)<f(a), or raises an exception Not_descending
when the search
comes at a distance closer than tol
from a
.
debug
is a boolean flag used for debugging.
This function can be used to find a first descending step, starting
from point a
, in a direction chosen by the sign of step
.
val golden_search : (float -> float) ->
float -> float -> int -> float -> float -> bool -> float * float
golden_search f a b max_iter abstol reltol debug
finds a minimum of
f
between a
and b
, using the slow but robust golden section
technique.
The search stops when the range of the search interval falls under
an absolute tolerance abstol
, or when it cannot be significantly
reduced (relative tolerance reltol
). If none of these criteria is
met, the search stops after max_iter
iterations.
debug
is a boolean flag used for debugging.
val brent_search : (float -> float) ->
float -> float -> int -> float -> float -> bool -> float * float
brent_search f a b max_iter abstol reltol debug
finds a minimum of
f
between a
and b
, using a parabolic interpolation when it
is possible, or reversing to the golden search when it is not.
The search stops when the range of the search interval falls under
an absolute tolerance abstol
, or when it cannot be significantly
reduced (relative tolerance reltol
). If none of these criteria is
met, the search stops after max_iter
iterations.
debug
is a boolean flag used for debugging.