mmfutils.optimize

Optimization tools.

mmfutils.optimize.bracket_monotonic(f, x0=0.0, x1=1.0, factor=2.0)[source]

Return (x0, x1) where f(x0)*f(x1) < 0.

Assumes that f is monotonic and that the root exists.

Proceeds by increasing the size of the interval by factor in the direction of the root until the root is found.

Examples

>>> import math
>>> bracket_monotonic(lambda x:10 - math.exp(x))
(0.0, 3.0)
>>> bracket_monotonic(lambda x:10 - math.exp(-x), factor=1.5)
(4.75, -10.875)
mmfutils.optimize.ubrentq(f, a, b, *v, **kw)[source]

Version of scipy.optimize.brentq with uncertainty processing using the uncertainties package.

mmfutils.optimize.usolve(f, a, *v, **kw)[source]

Return the root of f(x) = 0 with uncertainties propagated.

Parameters
  • f (function) – Function to find root of f(x) = 0. Note: this must work with only a single argument even if the solver supports args etc. Thus, use lambda x: f(x, …) or functools.partial if needed.

  • solver (function) – Solver function (default is scipy.optimize.brentq).

  • v – Remaining arguments will be passed as solver(f, a, *v, **kw).

  • kw – Remaining arguments will be passed as solver(f, a, *v, **kw).