Skip to content

Commit

Permalink
Fix formatting error and cubic interpolation typo
Browse files Browse the repository at this point in the history
Forgot to test CubicBool=True on prior commit, but there was only one tiny error, 3 character fix. Began to implement value function, but ran out of time.
  • Loading branch information
mnwhite committed Mar 12, 2024
1 parent 491a6f6 commit 8d3cc8d
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions HARK/ConsumptionSaving/ConsMarkovModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,20 @@ def calc_vPPnext(S, a, R):
# Construct the beginning-of-period value functional conditional on next
# period's state and add it to the list of value functions
if vFuncBool:

Check warning on line 277 in HARK/ConsumptionSaving/ConsMarkovModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsMarkovModel.py#L277

Added line #L277 was not covered by tests
pass
# BegOfPrd_vFunc = self.make_EndOfPrdvFuncCond()
# EndOfPrdvFunc_list.append(EndOfPrdvFunc)
# TODO: Implement vFunc functionality
# Calculate end-of-period value, its derivative, and their pseudo-inverse
BegOfPrd_vNext = DiscFacEff * expected(calc_vNext, IncShkDstn, args=(aNrmNext, Rfree))

Check warning on line 279 in HARK/ConsumptionSaving/ConsMarkovModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsMarkovModel.py#L279

Added line #L279 was not covered by tests
# value transformed through inverse utility
BegOfPrd_vNvrsNext = uFunc.inv(BegOfPrd_vNext)
BegOfPrd_vNvrsPnext = BegOfPrd_vPnext * uFunc.derinv(BegOfPrd_vNext, order=(0, 1))
BegOfPrd_vNvrsNext = np.insert(BegOfPrd_vNvrsNext, 0, 0.0)
BegOfPrd_vNvrsPnext = np.insert(BegOfPrd_vNvrsPnext, 0, BegOfPrd_vNvrsPnext[0])

Check warning on line 284 in HARK/ConsumptionSaving/ConsMarkovModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsMarkovModel.py#L281-L284

Added lines #L281 - L284 were not covered by tests
# This is a very good approximation, vNvrsPP = 0 at the asset minimum

# Construct the end-of-period value function
aNrm_temp = np.insert(aNrmNext, 0, BoroCnstNat)
BegOfPrd_vNvrsFunc = CubicInterp(aNrm_temp, BegOfPrd_vNvrsNext, BegOfPrd_vNvrsPnext)
BegOfPrd_vFunc = ValueFuncCRRA(BegOfPrd_vNvrsFunc, CRRA)
BegOfPrd_vFunc_list.append(BegOfPrd_vFunc)

Check warning on line 291 in HARK/ConsumptionSaving/ConsMarkovModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsMarkovModel.py#L288-L291

Added lines #L288 - L291 were not covered by tests

# BegOfPrdvP is marginal value conditional on *next* period's state.
# Take expectations over Markov transitions to get EndOfPrdvP conditional on
Expand Down Expand Up @@ -388,7 +398,7 @@ def calc_vPPnext(S, a, R):

# Calculate the MPC at each market resource gridpoint in each state (if desired)
if CubicBool:
dcda = EndOfPrd_vPP / uFunc.der(cNrmNow, order=2)
dcda = EndOfPrd_vPP / uFunc.der(cNrmNow[:,1:], order=2) # drop first
MPCnow = dcda / (dcda + 1.0)
MPCnow = np.hstack((np.reshape(MPCmaxNow, (StateCountNow, 1)), MPCnow))

Check warning on line 403 in HARK/ConsumptionSaving/ConsMarkovModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsMarkovModel.py#L400-L403

Added lines #L400 - L403 were not covered by tests

Expand Down Expand Up @@ -777,9 +787,9 @@ def v_lvl_next(shocks, a_nrm, Rfree):
) # This is a very good approximation, vNvrsPP = 0 at the asset minimum
aNrm_temp = np.insert(self.aNrmNow, 0, self.BoroCnstNat)
EndOfPrdvNvrsFunc = CubicInterp(aNrm_temp, EndOfPrdvNvrs, EndOfPrdvNvrsP)
EndOfPrdvFunc_dond = ValueFuncCRRA(EndOfPrdvNvrsFunc, self.CRRA)
EndOfPrdvFunc_cond = ValueFuncCRRA(EndOfPrdvNvrsFunc, self.CRRA)

Check warning on line 790 in HARK/ConsumptionSaving/ConsMarkovModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsMarkovModel.py#L790

Added line #L790 was not covered by tests

return EndOfPrdvFunc_dond
return EndOfPrdvFunc_cond

Check warning on line 792 in HARK/ConsumptionSaving/ConsMarkovModel.py

View check run for this annotation

Codecov / codecov/patch

HARK/ConsumptionSaving/ConsMarkovModel.py#L792

Added line #L792 was not covered by tests

def calc_EndOfPrdvPcond(self):
"""
Expand Down Expand Up @@ -881,9 +891,8 @@ def calc_EndOfPrdvP(self):
np.logical_and(self.possible_transitions[:, j], which_states)
): # only consider a future state if one of the relevant states could transition to it
EndOfPrdvP_all[j, :] = self.EndOfPrdvPfunc_list[j](aGrid)
if (
self.CubicBool
): # Add conditional end-of-period (marginal) marginal value to the arrays
# Add conditional end-of-period (marginal) marginal value to the arrays
if self.CubicBool:
EndOfPrdvPP_all[j, :] = self.EndOfPrdvPfunc_list[j].derivativeX(
aGrid
)
Expand Down Expand Up @@ -1017,9 +1026,8 @@ def make_solution(self, cNrm, mNrm):
solution_cond = ConsumerSolution(
cFunc=cFuncNow, vPfunc=vPfuncNow, mNrmMin=self.mNrmMinNow
)
if (
self.CubicBool
): # Add the state-conditional marginal marginal value function (if desired)
if self.CubicBool:
# Add the state-conditional marginal marginal value function (if desired)
solution_cond = self.add_vPPfunc(solution_cond)

# Add the current-state-conditional solution to the overall period solution
Expand Down Expand Up @@ -1257,7 +1265,7 @@ class MarkovConsumerType(IndShockConsumerType):
def __init__(self, **kwds):
IndShockConsumerType.__init__(self, **kwds)
self.solve_one_period = _solve_ConsMarkov
#self.solve_one_period = solve_one_period_ConsMarkov
# self.solve_one_period = solve_one_period_ConsMarkov

if not hasattr(self, "global_markov"):
self.global_markov = False
Expand Down

0 comments on commit 8d3cc8d

Please sign in to comment.