From 40315e089c5b2b518e000673da137105f2ed297d Mon Sep 17 00:00:00 2001 From: Jesse Perla Date: Tue, 19 Nov 2024 10:13:11 -0800 Subject: [PATCH] More robust optimization --- lectures/dynamic_programming_squared/amss.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lectures/dynamic_programming_squared/amss.md b/lectures/dynamic_programming_squared/amss.md index 421b8297..9d8152e4 100644 --- a/lectures/dynamic_programming_squared/amss.md +++ b/lectures/dynamic_programming_squared/amss.md @@ -1309,12 +1309,18 @@ function get_policies_time0(T::BellmanEquation_Recursive, U, Uc, Un = model.U, model.Uc, model.Un function objf(z, grad) + if any(isnan, z) + return -Inf + end c, xprime = z[1], z[2] n = (c + G[s0]) / Theta[s0] return -(U(c, n) + beta * Vf[s0](xprime)) end function cons(z, grad) + if any(isnan, z) + return -Inf + end c, xprime, TT = z[1], z[2], z[3] n = (c + G[s0]) / Theta[s0] return -Uc(c, n) * (c - B_ - TT) - Un(c, n) * n - beta * xprime