Skip to content

Commit d6976fd

Browse files
authored
Fix AMSS (#315)
* More robust optimization * Changes to size to eliminate bars
1 parent c38884e commit d6976fd

File tree

1 file changed

+9
-3
lines changed
  • lectures/dynamic_programming_squared

1 file changed

+9
-3
lines changed

lectures/dynamic_programming_squared/amss.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,12 +1309,18 @@ function get_policies_time0(T::BellmanEquation_Recursive,
13091309
U, Uc, Un = model.U, model.Uc, model.Un
13101310
13111311
function objf(z, grad)
1312+
if any(isnan, z)
1313+
return -Inf
1314+
end
13121315
c, xprime = z[1], z[2]
13131316
n = (c + G[s0]) / Theta[s0]
13141317
return -(U(c, n) + beta * Vf[s0](xprime))
13151318
end
13161319
13171320
function cons(z, grad)
1321+
if any(isnan, z)
1322+
return -Inf
1323+
end
13181324
c, xprime, TT = z[1], z[2], z[3]
13191325
n = (c + G[s0]) / Theta[s0]
13201326
return -Uc(c, n) * (c - B_ - TT) - Un(c, n) * n - beta * xprime
@@ -1511,7 +1517,7 @@ sim_seq_h_plot = hcat(sim_seq_h[1:3]..., sim_seq_h[4],
15111517
sim_bel_h_plot = hcat(sim_bel_h[1:3]..., sim_bel_h[5],
15121518
time_example.G[sHist_h],
15131519
time_example.Theta[sHist_h] .* sim_bel_h[2])
1514-
p = plot(size = (920, 750), layout = (3, 2),
1520+
p = plot(size = (700, 700), layout = (3, 2),
15151521
xaxis = (0:6), grid = false, titlefont = Plots.font("sans-serif", 10))
15161522
plot!(p, title = titles)
15171523
for i in 1:6
@@ -1626,7 +1632,7 @@ sim_bel_plot = hcat(sim_bel[1:3]...,
16261632
log_example.Theta[sHist] .* sim_bel[2])
16271633
16281634
#plot policies
1629-
p = plot(size = (920, 750), layout = grid(3, 2),
1635+
p = plot(size = (700, 700), layout = grid(3, 2),
16301636
xaxis = (0:T), grid = false, titlefont = Plots.font("sans-serif", 10))
16311637
labels = fill(("", ""), 6)
16321638
labels[3] = ("Complete Market", "Incomplete Market")
@@ -1671,7 +1677,7 @@ sim_bel_long_plot = hcat(sim_bel_long[1:3]..., sim_bel_long[5],
16711677
log_example.G[sHist_long],
16721678
log_example.Theta[sHist_long] .* sim_bel_long[2])
16731679
1674-
p = plot(size = (920, 750), layout = (3, 2), xaxis = (0:50:T_long),
1680+
p = plot(size = (700, 700), layout = (3, 2), xaxis = (0:50:T_long),
16751681
grid = false,
16761682
titlefont = Plots.font("sans-serif", 10))
16771683
plot!(p, title = titles)

0 commit comments

Comments
 (0)