Skip to content

Commit

Permalink
Pull the definition of tol out of the for loop
Browse files Browse the repository at this point in the history
in modified_policy_iteration
  • Loading branch information
oyamad committed Mar 14, 2016
1 parent 4a212cb commit fd3fd1a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions quantecon/markov/ddp.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,14 +775,15 @@ def midrange(z):
u = np.empty(self.num_states)
sigma = np.empty(self.num_states, dtype=int)

try:
tol = epsilon * (1-self.beta) / self.beta
except ZeroDivisionError: # Raised if beta = 0
tol = np.inf

for i in range(max_iter):
# Policy improvement
self.bellman_operator(v, Tv=u, sigma=sigma)
diff = u - v
try:
tol = epsilon * (1-self.beta) / self.beta
except ZeroDivisionError: # Raised if beta = 0
tol = np.inf
if span(diff) < tol:
v[:] = u + midrange(diff) * self.beta / (1 - self.beta)
break
Expand Down

0 comments on commit fd3fd1a

Please sign in to comment.