Skip to content

Commit 98e8ad3

Browse files
remove Dierckx
1 parent b08fd4f commit 98e8ad3

File tree

1 file changed

+20
-20
lines changed
  • lectures/dynamic_programming_squared

1 file changed

+20
-20
lines changed

lectures/dynamic_programming_squared/amss.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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])
655655
end
@@ -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]))
692692
end
693693
```
@@ -961,8 +961,8 @@ assets, returning any excess revenues to the household as nonnegative lump sum t
961961
The recursive formulation is implemented as follows
962962

963963
```{code-cell} julia
964-
using Dierckx
965964
965+
using DataInterpolations
966966
967967
mutable struct BellmanEquation_Recursive{TP <: Model, TI <: Integer, TR <: Real}
968968
model::TP
@@ -1036,17 +1036,17 @@ 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)
10451045
# cf[s_, sprime] = LinInterp(x[end:-1:1], c[:, sprime][end:-1:1])
10461046
# nf[s_, sprime] = LinInterp(x[end:-1:1], n[:, sprime][end:-1:1])
10471047
# xprimef[s_, sprime] = LinInterp(x[end:-1:1], xprimes[:, sprime][end:-1:1])
10481048
end
1049-
splV = Spline1D(x[end:-1:1], V[end:-1:1], k=3)
1049+
splV = CubicSpline(V[end:-1:1], x[end:-1:1])
10501050
Vf[s_] = y -> splV(y)
10511051
# Vf[s_] = LinInterp(x[end:-1:1], V[end:-1:1])
10521052
end
@@ -1094,14 +1094,14 @@ function fit_policy_function(T::BellmanEquation_Recursive,
10941094
for (i_x, x) in enumerate(xgrid)
10951095
PFvec[:, i_x] = PF(i_x, x, s_)
10961096
end
1097-
splV = Spline1D(xgrid, PFvec[1,:], k=3)
1097+
splV = CubicSpline(PFvec[1,:], xgrid)
10981098
Vf[s_] = y -> splV(y)
10991099
# Vf[s_] = LinInterp(xgrid, PFvec[1, :])
11001100
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)
1101+
splc = CubicSpline(PFvec[1 + sprime, :], xgrid)
1102+
spln = CubicSpline(PFvec[1 + S + sprime, :], xgrid)
1103+
splxprime = CubicSpline(PFvec[1 + 2S + sprime, :], xgrid)
1104+
splTT = CubicSpline(PFvec[1 + 3S + sprime, :], xgrid)
11051105
cf[s_, sprime] = y -> splc(y)
11061106
nf[s_, sprime] = y -> spln(y)
11071107
xprimef[s_, sprime] = y -> splxprime(y)
@@ -1281,7 +1281,7 @@ function get_policies_time1(T::BellmanEquation_Recursive,
12811281
ftol_rel!(opt, 1e-8)
12821282
ftol_abs!(opt, 1e-8)
12831283
1284-
(minf, minx, ret) = optimize(opt, init)
1284+
(minf, minx, ret) = NLopt.optimize(opt, init)
12851285
12861286
if ret != :SUCCESS && ret != :ROUNDOFF_LIMITED && ret != :MAXEVAL_REACHED &&
12871287
ret != :FTOL_REACHED && ret != :MAXTIME_REACHED
@@ -1356,7 +1356,7 @@ function get_policies_time0(T::BellmanEquation_Recursive,
13561356
maxeval!(opt, 100000000)
13571357
maxtime!(opt, 30)
13581358
1359-
(minf, minx, ret) = optimize(opt, init)
1359+
(minf, minx, ret) = NLopt.optimize(opt, init)
13601360
13611361
if ret != :SUCCESS && ret != :ROUNDOFF_LIMITED && ret != :MAXEVAL_REACHED &&
13621362
ret != :FTOL_REACHED
@@ -1681,12 +1681,12 @@ p
16811681
tags: [remove-cell]
16821682
---
16831683
@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
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
16901690
end
16911691
```
16921692

0 commit comments

Comments
 (0)