Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Updates for Numba 0.49.0 #531

Merged
merged 4 commits into from
Apr 21, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
FIX: Fix errors in tests for nelder_mead.py when Numba 0.49.0 is used
  • Loading branch information
QBatista committed Apr 21, 2020
commit 5c37da7d4148d1a34386b4048d64e7c02eda32e4
13 changes: 9 additions & 4 deletions quantecon/optimize/nelder_mead.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ def _nelder_mead_algorithm(fun, vertices, bounds=np.array([[], []]).T,
break

# Step 2: Reflection
x_r = x_bar + ρ * (x_bar - vertices[worst_val_idx])
# https://github.com/QuantEcon/QuantEcon.py/issues/530
temp = ρ * (x_bar - vertices[worst_val_idx])
x_r = x_bar + temp
f_r = _neg_bounded_fun(fun, bounds, x_r, args=args)

if f_r >= f_val[best_val_idx] and f_r < f_val[sort_ind[n-1]]:
Expand All @@ -230,7 +232,8 @@ def _nelder_mead_algorithm(fun, vertices, bounds=np.array([[], []]).T,

# Step 3: Expansion
elif f_r < f_val[best_val_idx]:
x_e = x_bar + χ * (x_r - x_bar)
temp = χ * (x_r - x_bar) # https://github.com/QuantEcon/QuantEcon.py/issues/530
x_e = x_bar + temp
f_e = _neg_bounded_fun(fun, bounds, x_e, args=args)
if f_e < f_r: # Greedy minimization
vertices[worst_val_idx] = x_e
Expand All @@ -242,11 +245,13 @@ def _nelder_mead_algorithm(fun, vertices, bounds=np.array([[], []]).T,
# Step 4 & 5: Contraction and Shrink
else:
# Step 4: Contraction
# https://github.com/QuantEcon/QuantEcon.py/issues/530
temp = γ * (x_r - x_bar)
if f_r < f_val[worst_val_idx]: # Step 4.a: Outside Contraction
x_c = x_bar + γ * (x_r - x_bar)
x_c = x_bar + temp
LV_ratio_update = ργ
else: # Step 4.b: Inside Contraction
x_c = x_bar - γ * (x_r - x_bar)
x_c = x_bar - temp
LV_ratio_update = γ

f_c = _neg_bounded_fun(fun, bounds, x_c, args=args)
Expand Down