scijit.optimize.fminbound¶
- scijit.optimize.fminbound(f, x1, x2, args=(), xtol=1e-05, maxfun=500, full_output=False, disp=1)¶
Bounded scalar minimizer on a fixed interval.
Unlike
brent()andgolden(),[x1, x2]is a hard box: the search never leaves it, so the answer is the constrained minimum, which may sit on an endpoint.Callback style A:
fis a plain@njitf(x) -> float.- Parameters:
- f@njit function
f(x) -> float Function to minimize.
- x1, x2float
Interval bounds, required (there is no default box).
x1 > x2raisesValueError.- argstuple, optional
Extra arguments for f, unpacked into every call as
f(x, *args). Must be a tuple; anything else raisesTypeError. Default().- xtolfloat, optional
Absolute tolerance on the minimizer position. Default 1e-5, looser than the other minimizers here.
- maxfunint, optional
Cap on function evaluations, not iterations. Default 500.
- full_outputbool, optional
False(default) returns x alone.Truereturns(x, fun, status, nfev), with status THIRD. Inside@njitit must be a compile-time constant; see Notes.- dispint, optional
Print level.
0and1print nothing on a converged solve,2prints the termination block. Default1.3raises NotImplementedError; see Notes.
- f@njit function
- Returns:
- xfloat
The minimiser, when
full_outputis False.- (x, fun, status, nfev)tuple
When
full_outputis True. status is 0 on success and 1 when maxfun was reached, and it is the THIRD element, not the last.
- Raises:
- ValueError
If either bound is not finite, or if
x1 > x2.- TypeError
If args is not a tuple.
- NotImplementedError
If
disp >= 3.
- Warns:
- OptimizeWarning
On either failure exit, when
disp > 0:"Maximum number of function evaluations exceeded --- increase maxfun argument."and"NaN result encountered.", each wrapped in newlines.
See also
scipy.optimize.fminboundThe scipy routine this mirrors.
scijit.optimize.brentUnbounded, seeded rather than bracketed.
scijit.optimize.minimize_scalarmethod='bounded'reaches this one.
Notes
full_output selects the RETURN SHAPE, and a compiled function has one return type per signature, so inside
@njitthe flag has to be readable when the call compiles. A literal, an omitted default and a module-level constant all are; a variable is not, and raises TypingError naming the constraint. From Python a runtime value is fine.disp is an int print level, not a bool.
0and1print nothing on a converged solve, and signal a maxfun limit through a warning rather than a print.2prints the termination block.3would add a per-iteration Func-count table whose Procedure column names the step type (golden or parabolic) each iteration took; the bounded-Brent core does not report that, so3raises NotImplementedError rather than printing a table missing a column.Pure
@njit, safe to call from anumba.prangeloop.https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fminbound.html
Examples
>>> from numba import njit >>> from scijit.optimize import fminbound >>> @njit ... def q(x): ... return (x - 1.5) ** 2 + 0.5 >>> @njit ... def run(): ... return fminbound(q, 0.0, 3.0) >>> round(run(), 8) 1.5 >>> @njit ... def run_full(): ... return fminbound(q, 0.0, 3.0, (), 1e-5, 500, True, 0) >>> run_full() (1.5, 0.5, 0, 6)