adding test for solution of ConsMarkovModel, see
import numpy as np
from HARK.ConsumptionSaving.ConsIndShockModel import init_idiosyncratic_shocks
from HARK.ConsumptionSaving.ConsMarkovModel import MarkovConsumerType
+from HARK.distribution import DiscreteDistribution
from copy import copy
import unittest
@@ -17,7 +18,7 @@ class test_ConsMarkovSolver(unittest.TestCase):
p_unemploy_good = p_reemploy * urate_good / (1 - urate_good)
p_unemploy_bad = p_reemploy * urate_bad / (1 - urate_bad)
boom_prob = 1.0 / recession_length
- self.MrkvArray = np.array(
+ MrkvArray = np.array(
[
[
(1 - p_unemploy_good) * (1 - bust_prob),
@@ -47,8 +48,24 @@ class test_ConsMarkovSolver(unittest.TestCase):
)
init_serial_unemployment = copy(init_idiosyncratic_shocks)
- init_serial_unemployment["MrkvArray"] = [self.MrkvArray]
+ init_serial_unemployment["MrkvArray"] = [MrkvArray]
+ init_serial_unemployment["UnempPrb"] = 0 # to make income distribution when employed
+ init_serial_unemployment["global_markov"] = False
self.model = MarkovConsumerType(**init_serial_unemployment)
+ self.model.cycles = 0
+ self.model.vFuncBool = False # for easy toggling here
+
+ # Replace the default (lognormal) income distribution with a custom one
+ employed_income_dist = DiscreteDistribution(np.ones(1), [np.ones(1), np.ones(1)]) # Definitely get income
+ unemployed_income_dist = DiscreteDistribution(np.ones(1), [np.ones(1), np.zeros(1)]) # Definitely don't
+ self.model.IncomeDstn = [
+ [
+ employed_income_dist,
+ unemployed_income_dist,
+ employed_income_dist,
+ unemployed_income_dist,
+ ]
+ ]
def test_checkMarkovInputs(self):
# check Rfree
@@ -56,6 +73,7 @@ class test_ConsMarkovSolver(unittest.TestCase):
# fix Rfree
self.model.Rfree = np.array(4 * [self.model.Rfree])
# check MrkvArray, first mess up the setup
+ self.MrkvArray = self.model.MrkvArray
self.model.MrkvArray = np.random.rand(3, 3)
self.assertRaises(ValueError, self.model.checkMarkovInputs)
# then fix it back
@@ -68,3 +86,8 @@ class test_ConsMarkovSolver(unittest.TestCase):
self.assertRaises(ValueError, self.model.checkMarkovInputs)
# fix PermGroFac
self.model.PermGroFac = [np.array(4 * self.model.PermGroFac)]
+
+ def test_solve(self):
+ self.test_checkMarkovInputs()
+ self.model.timeFwd()
+ self.model.solve()
