@@ -649,7 +649,7 @@ function get_policies_time1(T::BellmanEquation,
649649 init[i] = lb[i]
650650 end
651651 end
652- (minf, minx, ret) = optimize(opt, init)
652+ (minf, minx, ret) = NLopt. optimize(opt, init)
653653 T.z0[i_x, s] = vcat(minx[1], minx[1] + G[s], minx[2:end])
654654 return vcat(-minf, T.z0[i_x, s])
655655end
@@ -687,7 +687,7 @@ function get_policies_time0(T::BellmanEquation,
687687 init[i] = lb[i]
688688 end
689689 end
690- (minf, minx, ret) = optimize(opt, init)
690+ (minf, minx, ret) = NLopt. optimize(opt, init)
691691 return vcat(-minf, vcat(minx[1], minx[1]+G[s0], minx[2:end]))
692692end
693693```
@@ -961,8 +961,8 @@ assets, returning any excess revenues to the household as nonnegative lump sum t
961961The recursive formulation is implemented as follows
962962
963963``` {code-cell} julia
964- using Dierckx
965964
965+ using DataInterpolations
966966
967967mutable struct BellmanEquation_Recursive{TP <: Model, TI <: Integer, TR <: Real}
968968 model::TP
@@ -1036,19 +1036,15 @@ function solve_time1_bellman(model::Model{TR}, μgrid::AbstractArray) where {TR
10361036 xprimes = repeat(x, 1, S)
10371037 xgrid[s_, :] = x
10381038 for sprime = 1:S
1039- splc = Spline1D(x[ end:-1:1], c[:, sprime][ end:-1:1], k=3 )
1040- spln = Spline1D(x[ end:-1:1], n[:, sprime][ end:-1:1], k=3 )
1041- splx = Spline1D(x[ end:-1:1], xprimes[:, sprime][ end:-1:1], k=3 )
1039+ splc = CubicSpline(c[:, sprime][ end:-1:1], x[ end:-1:1])
1040+ spln = CubicSpline(n[:, sprime][ end:-1:1], x[ end:-1:1])
1041+ splx = CubicSpline(xprimes[:, sprime][ end:-1:1], x[ end:-1:1])
10421042 cf[s_, sprime] = y -> splc(y)
10431043 nf[s_, sprime] = y -> spln(y)
10441044 xprimef[s_, sprime] = y -> splx(y)
1045- # cf[s_, sprime] = LinInterp(x[end:-1:1], c[:, sprime][end:-1:1])
1046- # nf[s_, sprime] = LinInterp(x[end:-1:1], n[:, sprime][end:-1:1])
1047- # xprimef[s_, sprime] = LinInterp(x[end:-1:1], xprimes[:, sprime][end:-1:1])
10481045 end
1049- splV = Spline1D(x [end:-1:1], V [end:-1:1], k=3 )
1046+ splV = CubicSpline(V [end:-1:1], x [end:-1:1])
10501047 Vf[s_] = y -> splV(y)
1051- # Vf[s_] = LinInterp(x[end:-1:1], V[end:-1:1])
10521048 end
10531049
10541050 policies = [cf, nf, xprimef]
@@ -1094,14 +1090,13 @@ function fit_policy_function(T::BellmanEquation_Recursive,
10941090 for (i_x, x) in enumerate(xgrid)
10951091 PFvec[:, i_x] = PF(i_x, x, s_)
10961092 end
1097- splV = Spline1D(xgrid, PFvec[1,:], k=3 )
1093+ splV = CubicSpline( PFvec[1,:], xgrid )
10981094 Vf[s_] = y -> splV(y)
1099- # Vf[s_] = LinInterp(xgrid, PFvec[1, :])
11001095 for sprime=1:S
1101- splc = Spline1D(xgrid, PFvec[1 + sprime, :], k=3 )
1102- spln = Spline1D(xgrid, PFvec[1 + S + sprime, :], k=3 )
1103- splxprime = Spline1D(xgrid, PFvec[1 + 2S + sprime, :], k=3 )
1104- splTT = Spline1D(xgrid, PFvec[1 + 3S + sprime, :], k=3 )
1096+ splc = CubicSpline( PFvec[1 + sprime, :], xgrid )
1097+ spln = CubicSpline( PFvec[1 + S + sprime, :], xgrid )
1098+ splxprime = CubicSpline( PFvec[1 + 2S + sprime, :], xgrid )
1099+ splTT = CubicSpline( PFvec[1 + 3S + sprime, :], xgrid )
11051100 cf[s_, sprime] = y -> splc(y)
11061101 nf[s_, sprime] = y -> spln(y)
11071102 xprimef[s_, sprime] = y -> splxprime(y)
@@ -1281,7 +1276,7 @@ function get_policies_time1(T::BellmanEquation_Recursive,
12811276 ftol_rel!(opt, 1e-8)
12821277 ftol_abs!(opt, 1e-8)
12831278
1284- (minf, minx, ret) = optimize(opt, init)
1279+ (minf, minx, ret) = NLopt. optimize(opt, init)
12851280
12861281 if ret != :SUCCESS && ret != :ROUNDOFF_LIMITED && ret != :MAXEVAL_REACHED &&
12871282 ret != :FTOL_REACHED && ret != :MAXTIME_REACHED
@@ -1356,7 +1351,7 @@ function get_policies_time0(T::BellmanEquation_Recursive,
13561351 maxeval!(opt, 100000000)
13571352 maxtime!(opt, 30)
13581353
1359- (minf, minx, ret) = optimize(opt, init)
1354+ (minf, minx, ret) = NLopt. optimize(opt, init)
13601355
13611356 if ret != :SUCCESS && ret != :ROUNDOFF_LIMITED && ret != :MAXEVAL_REACHED &&
13621357 ret != :FTOL_REACHED
@@ -1681,12 +1676,12 @@ p
16811676tags: [remove-cell]
16821677---
16831678@testset begin
1684- # test sim_seq_long_plot[50, 3] ≈ 0.3951985593686047
1685- # test sim_bel_long_plot[50, 3] ≈ 0.05684753244006188 atol = 1e-2
1686- # test sim_seq_long_plot[100, 4] ≈ 0.340233842670859
1687- # test sim_bel_long_plot[100, 4] ≈ 0.2093423366870517 atol = 1e-3
1688- # test sim_seq_long_plot[200, 2] ≈ 0.5839693539786998
1689- # test sim_bel_long_plot[200, 2] ≈ 0.6324036099550768 atol = 1e-3
1679+ @ test sim_seq_long_plot[50, 3] ≈ 0.3951985593686047
1680+ @ test sim_bel_long_plot[50, 3] ≈ 0.05684753244006188 atol = 1e-2
1681+ @ test sim_seq_long_plot[100, 4] ≈ 0.340233842670859
1682+ @ test sim_bel_long_plot[100, 4] ≈ 0.2093423366870517 atol = 1e-3
1683+ @ test sim_seq_long_plot[200, 2] ≈ 0.5839693539786998
1684+ @ test sim_bel_long_plot[200, 2] ≈ 0.6324036099550768 atol = 1e-3
16901685end
16911686```
16921687
0 commit comments