Skip to content

Commit 817b644

Browse files
committed
Fix convergence conditions
1 parent 5fb07e9 commit 817b644

File tree

10 files changed

+37
-40
lines changed

10 files changed

+37
-40
lines changed

lectures/_static/lecture_specific/coleman_policy_iter/solve_time_iter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ def solve_model_time_iter(model, # Class with model information
1717
print(f"Error at iteration {i} is {error}.")
1818
σ = σ_new
1919

20-
if i == max_iter:
20+
if error > tol:
2121
print("Failed to converge!")
2222

23-
if verbose and i < max_iter:
23+
if verbose:
2424
print(f"\nConverged in {i} iterations.")
2525

2626
return σ_new

lectures/_static/lecture_specific/optgrowth/solve_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def solve_model(og,
2121
print(f"Error at iteration {i} is {error}.")
2222
v = v_new
2323

24-
if i == max_iter:
24+
if error > tol:
2525
print("Failed to converge!")
2626

27-
if verbose and i < max_iter:
27+
if verbose:
2828
print(f"\nConverged in {i} iterations.")
2929

3030
return v_greedy, v_new

lectures/cake_eating_numerical.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ The basic idea is:
8888

8989
1. Take an arbitary intial guess of $v$.
9090
1. Obtain an update $w$ defined by
91-
91+
9292
$$
9393
w(x) = \max_{0\leq c \leq x} \{u(c) + \beta v(x-c)\}
9494
$$
95-
95+
9696
1. Stop if $w$ is approximately equal to $v$, otherwise set
9797
$v=w$ and go back to step 2.
9898

@@ -299,10 +299,10 @@ def compute_value_function(ce,
299299
300300
v = v_new
301301
302-
if i == max_iter:
302+
if error > tol:
303303
print("Failed to converge!")
304304
305-
if verbose and i < max_iter:
305+
if verbose:
306306
print(f"\nConverged in {i} iterations.")
307307
308308
return v_new
@@ -657,10 +657,10 @@ def iterate_euler_equation(ce,
657657
658658
σ = σ_new
659659
660-
if i == max_iter:
660+
if error > tol:
661661
print("Failed to converge!")
662662
663-
if verbose and i < max_iter:
663+
if verbose:
664664
print(f"\nConverged in {i} iterations.")
665665
666666
return σ
@@ -685,4 +685,4 @@ plt.show()
685685
```
686686

687687
```{solution-end}
688-
```
688+
```

lectures/career.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,11 @@ def solve_model(cw,
300300
print(f"Error at iteration {i} is {error}.")
301301
v = v_new
302302
303-
if i == max_iter and error > tol:
303+
if error > tol:
304304
print("Failed to converge!")
305305
306-
else:
307-
if verbose:
308-
print(f"\nConverged in {i} iterations.")
306+
elif verbose:
307+
print(f"\nConverged in {i} iterations.")
309308
310309
return v_new
311310
```
@@ -545,4 +544,4 @@ has become more concentrated around the mean, making high-paying jobs
545544
less realistic.
546545

547546
```{solution-end}
548-
```
547+
```

lectures/ifp_advanced.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,10 @@ def solve_model_time_iter(model, # Class with model information
494494
print(f"Error at iteration {i} is {error}.")
495495
a_vec, σ_vec = np.copy(a_new), np.copy(σ_new)
496496
497-
if i == max_iter:
497+
if error > tol:
498498
print("Failed to converge!")
499499
500-
if verbose and i < max_iter:
500+
if verbose:
501501
print(f"\nConverged in {i} iterations.")
502502
503503
return a_new, σ_new

lectures/jv.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,10 @@ def solve_model(jv,
362362
print(f"Error at iteration {i} is {error}.")
363363
v = v_new
364364
365-
if i == max_iter:
365+
if error > tol:
366366
print("Failed to converge!")
367367
368-
if verbose and i < max_iter:
368+
if verbose:
369369
print(f"\nConverged in {i} iterations.")
370370
371371
return v_new
@@ -569,4 +569,4 @@ This seems reasonable and helps us confirm that our dynamic programming
569569
solutions are probably correct.
570570

571571
```{solution-end}
572-
```
572+
```

lectures/mccall_correlated.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ def compute_fixed_point(js,
281281
print(f"Error at iteration {i} is {error}.")
282282
f_in[:] = f_out
283283
284-
if i == max_iter:
284+
if error > tol:
285285
print("Failed to converge!")
286286
287-
if verbose and i < max_iter:
287+
if verbose:
288288
print(f"\nConverged in {i} iterations.")
289289
290290
return f_out
@@ -453,4 +453,4 @@ plt.show()
453453
The figure shows that more patient individuals tend to wait longer before accepting an offer.
454454

455455
```{solution-end}
456-
```
456+
```

lectures/navy_captain.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def solve_model(wf, tol=1e-4, max_iter=1000):
538538
i += 1
539539
h = h_new
540540
541-
if i == max_iter:
541+
if error > tol:
542542
print("Failed to converge!")
543543
544544
return h_new
@@ -621,25 +621,25 @@ conditioning on knowing for sure that nature has selected $f_{0}$,
621621
in the first case, or $f_{1}$, in the second case.
622622

623623
1. under $f_{0}$,
624-
624+
625625
$$
626626
V^{0}\left(\pi\right)=\begin{cases}
627627
0 & \text{if }\alpha\leq\pi,\\
628628
c+EV^{0}\left(\pi^{\prime}\right) & \text{if }\beta\leq\pi<\alpha,\\
629629
\bar L_{1} & \text{if }\pi<\beta.
630630
\end{cases}
631631
$$
632-
632+
633633
1. under $f_{1}$
634-
634+
635635
$$
636636
V^{1}\left(\pi\right)=\begin{cases}
637637
\bar L_{0} & \text{if }\alpha\leq\pi,\\
638638
c+EV^{1}\left(\pi^{\prime}\right) & \text{if }\beta\leq\pi<\alpha,\\
639639
0 & \text{if }\pi<\beta.
640640
\end{cases}
641641
$$
642-
642+
643643

644644
where
645645
$\pi^{\prime}=\frac{\pi f_{0}\left(z^{\prime}\right)}{\pi f_{0}\left(z^{\prime}\right)+\left(1-\pi\right)f_{1}\left(z^{\prime}\right)}$.
@@ -1118,4 +1118,3 @@ plt.title('Uncond. distribution of log likelihood ratio at frequentist t')
11181118
11191119
plt.show()
11201120
```
1121-

lectures/odu.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ $$
149149

150150

151151

152-
The worker's time $t$ subjective belief about the the distribution of $W_t$ is
152+
The worker's time $t$ subjective belief about the the distribution of $W_t$ is
153153

154154
$$
155-
\pi_t f + (1 - \pi_t) g,
155+
\pi_t f + (1 - \pi_t) g,
156156
$$
157157

158158
where $\pi_t$ updates via
@@ -427,10 +427,10 @@ def solve_model(sp,
427427
print(f"Error at iteration {i} is {error}.")
428428
v = v_new
429429
430-
if i == max_iter:
430+
if error > tol:
431431
print("Failed to converge!")
432432
433-
if verbose and i < max_iter:
433+
if verbose:
434434
print(f"\nConverged in {i} iterations.")
435435
436436
@@ -731,10 +731,10 @@ def solve_wbar(sp,
731731
print(f"Error at iteration {i} is {error}.")
732732
w = w_new
733733
734-
if i == max_iter:
734+
if error > tol:
735735
print("Failed to converge!")
736736
737-
if verbose and i < max_iter:
737+
if verbose:
738738
print(f"\nConverged in {i} iterations.")
739739
740740
return w_new
@@ -1178,4 +1178,3 @@ after having acquired less information about the wage distribution.
11781178
```{code-cell} python3
11791179
job_search_example(1, 1, 3, 1.2, c=0.1)
11801180
```
1181-

lectures/wald_friedman.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ def solve_model(wf, tol=1e-4, max_iter=1000):
526526
i += 1
527527
h = h_new
528528
529-
if i == max_iter:
529+
if error > tol:
530530
print("Failed to converge!")
531531
532532
return h_new
@@ -902,11 +902,11 @@ Wald summarizes Neyman and Pearson's setup as follows:
902902

903903
> Neyman and Pearson show that a region consisting of all samples
904904
> $(z_1, z_2, \ldots, z_n)$ which satisfy the inequality
905-
>
905+
>
906906
> $$
907907
\frac{ f_1(z_1) \cdots f_1(z_n)}{f_0(z_1) \cdots f_0(z_n)} \geq k
908908
$$
909-
>
909+
>
910910
> is a most powerful critical region for testing the hypothesis
911911
> $H_0$ against the alternative hypothesis $H_1$. The term
912912
> $k$ on the right side is a constant chosen so that the region

0 commit comments

Comments
 (0)