Skip to content

Commit f722b25

Browse files
committed
modified return value to include number of function calls
1 parent e890f71 commit f722b25

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

quantecon/optimize/scalar_maximization.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ def maximize_scalar(func, a, b, args=(), xtol=1e-5, maxiter=500):
3131
The maximum value attained
3232
xf : float
3333
The maximizer
34-
status_flag : int
35-
Indicates whether or not the maximum number of function calls was
34+
info : tuple
35+
A tuple of the form (status_flag, num_iter). Here status_flag
36+
indicates whether or not the maximum number of function calls was
3637
attained. A value of 0 implies that the maximum was not hit.
38+
The value `num_iter` is the number of function calls.
3739
3840
Example
3941
-------
@@ -43,7 +45,7 @@ def maximize_scalar(func, a, b, args=(), xtol=1e-5, maxiter=500):
4345
def f(x):
4446
return -(x + 2.0)**2 + 1.0
4547
46-
fval, xf, status_flag = maximize_scalar(f, -2, 2)
48+
fval, xf, info = maximize_scalar(f, -2, 2)
4749
```
4850
4951
"""
@@ -137,5 +139,6 @@ def f(x):
137139
break
138140

139141
fval = -fx
142+
info = status_flag, num
140143

141-
return fval, xf, status_flag
144+
return fval, xf, info

quantecon/optimize/tests/test_scalar_max.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_maximize_scalar():
2222
"""
2323
true_fval = 1.0
2424
true_xf = -2.0
25-
fval, xf, status_flag = maximize_scalar(f, -2, 2)
25+
fval, xf, info = maximize_scalar(f, -2, 2)
2626
assert_almost_equal(true_fval, fval, decimal=4)
2727
assert_almost_equal(true_xf, xf, decimal=4)
2828

@@ -41,7 +41,7 @@ def test_maximize_scalar_multivariate():
4141
y = 5
4242
true_fval = 5.0
4343
true_xf = -0.0
44-
fval, xf, status_flag = maximize_scalar(g, -10, 10, args=(y,))
44+
fval, xf, info = maximize_scalar(g, -10, 10, args=(y,))
4545
assert_almost_equal(true_fval, fval, decimal=4)
4646
assert_almost_equal(true_xf, xf, decimal=4)
4747

0 commit comments

Comments
 (0)