Skip to content

Commit 794a376

Browse files
committed
Fix interp issues
1 parent cbd9876 commit 794a376

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lectures/_static/lecture_specific/opt_tax_recur/recursive_allocation.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,17 @@ def simulate(self, b0, s0, T, sHist=None):
131131
# Time 1 onward
132132
for t in range(1, T):
133133
s, x = sHist[t], xHist[t-1]
134-
cHist[t] = interp(self.x_grid, self.c1[:, s], x)
135-
nHist[t] = interp(self.x_grid, self.n1[:, s], x)
134+
cHist[t] = np.interp(x, self.x_grid, self.c1[:, s])
135+
nHist[t] = np.interp(x, self.x_grid, self.n1[:, s])
136136

137137
τHist[t] = self.τ(cHist[t], nHist[t])
138138

139139
Bhist[t] = x / Uc(cHist[t], 1-nHist[t])
140140

141141
c, n = np.empty((2, self.S))
142142
for sprime in range(self.S):
143-
c[sprime] = interp(x_grid, self.c1[:, sprime], x)
144-
n[sprime] = interp(x_grid, self.n1[:, sprime], x)
143+
c[sprime] = np.interp(x, x_grid, self.c1[:, sprime])
144+
n[sprime] = np.interp(x, x_grid, self.n1[:, sprime])
145145
Euc = π[sHist[t-1]] @ Uc(c, 1-n)
146146
RHist[t-1] = Uc(cHist[t-1], 1-nHist[t-1]) / (self.pref.β * Euc)
147147

@@ -150,7 +150,7 @@ def simulate(self, b0, s0, T, sHist=None):
150150

151151
if t < T-1:
152152
sprime = sHist[t+1]
153-
xHist[t] = interp(self.x_grid, self.xprime1[:, s, sprime], x)
153+
xHist[t] = np.interp(x, self.x_grid, self.xprime1[:, s, sprime])
154154

155155
return [cHist, nHist, Bhist, τHist, gHist, yHist, xHist, RHist]
156156

@@ -209,7 +209,7 @@ def obj_V(z_sub, x, s, V, pref, π, g, x_grid, b0=None):
209209
# prepare Vprime vector
210210
Vprime = np.empty(S)
211211
for sprime in range(S):
212-
Vprime[sprime] = interp(x_grid, V[:, sprime], xprime[sprime])
212+
Vprime[sprime] = np.interp(xprime[sprime], x_grid, V[:, sprime])
213213

214214
# compute the objective value
215215
obj = U(c, l) + β * π[s] @ Vprime

0 commit comments

Comments
 (0)