@@ -2177,12 +2177,12 @@ def fminbound(func, x1, x2, args=(), xtol=1e-5, maxfun=500,
2177
2177
Parameters (over given interval) which minimize the
2178
2178
objective function.
2179
2179
fval : number
2180
- The function value evaluated at the minimizer.
2180
+ (Optional output) The function value evaluated at the minimizer.
2181
2181
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
2183
2183
function calls reached).
2184
2184
numfunc : int
2185
- The number of function calls made.
2185
+ (Optional output) The number of function calls made.
2186
2186
2187
2187
See also
2188
2188
--------
@@ -2217,12 +2217,13 @@ def fminbound(func, x1, x2, args=(), xtol=1e-5, maxfun=500,
2217
2217
>>> minimum = f(minimizer)
2218
2218
>>> minimum
2219
2219
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
2221
2222
>>> minimizer
2222
2223
3.000005960860986
2223
2224
>>> minimum = f(minimizer)
2224
- >>> minimum
2225
- 4.000023843479476
2225
+ >>> minimum, fval
2226
+ ( 4.000023843479476, 4.000023843479476)
2226
2227
"""
2227
2228
options = {'xatol' : xtol ,
2228
2229
'maxiter' : maxfun ,
@@ -2564,7 +2565,7 @@ def get_result(self, full_output=False):
2564
2565
def brent (func , args = (), brack = None , tol = 1.48e-8 , full_output = 0 , maxiter = 500 ):
2565
2566
"""
2566
2567
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
2568
2569
of tol.
2569
2570
2570
2571
Parameters
@@ -2574,11 +2575,11 @@ def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500):
2574
2575
args : tuple, optional
2575
2576
Additional arguments (if present).
2576
2577
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`` .
2582
2583
tol : float, optional
2583
2584
Relative error in solution `xopt` acceptable for convergence.
2584
2585
full_output : bool, optional
@@ -2592,11 +2593,11 @@ def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500):
2592
2593
xmin : ndarray
2593
2594
Optimum point.
2594
2595
fval : float
2595
- Optimum value.
2596
+ (Optional output) Optimum function value.
2596
2597
iter : int
2597
- Number of iterations.
2598
+ (Optional output) Number of iterations.
2598
2599
funcalls : int
2599
- Number of objective function evaluations made.
2600
+ (Optional output) Number of objective function evaluations made.
2600
2601
2601
2602
See also
2602
2603
--------
@@ -2609,26 +2610,27 @@ def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500):
2609
2610
convergence of golden section method.
2610
2611
2611
2612
Does not ensure that the minimum lies in the range specified by
2612
- `brack`. See `fminbound`.
2613
+ `brack`. See `scipy.optimize. fminbound`.
2613
2614
2614
2615
Examples
2615
2616
--------
2616
2617
We illustrate the behaviour of the function when `brack` is of
2617
2618
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)`` .
2620
2621
2621
2622
>>> def f(x):
2622
- ... return x **2
2623
+ ... return (x-1) **2
2623
2624
2624
2625
>>> from scipy import optimize
2625
2626
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)
2632
2634
2633
2635
"""
2634
2636
options = {'xtol' : tol ,
@@ -2695,11 +2697,11 @@ def _minimize_scalar_brent(func, brack=None, args=(), xtol=1.48e-8,
2695
2697
def golden (func , args = (), brack = None , tol = _epsilon ,
2696
2698
full_output = 0 , maxiter = 5000 ):
2697
2699
"""
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
2699
2701
method.
2700
2702
2701
2703
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
2703
2705
tol.
2704
2706
2705
2707
Parameters
@@ -2709,18 +2711,27 @@ def golden(func, args=(), brack=None, tol=_epsilon,
2709
2711
args : tuple, optional
2710
2712
Additional arguments (if present), passed to func.
2711
2713
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`` .
2717
2719
tol : float, optional
2718
2720
x tolerance stop criterion
2719
2721
full_output : bool, optional
2720
2722
If True, return optional outputs.
2721
2723
maxiter : int
2722
2724
Maximum number of iterations to perform.
2723
2725
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
+
2724
2735
See also
2725
2736
--------
2726
2737
minimize_scalar: Interface to minimization algorithms for scalar
@@ -2739,16 +2750,17 @@ def golden(func, args=(), brack=None, tol=_epsilon,
2739
2750
not necessarily lie in the range ``(xa, xb)``.
2740
2751
2741
2752
>>> def f(x):
2742
- ... return x **2
2753
+ ... return (x-1) **2
2743
2754
2744
2755
>>> from scipy import optimize
2745
2756
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)
2752
2764
2753
2765
"""
2754
2766
options = {'xtol' : tol , 'maxiter' : maxiter }
0 commit comments