Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4b44d69

Browse filesBrowse files
authored
DOC: optimize.minimize_scalar and friends: correct documentation (scipy#17705)
1 parent 048be0f commit 4b44d69
Copy full SHA for 4b44d69

File tree

2 files changed

+58
-44
lines changed
Filter options

2 files changed

+58
-44
lines changed

‎scipy/optimize/_minimize.py

Copy file name to clipboardExpand all lines: scipy/optimize/_minimize.py
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -762,11 +762,13 @@ def minimize_scalar(fun, bracket=None, bounds=None, args=(),
762762
Scalar function, must return a scalar.
763763
bracket : sequence, optional
764764
For methods 'brent' and 'golden', `bracket` defines the bracketing
765-
interval and can either have three items ``(a, b, c)`` so that
766-
``a < b < c`` and ``fun(b) < fun(a), fun(c)`` or two items ``a`` and
767-
``c`` which are assumed to be a starting interval for a downhill
768-
bracket search (see `bracket`); it doesn't always mean that the
769-
obtained solution will satisfy ``a <= x <= c``.
765+
interval and is required.
766+
Either a triple ``(xa, xb, xc)`` satisfying ``xa < xb < xc`` and
767+
``func(xb) < func(xa) and func(xb) < func(xc)``, or a pair
768+
``(xa, xb)`` to be used as initial points for a downhill bracket search
769+
(see `scipy.optimize.bracket`).
770+
The minimizer ``res.x`` will not necessarily satisfy
771+
``xa <= res.x <= xb``.
770772
bounds : sequence, optional
771773
For method 'bounded', `bounds` is mandatory and must have two finite
772774
items corresponding to the optimization bounds.

‎scipy/optimize/_optimize.py

Copy file name to clipboardExpand all lines: scipy/optimize/_optimize.py
+51-39Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,12 +2177,12 @@ def fminbound(func, x1, x2, args=(), xtol=1e-5, maxfun=500,
21772177
Parameters (over given interval) which minimize the
21782178
objective function.
21792179
fval : number
2180-
The function value evaluated at the minimizer.
2180+
(Optional output) The function value evaluated at the minimizer.
21812181
ierr : int
2182-
An error flag (0 if converged, 1 if maximum number of
2182+
(Optional output) An error flag (0 if converged, 1 if maximum number of
21832183
function calls reached).
21842184
numfunc : int
2185-
The number of function calls made.
2185+
(Optional output) The number of function calls made.
21862186
21872187
See also
21882188
--------
@@ -2217,12 +2217,13 @@ def fminbound(func, x1, x2, args=(), xtol=1e-5, maxfun=500,
22172217
>>> minimum = f(minimizer)
22182218
>>> minimum
22192219
0.0
2220-
>>> minimizer = optimize.fminbound(f, 3, 4)
2220+
>>> res = optimize.fminbound(f, 3, 4, full_output=True)
2221+
>>> minimizer, fval, ierr, numfunc = res
22212222
>>> minimizer
22222223
3.000005960860986
22232224
>>> minimum = f(minimizer)
2224-
>>> minimum
2225-
4.000023843479476
2225+
>>> minimum, fval
2226+
(4.000023843479476, 4.000023843479476)
22262227
"""
22272228
options = {'xatol': xtol,
22282229
'maxiter': maxfun,
@@ -2564,7 +2565,7 @@ def get_result(self, full_output=False):
25642565
def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500):
25652566
"""
25662567
Given a function of one variable and a possible bracket, return
2567-
the local minimum of the function isolated to a fractional precision
2568+
a local minimizer of the function isolated to a fractional precision
25682569
of tol.
25692570
25702571
Parameters
@@ -2574,11 +2575,11 @@ def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500):
25742575
args : tuple, optional
25752576
Additional arguments (if present).
25762577
brack : tuple, optional
2577-
Either a triple (xa,xb,xc) where xa<xb<xc and func(xb) <
2578-
func(xa), func(xc) or a pair (xa,xb) which are used as a
2579-
starting interval for a downhill bracket search (see
2580-
`bracket`). Providing the pair (xa,xb) does not always mean
2581-
the obtained solution will satisfy xa<=x<=xb.
2578+
Either a triple ``(xa, xb, xc)`` satisfying ``xa < xb < xc`` and
2579+
``func(xb) < func(xa) and func(xb) < func(xc)``, or a pair
2580+
``(xa, xb)`` to be used as initial points for a downhill bracket search
2581+
(see `scipy.optimize.bracket`).
2582+
The minimizer ``x`` will not necessarily satisfy ``xa <= x <= xb``.
25822583
tol : float, optional
25832584
Relative error in solution `xopt` acceptable for convergence.
25842585
full_output : bool, optional
@@ -2592,11 +2593,11 @@ def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500):
25922593
xmin : ndarray
25932594
Optimum point.
25942595
fval : float
2595-
Optimum value.
2596+
(Optional output) Optimum function value.
25962597
iter : int
2597-
Number of iterations.
2598+
(Optional output) Number of iterations.
25982599
funcalls : int
2599-
Number of objective function evaluations made.
2600+
(Optional output) Number of objective function evaluations made.
26002601
26012602
See also
26022603
--------
@@ -2609,26 +2610,27 @@ def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500):
26092610
convergence of golden section method.
26102611
26112612
Does not ensure that the minimum lies in the range specified by
2612-
`brack`. See `fminbound`.
2613+
`brack`. See `scipy.optimize.fminbound`.
26132614
26142615
Examples
26152616
--------
26162617
We illustrate the behaviour of the function when `brack` is of
26172618
size 2 and 3 respectively. In the case where `brack` is of the
2618-
form (xa,xb), we can see for the given values, the output need
2619-
not necessarily lie in the range (xa,xb).
2619+
form ``(xa, xb)``, we can see for the given values, the output does
2620+
not necessarily lie in the range ``(xa, xb)``.
26202621
26212622
>>> def f(x):
2622-
... return x**2
2623+
... return (x-1)**2
26232624
26242625
>>> from scipy import optimize
26252626
2626-
>>> minimum = optimize.brent(f,brack=(1,2))
2627-
>>> minimum
2628-
0.0
2629-
>>> minimum = optimize.brent(f,brack=(-1,0.5,2))
2630-
>>> minimum
2631-
-2.7755575615628914e-17
2627+
>>> minimizer = optimize.brent(f, brack=(1, 2))
2628+
>>> minimizer
2629+
1
2630+
>>> res = optimize.brent(f, brack=(-1, 0.5, 2), full_output=True)
2631+
>>> xmin, fval, iter, funcalls = res
2632+
>>> f(xmin), fval
2633+
(0.0, 0.0)
26322634
26332635
"""
26342636
options = {'xtol': tol,
@@ -2695,11 +2697,11 @@ def _minimize_scalar_brent(func, brack=None, args=(), xtol=1.48e-8,
26952697
def golden(func, args=(), brack=None, tol=_epsilon,
26962698
full_output=0, maxiter=5000):
26972699
"""
2698-
Return the minimum of a function of one variable using golden section
2700+
Return the minimizer of a function of one variable using the golden section
26992701
method.
27002702
27012703
Given a function of one variable and a possible bracketing interval,
2702-
return the minimum of the function isolated to a fractional precision of
2704+
return a minimizer of the function isolated to a fractional precision of
27032705
tol.
27042706
27052707
Parameters
@@ -2709,18 +2711,27 @@ def golden(func, args=(), brack=None, tol=_epsilon,
27092711
args : tuple, optional
27102712
Additional arguments (if present), passed to func.
27112713
brack : tuple, optional
2712-
Triple (a,b,c), where (a<b<c) and func(b) <
2713-
func(a),func(c). If bracket consists of two numbers (a,
2714-
c), then they are assumed to be a starting interval for a
2715-
downhill bracket search (see `bracket`); it doesn't always
2716-
mean that obtained solution will satisfy a<=x<=c.
2714+
Either a triple ``(xa, xb, xc)`` where ``xa < xb < xc`` and
2715+
``func(xb) < func(xa) and func(xb) < func(xc)``, or a pair (xa, xb)
2716+
to be used as initial points for a downhill bracket search (see
2717+
`scipy.optimize.bracket`).
2718+
The minimizer ``x`` will not necessarily satisfy ``xa <= x <= xb``.
27172719
tol : float, optional
27182720
x tolerance stop criterion
27192721
full_output : bool, optional
27202722
If True, return optional outputs.
27212723
maxiter : int
27222724
Maximum number of iterations to perform.
27232725
2726+
Returns
2727+
-------
2728+
xmin : ndarray
2729+
Optimum point.
2730+
fval : float
2731+
(Optional output) Optimum function value.
2732+
funcalls : int
2733+
(Optional output) Number of objective function evaluations made.
2734+
27242735
See also
27252736
--------
27262737
minimize_scalar: Interface to minimization algorithms for scalar
@@ -2739,16 +2750,17 @@ def golden(func, args=(), brack=None, tol=_epsilon,
27392750
not necessarily lie in the range ``(xa, xb)``.
27402751
27412752
>>> def f(x):
2742-
... return x**2
2753+
... return (x-1)**2
27432754
27442755
>>> from scipy import optimize
27452756
2746-
>>> minimum = optimize.golden(f, brack=(1, 2))
2747-
>>> minimum
2748-
1.5717277788484873e-162
2749-
>>> minimum = optimize.golden(f, brack=(-1, 0.5, 2))
2750-
>>> minimum
2751-
-1.5717277788484873e-162
2757+
>>> minimizer = optimize.golden(f, brack=(1, 2))
2758+
>>> minimizer
2759+
1
2760+
>>> res = optimize.golden(f, brack=(-1, 0.5, 2), full_output=True)
2761+
>>> xmin, fval, funcalls = res
2762+
>>> f(xmin), fval
2763+
(9.925165290385052e-18, 9.925165290385052e-18)
27522764
27532765
"""
27542766
options = {'xtol': tol, 'maxiter': maxiter}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.